diff --git a/Exceptions/CannotExtendClassException.php b/Exceptions/CannotExtendClassException.php index 827cf26..63b807b 100644 --- a/Exceptions/CannotExtendClassException.php +++ b/Exceptions/CannotExtendClassException.php @@ -6,6 +6,12 @@ class CannotExtendClassException extends Exception { + /** + * __construct + * + * @param string $message + * @return void + */ public function __construct(string $message) { $args = debug_backtrace()[1]; diff --git a/Exceptions/ClassDoesNotExistException.php b/Exceptions/ClassDoesNotExistException.php new file mode 100644 index 0000000..1f89209 --- /dev/null +++ b/Exceptions/ClassDoesNotExistException.php @@ -0,0 +1,25 @@ + $value) { + $this->{$key} = $value; + } + + $this->message = $message; + } +} diff --git a/Upstart/Prototype.php b/Upstart/Prototype.php index 2a034c1..31981f7 100644 --- a/Upstart/Prototype.php +++ b/Upstart/Prototype.php @@ -6,6 +6,7 @@ use ReflectionClass; use Modulus\Support\Extendable; use Modulus\Framework\Exceptions\CannotExtendClassException; +use Modulus\Framework\Exceptions\ClassDoesNotExistException; class Prototype { @@ -19,6 +20,8 @@ class Prototype */ public function bind(string $class, string $method, Closure $closure) { + if (!class_exists($class)) throw new ClassDoesNotExistException("Class {$class} does not exist"); + if (!in_array( Extendable::class, array_keys((new ReflectionClass($class))->getTraits())) @@ -39,6 +42,8 @@ public function bind(string $class, string $method, Closure $closure) */ public function static(string $class, string $method, Closure $closure) { + if (!class_exists($class)) throw new ClassDoesNotExistException("Class {$class} does not exist"); + if (!in_array( Extendable::class, array_keys((new ReflectionClass($class))->getTraits())) diff --git a/composer.json b/composer.json index 8a4dc9b..ffc157b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "modulusphp/framework", "description": "Framework component for Modulus", - "version": "1.9.8.10", + "version": "1.9.8.11", "license": "MIT", "type": "package", "authors": [{