-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
squashed commits refactoring error handling logic of Liip\ImagineBund…
…le\Binary\Loader\ChainLoader: - refactored Liip\ImagineBundle\Binary\Loader\ChainLoader error handling logic to exception classes instead of prior half-baked and confusing handling inside loader inself - testing alternate ChainNotLoadableException::compileExceptionMessage() implementation - cleanup of refactored Liip\ImagineBundle\Binary\Loader\ChainLoader and its related exceptions - ran php-cs-fixer on prior ChainLoader related changes - updates per reviews from @dbu and @franmomu
- Loading branch information
1 parent
6ed7f68
commit e49602b
Showing
4 changed files
with
109 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Exception/Binary/Loader/ChainAttemptNotLoadableException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Exception\Binary\Loader; | ||
|
||
use Liip\ImagineBundle\Binary\Loader\LoaderInterface; | ||
|
||
final class ChainAttemptNotLoadableException extends NotLoadableException | ||
{ | ||
private string $configName; | ||
private LoaderInterface $loaderInst; | ||
|
||
public function __construct(string $configName, LoaderInterface $loaderInst, NotLoadableException $loaderException) | ||
{ | ||
$this->configName = $configName; | ||
$this->loaderInst = $loaderInst; | ||
|
||
parent::__construct($this->compileFailureText(), 0, $loaderException); | ||
} | ||
|
||
public function getLoaderConfigName(): string | ||
{ | ||
return $this->configName; | ||
} | ||
|
||
public function getLoaderObjectInst(): LoaderInterface | ||
{ | ||
return $this->loaderInst; | ||
} | ||
|
||
public function getLoaderObjectName(): string | ||
{ | ||
return (new \ReflectionObject($this->getLoaderObjectInst()))->getShortName(); | ||
} | ||
|
||
public function getLoaderPriorError(): string | ||
{ | ||
return $this->getPrevious()->getMessage(); | ||
} | ||
|
||
private function compileFailureText(): string | ||
{ | ||
return sprintf('%s=[%s]', $this->getLoaderObjectName(), $this->getLoaderConfigName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Exception\Binary\Loader; | ||
|
||
final class ChainNotLoadableException extends NotLoadableException | ||
{ | ||
public function __construct(string $path, ChainAttemptNotLoadableException ...$exceptions) | ||
{ | ||
parent::__construct(self::compileExceptionMessage($path, ...$exceptions)); | ||
} | ||
|
||
private static function compileExceptionMessage(string $path, ChainAttemptNotLoadableException ...$exceptions): string | ||
{ | ||
return vsprintf('Source image not resolvable "%s" using "%s" %d loaders (internal exceptions: %s).', [ | ||
$path, self::compileLoaderConfigMaps(...$exceptions), \count($exceptions), self::compileLoaderErrorsList(...$exceptions), | ||
]); | ||
} | ||
|
||
private static function compileLoaderConfigMaps(ChainAttemptNotLoadableException ...$exceptions): string | ||
{ | ||
return self::implodeArrayMappedExceptions(static function (ChainAttemptNotLoadableException $e): string { | ||
return $e->getMessage(); | ||
}, ...$exceptions); | ||
} | ||
|
||
private static function compileLoaderErrorsList(ChainAttemptNotLoadableException ...$exceptions): string | ||
{ | ||
return self::implodeArrayMappedExceptions(static function (ChainAttemptNotLoadableException $e): string { | ||
return sprintf('%s=[%s]', $e->getLoaderObjectName(), $e->getLoaderPriorError()); | ||
}, ...$exceptions); | ||
} | ||
|
||
private static function implodeArrayMappedExceptions(\Closure $mapper, ChainAttemptNotLoadableException ...$exceptions): string | ||
{ | ||
return implode(', ', array_map($mapper, $exceptions)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters