From 641c01998f025efc89f2bce58357ea5cb0f67fd9 Mon Sep 17 00:00:00 2001 From: MartkCz Date: Thu, 20 May 2021 19:23:18 +0200 Subject: [PATCH] Tracy: add bluscreen with image info --- .../Exceptions/OperationNotFoundException.php | 26 ++++++++++++++++++- src/Bridge/Imagine/FilterProcessor.php | 2 +- .../ExceptionImageProviderInterface.php | 12 +++++++++ src/Bridge/Nette/Tracy/ImagistBlueScreen.php | 12 +++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/Bridge/Nette/Tracy/BlueScreen/ExceptionImageProviderInterface.php diff --git a/src/Bridge/Imagine/Exceptions/OperationNotFoundException.php b/src/Bridge/Imagine/Exceptions/OperationNotFoundException.php index 4604a73..637f65e 100644 --- a/src/Bridge/Imagine/Exceptions/OperationNotFoundException.php +++ b/src/Bridge/Imagine/Exceptions/OperationNotFoundException.php @@ -2,9 +2,33 @@ namespace Contributte\Imagist\Bridge\Imagine\Exceptions; +use Contributte\Imagist\Bridge\Nette\Tracy\BlueScreen\ExceptionImageProviderInterface; +use Contributte\Imagist\Entity\ImageInterface; use Exception; -class OperationNotFoundException extends Exception +class OperationNotFoundException extends Exception implements ExceptionImageProviderInterface { + private ImageInterface $image; + + public function __construct(ImageInterface $image) + { + $this->image = $image; + + $filterName = ''; + $filter = $image->getFilter(); + if ($filter) { + $filterName = $filter->getName(); + } + + parent::__construct( + sprintf('Operation not found for image "%s" with filter "%s".', $image->getName(), $filterName) + ); + } + + public function getImage(): ImageInterface + { + return $this->image; + } + } diff --git a/src/Bridge/Imagine/FilterProcessor.php b/src/Bridge/Imagine/FilterProcessor.php index 3821392..f941e8f 100644 --- a/src/Bridge/Imagine/FilterProcessor.php +++ b/src/Bridge/Imagine/FilterProcessor.php @@ -55,7 +55,7 @@ public function process(FileInterface $target, FileInterface $source, array $opt $operation = $this->operationRegistry->get($filter, $target->getImage()->getScope()); if (!$operation) { - throw new OperationNotFoundException(sprintf('Operation not found for %s', $target->getImage()->getId())); + throw new OperationNotFoundException($target->getImage()); } $operation->operate($image = $this->createImageInstance($source), $filter); diff --git a/src/Bridge/Nette/Tracy/BlueScreen/ExceptionImageProviderInterface.php b/src/Bridge/Nette/Tracy/BlueScreen/ExceptionImageProviderInterface.php new file mode 100644 index 0000000..193f503 --- /dev/null +++ b/src/Bridge/Nette/Tracy/BlueScreen/ExceptionImageProviderInterface.php @@ -0,0 +1,12 @@ + $panel, ]; }); + + $blueScreen->addPanel(function (?Throwable $exception) use ($blueScreen): ?array { + if (!$exception instanceof ExceptionImageProviderInterface) { + return null; + } + + return [ + 'tab' => 'Source image', + 'panel' => ($blueScreen->getDumper())($exception->getImage()), + ]; + }); } private static function isCollapsed(BlueScreen $blueScreen, string $file): bool