From 991514fd8e9702d2e431de3e65009fd8f92f2d51 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 7 Sep 2015 17:10:28 +0200 Subject: [PATCH 1/2] deprecated dependency on nette/reflection (BC break) --- src/Application/MicroPresenter.php | 2 +- .../UI/PresenterComponentReflection.php | 80 ++++++++++++++++++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index b6d4091bb..25c80aad4 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -78,7 +78,7 @@ public function run(Application\Request $request) if ($this->context) { foreach ($reflection->getParameters() as $param) { - if ($param->getClassName()) { + if ($param->getClass()) { unset($params[$param->getPosition()]); } } diff --git a/src/Application/UI/PresenterComponentReflection.php b/src/Application/UI/PresenterComponentReflection.php index 18901fbf7..376ccf91b 100644 --- a/src/Application/UI/PresenterComponentReflection.php +++ b/src/Application/UI/PresenterComponentReflection.php @@ -9,14 +9,20 @@ use Nette; use Nette\Application\BadRequestException; +use Nette\Reflection\ClassType; +use Nette\Reflection\Method; /** * Helpers for Presenter & PresenterComponent. + * @property-read string $name + * @property-read string $fileName * @internal */ -class PresenterComponentReflection extends Nette\Reflection\ClassType +class PresenterComponentReflection extends \ReflectionClass { + use Nette\SmartObject; + /** @var array getPersistentParams cache */ private static $ppCache = []; @@ -229,4 +235,76 @@ public static function getParameterType(\ReflectionParameter $param) } } + + /********************* compatiblity with Nette\Reflection ****************d*g**/ + + + public function getMethod($name) + { + return new MethodCompatibility($this->getName(), $name); + } + + + public function getMethods($filter = -1) + { + foreach ($res = parent::getMethods($filter) as $key => $val) { + $res[$key] = new MethodCompatibility($this->getName(), $val->getName()); + } + return $res; + } + + + public function __toString() + { + trigger_error(__METHOD__ . ' is deprecated.', E_USER_DEPRECATED); + return $this->getName(); + } + + + public function __get($name) + { + trigger_error("getReflection()->$name is deprecated.", E_USER_DEPRECATED); + return (new ClassType($this->getName()))->$name; + } + + + public function __call($name, $args) + { + if (method_exists(ClassType::class, $name)) { + trigger_error("getReflection()->$name() is deprecated, use Nette\\Reflection\\ClassType::from(\$presenter)->$name()", E_USER_DEPRECATED); + return call_user_func_array([new ClassType($this->getName()), $name], $args); + } + Nette\Utils\ObjectMixin::strictCall(get_class($this), $name); + } + +} + + +/** + * @internal + */ +class MethodCompatibility extends \ReflectionMethod +{ + use Nette\SmartObject; + + public function __toString() + { + trigger_error(__METHOD__ . ' is deprecated.', E_USER_DEPRECATED); + return parent::getDeclaringClass()->getName() . '::' . $this->getName() . '()'; + } + + + public function __get($name) + { + trigger_error("getMethod('{$this->getName()}')->$name is deprecated.", E_USER_DEPRECATED); + return (new Method(parent::getDeclaringClass()->getName(), $this->getName()))->$name; + } + + + public function __call($name, $args) + { + trigger_error("getMethod('{$this->getName()}')->$name() is deprecated, use Nette\\Reflection\\Method::from(\$presenter, '{$this->getName()}')->$name()", E_USER_DEPRECATED); + return call_user_func_array([new Method(parent::getDeclaringClass()->getName(), $this->getName()), $name], $args); + } + } From 2bfb38b217d66baa711bbff389ee2141222fe3ca Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 19 Jun 2015 17:51:19 +0200 Subject: [PATCH 2/2] PresenterComponent::checkRequirements() is called with native PHP reflection classes instead of Nette\Reflection\* (BC break!) --- src/Application/UI/Presenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 21e9b2e00..974ae19fb 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -176,7 +176,7 @@ public function run(Application\Request $request) } $this->initGlobalParameters(); - $this->checkRequirements($this->getReflection()); + $this->checkRequirements(new \ReflectionClass($this)); $this->startup(); if (!$this->startupCheck) { $class = $this->getReflection()->getMethod('startup')->getDeclaringClass()->getName();