From d51768c11e6b0ce0f1e64b88217ebc0df8eea0b7 Mon Sep 17 00:00:00 2001 From: donald_p Date: Wed, 20 Mar 2019 05:05:34 +0200 Subject: [PATCH 1/4] package: version bump --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": [{ From 46c95ecc312fced1dd18b794e2dab23fa4fde2bb Mon Sep 17 00:00:00 2001 From: donald_p Date: Wed, 20 Mar 2019 05:06:15 +0200 Subject: [PATCH 2/4] feat: thrown when extendable class does not exist --- Exceptions/ClassDoesNotExistException.php | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Exceptions/ClassDoesNotExistException.php 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; + } +} From b5cbe43372b47fa36c0c5887010403e980492daa Mon Sep 17 00:00:00 2001 From: donald_p Date: Wed, 20 Mar 2019 05:06:37 +0200 Subject: [PATCH 3/4] doc: added comments --- Exceptions/CannotExtendClassException.php | 6 ++++++ 1 file changed, 6 insertions(+) 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]; From 3dc160fecce6552a7136d20c7e07cd05e5c75cad Mon Sep 17 00:00:00 2001 From: donald_p Date: Wed, 20 Mar 2019 05:07:01 +0200 Subject: [PATCH 4/4] feat: throw exception if class does not exist --- Upstart/Prototype.php | 5 +++++ 1 file changed, 5 insertions(+) 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()))