mirror of
https://github.com/flarum/core.git
synced 2025-08-12 03:14:33 +02:00
Move exception cause guessing out of handler
This commit is contained in:
@@ -24,4 +24,14 @@ class ComposerCommandFailedException extends Exception
|
|||||||
|
|
||||||
parent::__construct($output);
|
parent::__construct($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function guessCause(): ?string
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRawPackageName(): string
|
||||||
|
{
|
||||||
|
return preg_replace('/^([A-z0-9-_\/]+)(?::.*|)$/i', '$1', $this->packageName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,8 +13,6 @@ use Flarum\Foundation\ErrorHandling\HandledError;
|
|||||||
|
|
||||||
class ComposerCommandFailedExceptionHandler
|
class ComposerCommandFailedExceptionHandler
|
||||||
{
|
{
|
||||||
protected const INCOMPATIBLE_REGEX = '/(?:(?: +- {PACKAGE_NAME}(?: v[0-9A-z.-]+ requires|\[[^\[\]]+\] require) flarum\/core)|(?:Could not find a version of package {PACKAGE_NAME} matching your minim)|(?: +- Root composer.json requires {PACKAGE_NAME} [^,]+, found {PACKAGE_NAME}\[[^\[\]]+\]+ but it does not match your minimum-stability))/m';
|
|
||||||
|
|
||||||
public function handle(ComposerCommandFailedException $e): HandledError
|
public function handle(ComposerCommandFailedException $e): HandledError
|
||||||
{
|
{
|
||||||
return (new HandledError(
|
return (new HandledError(
|
||||||
@@ -39,16 +37,6 @@ class ComposerCommandFailedExceptionHandler
|
|||||||
|
|
||||||
protected function guessCause(ComposerCommandFailedException $e): ?string
|
protected function guessCause(ComposerCommandFailedException $e): ?string
|
||||||
{
|
{
|
||||||
$rawPackageName = preg_replace('/^([A-z0-9-_\/]+)(?::.*|)$/i', '$1', $e->packageName);
|
return $e->guessCause();
|
||||||
|
|
||||||
if ($e instanceof ComposerRequireFailedException) {
|
|
||||||
$hasMatches = preg_match(str_replace('{PACKAGE_NAME}', preg_quote($rawPackageName, '/'), self::INCOMPATIBLE_REGEX), $e->getMessage(), $matches);
|
|
||||||
|
|
||||||
if ($hasMatches) {
|
|
||||||
return 'extension_incompatible_with_instance';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,5 +11,20 @@ namespace Flarum\PackageManager\Exception;
|
|||||||
|
|
||||||
class ComposerRequireFailedException extends ComposerCommandFailedException
|
class ComposerRequireFailedException extends ComposerCommandFailedException
|
||||||
{
|
{
|
||||||
// ...
|
protected const INCOMPATIBLE_REGEX = '/(?:(?: +- {PACKAGE_NAME}(?: v[0-9A-z.-]+ requires|\[[^\[\]]+\] require) flarum\/core)|(?:Could not find a version of package {PACKAGE_NAME} matching your minim)|(?: +- Root composer.json requires {PACKAGE_NAME} [^,]+, found {PACKAGE_NAME}\[[^\[\]]+\]+ but it does not match your minimum-stability))/m';
|
||||||
|
|
||||||
|
public function guessCause(): ?string
|
||||||
|
{
|
||||||
|
$hasMatches = preg_match(
|
||||||
|
str_replace('{PACKAGE_NAME}', preg_quote($this->getRawPackageName(), '/'), self::INCOMPATIBLE_REGEX),
|
||||||
|
$this->getMessage(),
|
||||||
|
$matches
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($hasMatches) {
|
||||||
|
return 'extension_incompatible_with_instance';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user