1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-28 16:19:50 +02:00

Enable external resolvables

This commit is contained in:
Oliver Vogel
2023-11-26 11:27:05 +01:00
parent 7c1e07db06
commit 08ae0df4f0

View File

@@ -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;
@@ -22,4 +29,21 @@ abstract class AbstractDriver implements DriverInterface
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;
}
}