From d814c54469fac84b42eeb1ffa58eadc06faf97fc Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 4 May 2016 16:05:05 +0200 Subject: [PATCH] =?UTF-8?q?PresenterComponentReflection=20=E2=87=92=20Comp?= =?UTF-8?q?onentReflection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 ++- src/Application/MicroPresenter.php | 2 +- ...onentReflection.php => ComponentReflection.php} | 2 +- src/Application/UI/MethodReflection.php | 4 ++-- src/Application/UI/Presenter.php | 14 +++++++------- src/Application/UI/PresenterComponent.php | 10 +++++----- src/compatibility.php | 8 ++++++++ ...t => ComponentReflection.combineArgs.php7.phpt} | 4 ++-- ...s.phpt => ComponentReflection.combineArgs.phpt} | 4 ++-- ...e.phpt => ComponentReflection.convertType.phpt} | 8 ++++---- ...pt => ComponentReflection.parseAnnotation.phpt} | 4 ++-- 11 files changed, 36 insertions(+), 27 deletions(-) rename src/Application/UI/{PresenterComponentReflection.php => ComponentReflection.php} (99%) create mode 100644 src/compatibility.php rename tests/UI/{PresenterComponentReflection.combineArgs.php7.phpt => ComponentReflection.combineArgs.php7.phpt} (98%) rename tests/UI/{PresenterComponentReflection.combineArgs.phpt => ComponentReflection.combineArgs.phpt} (96%) rename tests/UI/{PresenterComponentReflection.convertType.phpt => ComponentReflection.convertType.phpt} (93%) rename tests/UI/{PresenterComponentReflection.parseAnnotation.phpt => ComponentReflection.parseAnnotation.phpt} (86%) diff --git a/composer.json b/composer.json index b6c28422f..8a89de639 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ "nette/latte": "<2.4" }, "autoload": { - "classmap": ["src/"] + "classmap": ["src/"], + "files": ["src/compatibility.php"] }, "minimum-stability": "dev", "extra": { diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 25c80aad4..d4f64a4ac 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -74,7 +74,7 @@ public function run(Application\Request $request) $params['presenter'] = $this; $callback = $params['callback']; $reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback)); - $params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params); + $params = Application\UI\ComponentReflection::combineArgs($reflection, $params); if ($this->context) { foreach ($reflection->getParameters() as $param) { diff --git a/src/Application/UI/PresenterComponentReflection.php b/src/Application/UI/ComponentReflection.php similarity index 99% rename from src/Application/UI/PresenterComponentReflection.php rename to src/Application/UI/ComponentReflection.php index cf6cf5a3f..ecd701d21 100644 --- a/src/Application/UI/PresenterComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -18,7 +18,7 @@ * @property-read string $fileName * @internal */ -class PresenterComponentReflection extends \ReflectionClass +class ComponentReflection extends \ReflectionClass { use Nette\SmartObject; diff --git a/src/Application/UI/MethodReflection.php b/src/Application/UI/MethodReflection.php index 3db2e2235..b2097c9ad 100644 --- a/src/Application/UI/MethodReflection.php +++ b/src/Application/UI/MethodReflection.php @@ -25,7 +25,7 @@ class MethodReflection extends \ReflectionMethod */ public function hasAnnotation($name) { - return (bool) PresenterComponentReflection::parseAnnotation($this, $name); + return (bool) ComponentReflection::parseAnnotation($this, $name); } @@ -36,7 +36,7 @@ public function hasAnnotation($name) */ public function getAnnotation($name) { - $res = PresenterComponentReflection::parseAnnotation($this, $name); + $res = ComponentReflection::parseAnnotation($this, $name); return $res ? end($res) : NULL; } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 9f4b60f73..ef0e694d9 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -291,7 +291,7 @@ protected function shutdown($response) */ public function checkRequirements($element) { - $user = (array) PresenterComponentReflection::parseAnnotation($element, 'User'); + $user = (array) ComponentReflection::parseAnnotation($element, 'User'); if (in_array('loggedIn', $user, TRUE) && !$this->getUser()->isLoggedIn()) { throw new Application\ForbiddenRequestException; } @@ -855,7 +855,7 @@ protected function createRequest($component, $destination, array $args, $mode) // PROCESS SIGNAL ARGUMENTS if (isset($signal)) { // $component must be IStatePersistent - $reflection = new PresenterComponentReflection(get_class($component)); + $reflection = new ComponentReflection(get_class($component)); if ($signal === 'this') { // means "no signal" $signal = ''; if (array_key_exists(0, $args)) { @@ -894,7 +894,7 @@ protected function createRequest($component, $destination, array $args, $mode) $current = ($action === '*' || strcasecmp($action, $this->action) === 0) && $presenterClass === get_class($this); - $reflection = new PresenterComponentReflection($presenterClass); + $reflection = new ComponentReflection($presenterClass); // counterpart of run() & tryCall() $method = $presenterClass::formatActionMethod($action); @@ -1005,7 +1005,7 @@ public static function argsToParams($class, $method, & $args, $supplemental = [] $i = 0; $rm = new \ReflectionMethod($class, $method); foreach ($rm->getParameters() as $param) { - list($type, $isClass) = PresenterComponentReflection::getParameterType($param); + list($type, $isClass) = ComponentReflection::getParameterType($param); $name = $param->getName(); if (array_key_exists($i, $args)) { @@ -1027,7 +1027,7 @@ public static function argsToParams($class, $method, & $args, $supplemental = [] throw new InvalidLinkException("Missing parameter \$$name required by $class::{$rm->getName()}()"); } - if (!PresenterComponentReflection::convertType($args[$name], $type, $isClass)) { + if (!ComponentReflection::convertType($args[$name], $type, $isClass)) { throw new InvalidLinkException(sprintf( 'Argument $%s passed to %s() must be %s, %s given.', $name, @@ -1119,7 +1119,7 @@ public function restoreRequest($key) */ public static function getPersistentComponents() { - return (array) PresenterComponentReflection::parseAnnotation(new \ReflectionClass(get_called_class()), 'persistent'); + return (array) ComponentReflection::parseAnnotation(new \ReflectionClass(get_called_class()), 'persistent'); } @@ -1139,7 +1139,7 @@ protected function getGlobalState($forClass = NULL) $state[$prefix . $key] = $val; } } - $this->saveState($state, $forClass ? new PresenterComponentReflection($forClass) : NULL); + $this->saveState($state, $forClass ? new ComponentReflection($forClass) : NULL); if ($sinces === NULL) { $sinces = []; diff --git a/src/Application/UI/PresenterComponent.php b/src/Application/UI/PresenterComponent.php index d8c5ef73a..b280da505 100644 --- a/src/Application/UI/PresenterComponent.php +++ b/src/Application/UI/PresenterComponent.php @@ -108,11 +108,11 @@ public function checkRequirements($element) /** * Access to reflection. - * @return PresenterComponentReflection + * @return ComponentReflection */ public static function getReflection() { - return new PresenterComponentReflection(get_called_class()); + return new ComponentReflection(get_called_class()); } @@ -151,7 +151,7 @@ public function loadState(array $params) /** * Saves state informations for next request. * @param array - * @param PresenterComponentReflection (internal, used by Presenter) + * @param ComponentReflection (internal, used by Presenter) * @return void */ public function saveState(array & $params, $reflection = NULL) @@ -173,7 +173,7 @@ public function saveState(array & $params, $reflection = NULL) } $type = gettype($meta['def']); - if (!PresenterComponentReflection::convertType($params[$name], $type)) { + if (!ComponentReflection::convertType($params[$name], $type)) { throw new InvalidLinkException(sprintf( "Value passed to persistent parameter '%s' in %s must be %s, %s given.", $name, @@ -247,7 +247,7 @@ public static function getPersistentParams() $rc = new \ReflectionClass(get_called_class()); $params = []; foreach ($rc->getProperties(\ReflectionProperty::IS_PUBLIC) as $rp) { - if (!$rp->isStatic() && PresenterComponentReflection::parseAnnotation($rp, 'persistent')) { + if (!$rp->isStatic() && ComponentReflection::parseAnnotation($rp, 'persistent')) { $params[] = $rp->getName(); } } diff --git a/src/compatibility.php b/src/compatibility.php new file mode 100644 index 000000000..5dcfc0ff8 --- /dev/null +++ b/src/compatibility.php @@ -0,0 +1,8 @@ +