Skip to content

Commit

Permalink
Enable external resolvables
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Nov 26, 2023
1 parent 7c1e07d commit 08ae0df
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Drivers/AbstractDriver.php
Expand Up @@ -2,14 +2,21 @@

namespace Intervention\Image\Drivers;

use Intervention\Image\Analyzers\AbstractAnalyzer;
use Intervention\Image\Encoders\AbstractEncoder;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Modifiers\AbstractModifier;
use ReflectionClass;

abstract class AbstractDriver implements DriverInterface
{
public function resolve(object $input): object
{
if ($this->isExternal($input)) {
return $input;
}

$driver_namespace = (new ReflectionClass($this))->getNamespaceName();
$class_path = substr(get_class($input), strlen("Intervention\\Image\\"));
$specialized = $driver_namespace . "\\" . $class_path;
Expand All @@ -22,4 +29,21 @@ public function resolve(object $input): object

return new $specialized($input, $this);
}

private function isExternal(object $input): bool
{
if ($input instanceof AbstractModifier) {
return false;
}

if ($input instanceof AbstractAnalyzer) {
return false;
}

if ($input instanceof AbstractEncoder) {
return false;
}

return true;
}
}

0 comments on commit 08ae0df

Please sign in to comment.