Skip to content

Commit

Permalink
Tracy: add bluscreen with image info
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed May 20, 2021
1 parent 847e0fd commit 641c019
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/Bridge/Imagine/Exceptions/OperationNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
2 changes: 1 addition & 1 deletion src/Bridge/Imagine/FilterProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types = 1);

namespace Contributte\Imagist\Bridge\Nette\Tracy\BlueScreen;

use Contributte\Imagist\Entity\ImageInterface;

interface ExceptionImageProviderInterface
{

public function getImage(): ImageInterface;

}
12 changes: 12 additions & 0 deletions src/Bridge/Nette/Tracy/ImagistBlueScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Contributte\Imagist\Bridge\Nette\Tracy;

use Contributte\Imagist\Bridge\Nette\Tracy\BlueScreen\BlueScreenBacktraceInterface;
use Contributte\Imagist\Bridge\Nette\Tracy\BlueScreen\ExceptionImageProviderInterface;
use Throwable;
use Tracy\BlueScreen;

Expand Down Expand Up @@ -39,6 +40,17 @@ public static function install(BlueScreen $blueScreen): void
'panel' => $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
Expand Down

0 comments on commit 641c019

Please sign in to comment.