mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 09:41:49 +08:00
Move exception cause guessing out of handler
This commit is contained in:
parent
7f5f5687db
commit
3bd2dd4813
|
@ -24,4 +24,14 @@ class ComposerCommandFailedException extends Exception
|
|||
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
return (new HandledError(
|
||||
|
@ -39,16 +37,6 @@ class ComposerCommandFailedExceptionHandler
|
|||
|
||||
protected function guessCause(ComposerCommandFailedException $e): ?string
|
||||
{
|
||||
$rawPackageName = preg_replace('/^([A-z0-9-_\/]+)(?::.*|)$/i', '$1', $e->packageName);
|
||||
|
||||
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;
|
||||
return $e->guessCause();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,20 @@ namespace Flarum\PackageManager\Exception;
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user