From 03443b23c28d4b0884fe917835bfe15857b5fc77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Thu, 18 Jul 2019 20:52:34 +0200 Subject: [PATCH 1/2] Fix $this to self:: in case of static method. --- src/Application/UI/Presenter.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index d8cf8436a..90d6ee8ac 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -188,15 +188,15 @@ public function run(Application\Request $request): Application\IResponse } $this->initGlobalParameters(); - $this->checkRequirements($this->getReflection()); + $this->checkRequirements(self::getReflection()); $this->onStartup($this); $this->startup(); if (!$this->startupCheck) { - $class = $this->getReflection()->getMethod('startup')->getDeclaringClass()->getName(); + $class = self::getReflection()->getMethod('startup')->getDeclaringClass()->getName(); throw new Nette\InvalidStateException("Method $class::startup() or its descendant doesn't call parent::startup()."); } // calls $this->action() - $this->tryCall($this->formatActionMethod($this->action), $this->params); + $this->tryCall(self::formatActionMethod($this->action), $this->params); // autoload components foreach ($this->globalParams as $id => $foo) { @@ -218,7 +218,7 @@ public function run(Application\Request $request): Application\IResponse $this->beforeRender(); $this->onRender($this); // calls $this->render() - $this->tryCall($this->formatRenderMethod($this->view), $this->params); + $this->tryCall(self::formatRenderMethod($this->view), $this->params); $this->afterRender(); // save component tree persistent state @@ -1151,7 +1151,7 @@ protected function getGlobalState(string $forClass = null): array */ public function saveState(array &$params, ComponentReflection $reflection = null): void { - ($reflection ?: $this->getReflection())->saveState($this, $params); + ($reflection ?: self::getReflection())->saveState($this, $params); } From 047eea46215f38048c300b67341ea0ad696bc9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sat, 20 Jul 2019 10:10:46 +0200 Subject: [PATCH 2/2] Presenter: Replace $this and self:: to static:: in static methods --- src/Application/UI/Presenter.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 90d6ee8ac..14945dfd9 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -188,15 +188,15 @@ public function run(Application\Request $request): Application\IResponse } $this->initGlobalParameters(); - $this->checkRequirements(self::getReflection()); + $this->checkRequirements(static::getReflection()); $this->onStartup($this); $this->startup(); if (!$this->startupCheck) { - $class = self::getReflection()->getMethod('startup')->getDeclaringClass()->getName(); + $class = static::getReflection()->getMethod('startup')->getDeclaringClass()->getName(); throw new Nette\InvalidStateException("Method $class::startup() or its descendant doesn't call parent::startup()."); } // calls $this->action() - $this->tryCall(self::formatActionMethod($this->action), $this->params); + $this->tryCall(static::formatActionMethod($this->action), $this->params); // autoload components foreach ($this->globalParams as $id => $foo) { @@ -218,7 +218,7 @@ public function run(Application\Request $request): Application\IResponse $this->beforeRender(); $this->onRender($this); // calls $this->render() - $this->tryCall(self::formatRenderMethod($this->view), $this->params); + $this->tryCall(static::formatRenderMethod($this->view), $this->params); $this->afterRender(); // save component tree persistent state @@ -506,7 +506,7 @@ public function formatLayoutTemplateFiles(): array } [$module, $presenter] = Helpers::splitName($this->getName()); $layout = $this->layout ?: 'layout'; - $dir = dirname($this->getReflection()->getFileName()); + $dir = dirname(static::getReflection()->getFileName()); $dir = is_dir("$dir/templates") ? $dir : dirname($dir); $list = [ "$dir/templates/$presenter/@$layout.latte", @@ -526,7 +526,7 @@ public function formatLayoutTemplateFiles(): array public function formatTemplateFiles(): array { [, $presenter] = Helpers::splitName($this->getName()); - $dir = dirname($this->getReflection()->getFileName()); + $dir = dirname(static::getReflection()->getFileName()); $dir = is_dir("$dir/templates") ? $dir : dirname($dir); return [ "$dir/templates/$presenter/$this->view.latte", @@ -740,7 +740,7 @@ final protected function createRequest(Component $component, string $destination $this->lastCreatedRequest = $this->lastCreatedRequestFlag = null; - $parts = $this->parseDestination($destination); + $parts = static::parseDestination($destination); $path = $parts['path']; $args = $parts['args'] ?? $args; @@ -1151,7 +1151,7 @@ protected function getGlobalState(string $forClass = null): array */ public function saveState(array &$params, ComponentReflection $reflection = null): void { - ($reflection ?: self::getReflection())->saveState($this, $params); + ($reflection ?: static::getReflection())->saveState($this, $params); }