From 2fff15005e60eec26a42ef5e249ff31f9ae5a944 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 23 Sep 2023 19:05:45 +0200 Subject: [PATCH 01/42] typo --- src/Application/UI/Component.php | 4 ++-- src/Application/UI/ComponentReflection.php | 2 +- src/Application/UI/Presenter.php | 2 +- src/Application/UI/StatePersistent.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 261c7aba0..6488786c9 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -152,7 +152,7 @@ public static function getReflection(): ComponentReflection /** - * Loads state informations. + * Loads state information. */ public function loadState(array $params): void { @@ -180,7 +180,7 @@ public function loadState(array $params): void /** - * Saves state informations for next request. + * Saves state information for next request. */ public function saveState(array &$params): void { diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 143dc5f82..313249dc3 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -101,7 +101,7 @@ public function getPersistentComponents(?string $class = null): array /** - * Saves state informations for next request. + * Saves state information for next request. */ public function saveState(Component $component, array &$params): void { diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 63dea49a9..28b0b32c2 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -1285,7 +1285,7 @@ protected function getGlobalState(?string $forClass = null): array /** - * Saves state informations for next request. + * Saves state information for next request. */ public function saveState(array &$params, ?ComponentReflection $reflection = null): void { diff --git a/src/Application/UI/StatePersistent.php b/src/Application/UI/StatePersistent.php index 1dd8c97c5..f24c0e53a 100644 --- a/src/Application/UI/StatePersistent.php +++ b/src/Application/UI/StatePersistent.php @@ -16,12 +16,12 @@ interface StatePersistent { /** - * Loads state informations. + * Loads state information. */ function loadState(array $params): void; /** - * Saves state informations for next request. + * Saves state information for next request. */ function saveState(array &$params): void; } From 17043d33c764631589bbd2a6812b29916baa17b0 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 23 Sep 2023 19:23:47 +0200 Subject: [PATCH 02/42] refactoring --- src/Application/UI/ComponentReflection.php | 114 ++++++++++----------- 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 313249dc3..0612167bb 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -33,40 +33,39 @@ final class ComponentReflection extends \ReflectionClass /** - * Returns array of classes persistent parameters. They have public visibility, - * are non-static and have annotation @persistent. + * Returns array of persistent properties. They are public and have attribute #[Persistent] or annotation @persistent. */ - public function getPersistentParams(?string $class = null): array + public function getPersistentParams(): array { - $class = $class ?? $this->getName(); - $params = &self::$ppCache[$class]; + $params = &self::$ppCache[$this->getName()]; if ($params !== null) { return $params; } $params = []; - if (is_subclass_of($class, Component::class)) { - $isPresenter = is_subclass_of($class, Presenter::class); - $defaults = get_class_vars($class); - foreach ($defaults as $name => $default) { - $rp = new \ReflectionProperty($class, $name); - if (!$rp->isStatic() - && ((PHP_VERSION_ID >= 80000 && $rp->getAttributes(Nette\Application\Attributes\Persistent::class)) - || self::parseAnnotation($rp, 'persistent')) - ) { - $params[$name] = [ - 'def' => $default, - 'type' => self::getPropertyType($rp, $default), - 'since' => $isPresenter ? Nette\Utils\Reflection::getPropertyDeclaringClass($rp)->getName() : null, - ]; - } + $isPresenter = $this->isSubclassOf(Presenter::class); + $defaults = $this->getDefaultProperties(); + foreach ($this->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) { + if (!$prop->isStatic() + && (self::parseAnnotation($prop, 'persistent') + || (PHP_VERSION_ID >= 80000 && $prop->getAttributes(Nette\Application\Attributes\Persistent::class))) + ) { + $default = $defaults[$prop->getName()] ?? null; + $params[$prop->getName()] = [ + 'def' => $default, + 'type' => self::getPropertyType($prop, $default), + 'since' => $isPresenter ? Nette\Utils\Reflection::getPropertyDeclaringClass($prop)->getName() : null, + ]; } + } - foreach ($this->getPersistentParams(get_parent_class($class)) as $name => $param) { + if ($this->getParentClass()->isSubclassOf(Component::class)) { + $parent = new self($this->getParentClass()->getName()); + foreach ($parent->getPersistentParams() as $name => $meta) { if (isset($params[$name])) { - $params[$name]['since'] = $param['since']; + $params[$name]['since'] = $meta['since']; } else { - $params[$name] = $param; + $params[$name] = $meta; } } } @@ -75,25 +74,22 @@ public function getPersistentParams(?string $class = null): array } - public function getPersistentComponents(?string $class = null): array + public function getPersistentComponents(): array { - $class = $class ?? $this->getName(); + $class = $this->getName(); $components = &self::$pcCache[$class]; if ($components !== null) { return $components; } $components = []; - if (is_subclass_of($class, Presenter::class)) { + if ($this->isSubclassOf(Presenter::class)) { foreach ($class::getPersistentComponents() as $name => $meta) { - if (is_string($meta)) { - $name = $meta; - } - - $components[$name] = ['since' => $class]; + $components[is_string($meta) ? $meta : $name] = ['since' => $class]; } - $components = $this->getPersistentComponents(get_parent_class($class)) + $components; + $parent = new self($this->getParentClass()->getName()); + $components = $parent->getPersistentComponents() + $components; } return $components; @@ -216,48 +212,48 @@ public static function convertType(&$val, string $types): bool */ private static function convertSingleType(&$val, string $type): bool { - $builtin = [ - 'string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'array' => 1, 'object' => 1, - 'callable' => 1, 'iterable' => 1, 'void' => 1, 'null' => 1, 'mixed' => 1, - 'boolean' => 1, 'integer' => 1, 'double' => 1, 'scalar' => 1, - ]; + $scalars = ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'boolean' => 1, 'double' => 1, 'integer' => 1]; + $tests = ['iterable' => 1, 'object' => 1, 'array' => 1, 'null' => 1]; - if (empty($builtin[$type])) { - return $val instanceof $type; - - } elseif ($type === 'object') { - return is_object($val); + if (isset($scalars[$type])) { + return self::dataLossConvert($val, $type); - } elseif ($type === 'callable') { - return false; + } elseif (isset($tests[$type])) { + return "is_$type"($val); - } elseif ($type === 'scalar') { + } elseif ($type === 'scalar') { // special historical type return !is_array($val); - } elseif ($type === 'array' || $type === 'iterable') { - return is_array($val); - } elseif ($type === 'mixed') { return true; - } elseif (!is_scalar($val)) { // array, resource, null, etc. + } elseif ($type === 'callable') { return false; } else { - $tmp = ($val === false ? '0' : (string) $val); - if ($type === 'double' || $type === 'float') { - $tmp = preg_replace('#\.0*$#D', '', $tmp); - } + return $val instanceof $type; + } + } - $orig = $tmp; - settype($tmp, $type); - if ($orig !== ($tmp === false ? '0' : (string) $tmp)) { - return false; // data-loss occurs - } - $val = $tmp; + private static function dataLossConvert(&$val, string $type): bool + { + if (!is_scalar($val)) { + return false; + } + + $tmp = ($val === false ? '0' : (string) $val); + if ($type === 'double' || $type === 'float') { + $tmp = preg_replace('#\.0*$#D', '', $tmp); + } + + $orig = $tmp; + settype($tmp, $type); + if ($orig !== ($tmp === false ? '0' : (string) $tmp)) { + return false; // data-loss occurs } + $val = $tmp; return true; } From 5927f8a4acf64b5f12d79dde0a0fc23fcf773c4a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 4 Oct 2023 04:13:10 +0200 Subject: [PATCH 03/42] ComponentReflection::convertType() supports true|false --- src/Application/UI/ComponentReflection.php | 5 +-- tests/UI/ComponentReflection.convertType.phpt | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 0612167bb..113e063d2 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -212,7 +212,7 @@ public static function convertType(&$val, string $types): bool */ private static function convertSingleType(&$val, string $type): bool { - $scalars = ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'boolean' => 1, 'double' => 1, 'integer' => 1]; + $scalars = ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'true' => 1, 'false' => 1, 'boolean' => 1, 'double' => 1, 'integer' => 1]; $tests = ['iterable' => 1, 'object' => 1, 'array' => 1, 'null' => 1]; if (isset($scalars[$type])) { @@ -248,7 +248,8 @@ private static function dataLossConvert(&$val, string $type): bool } $orig = $tmp; - settype($tmp, $type); + $spec = ['true' => true, 'false' => false]; + isset($spec[$type]) ? $tmp = $spec[$type] : settype($tmp, $type); if ($orig !== ($tmp === false ? '0' : (string) $tmp)) { return false; // data-loss occurs } diff --git a/tests/UI/ComponentReflection.convertType.phpt b/tests/UI/ComponentReflection.convertType.phpt index 72c3c2f42..daa0f7944 100644 --- a/tests/UI/ComponentReflection.convertType.phpt +++ b/tests/UI/ComponentReflection.convertType.phpt @@ -244,6 +244,38 @@ testIt('stdClass', 1); testIt('stdClass', 1.0); testIt('stdClass', 1.2); +testIt('true', null); +testIt('true', []); +testIt('true', $obj); +testIt('true', ''); +testIt('true', 'a'); +testIt('true', '1', true); +testIt('true', '1.0'); +testIt('true', '1.1'); +testIt('true', '1a'); +testIt('true', true, true); +testIt('true', false); +testIt('true', 0); +testIt('true', 1, true); +testIt('true', 1.0, true); +testIt('true', 1.2); + +testIt('false', null); +testIt('false', []); +testIt('false', $obj); +testIt('false', ''); +testIt('false', 'a'); +testIt('false', '1'); +testIt('false', '1.0'); +testIt('false', '1.1'); +testIt('false', '1a'); +testIt('false', true); +testIt('false', false, false); +testIt('false', 0, false); +testIt('false', 1); +testIt('false', 1.0); +testIt('false', 1.2); + testIt('Closure', $var = function () {}, $var); From 0fd1744ec9d85725cb649c6aba690e65d931d0b7 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 4 Oct 2023 04:13:10 +0200 Subject: [PATCH 04/42] added attribute #Parameter --- src/Application/Attributes/Parameter.php | 18 ++++ src/Application/UI/Component.php | 2 +- src/Application/UI/ComponentReflection.php | 36 +++++-- tests/UI/Presenter.getParameters.phpt | 107 +++++++++++++++++++++ 4 files changed, 152 insertions(+), 11 deletions(-) create mode 100644 src/Application/Attributes/Parameter.php create mode 100644 tests/UI/Presenter.getParameters.phpt diff --git a/src/Application/Attributes/Parameter.php b/src/Application/Attributes/Parameter.php new file mode 100644 index 000000000..11e8a7b10 --- /dev/null +++ b/src/Application/Attributes/Parameter.php @@ -0,0 +1,18 @@ +getReflection(); - foreach ($reflection->getPersistentParams() as $name => $meta) { + foreach ($reflection->getParameters() as $name => $meta) { if (isset($params[$name])) { // nulls are ignored if (!$reflection->convertType($params[$name], $meta['type'])) { throw new Nette\Application\BadRequestException(sprintf( diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 113e063d2..9d27cd5ab 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -33,9 +33,9 @@ final class ComponentReflection extends \ReflectionClass /** - * Returns array of persistent properties. They are public and have attribute #[Persistent] or annotation @persistent. + * Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter] or annotation @persistent. */ - public function getPersistentParams(): array + public function getParameters(): array { $params = &self::$ppCache[$this->getName()]; if ($params !== null) { @@ -46,9 +46,10 @@ public function getPersistentParams(): array $isPresenter = $this->isSubclassOf(Presenter::class); $defaults = $this->getDefaultProperties(); foreach ($this->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) { - if (!$prop->isStatic() - && (self::parseAnnotation($prop, 'persistent') - || (PHP_VERSION_ID >= 80000 && $prop->getAttributes(Nette\Application\Attributes\Persistent::class))) + if ($prop->isStatic()) { + continue; + } elseif (self::parseAnnotation($prop, 'persistent') + || (PHP_VERSION_ID >= 80000 && $prop->getAttributes(Nette\Application\Attributes\Persistent::class)) ) { $default = $defaults[$prop->getName()] ?? null; $params[$prop->getName()] = [ @@ -56,16 +57,20 @@ public function getPersistentParams(): array 'type' => self::getPropertyType($prop, $default), 'since' => $isPresenter ? Nette\Utils\Reflection::getPropertyDeclaringClass($prop)->getName() : null, ]; + } elseif (PHP_VERSION_ID >= 80000 && $prop->getAttributes(Nette\Application\Attributes\Parameter::class)) { + $params[$prop->getName()] = [ + 'type' => (string) ($prop->getType() ?? 'mixed'), + ]; } } if ($this->getParentClass()->isSubclassOf(Component::class)) { $parent = new self($this->getParentClass()->getName()); - foreach ($parent->getPersistentParams() as $name => $meta) { - if (isset($params[$name])) { - $params[$name]['since'] = $meta['since']; - } else { + foreach ($parent->getParameters() as $name => $meta) { + if (!isset($params[$name])) { $params[$name] = $meta; + } elseif (array_key_exists('since', $params[$name])) { + $params[$name]['since'] = $meta['since']; } } } @@ -74,6 +79,17 @@ public function getPersistentParams(): array } + /** + * Returns array of persistent properties. They are public and have attribute #[Persistent] or annotation @persistent. + */ + public function getPersistentParams(): array + { + return array_filter($this->getParameters(), function ($param) { + return array_key_exists('since', $param); + }); + } + + public function getPersistentComponents(): array { $class = $this->getName(); @@ -197,7 +213,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a */ public static function convertType(&$val, string $types): bool { - foreach (explode('|', $types) as $type) { + foreach (explode('|', ltrim($types, '?')) as $type) { if (self::convertSingleType($val, $type)) { return true; } diff --git a/tests/UI/Presenter.getParameters.phpt b/tests/UI/Presenter.getParameters.phpt new file mode 100644 index 000000000..e4e916a8c --- /dev/null +++ b/tests/UI/Presenter.getParameters.phpt @@ -0,0 +1,107 @@ + [ + 'def' => null, + 'type' => 'scalar', + 'since' => 'OnePresenter', + ], + ], + (new ComponentReflection(OnePresenter::class))->getParameters() + ); + + Assert::same( + [ + 'yes1' => [ + 'def' => null, + 'type' => 'scalar', + 'since' => 'OnePresenter', + ], + ], + (new ComponentReflection(TwoPresenter::class))->getParameters() + ); + +} else { + Assert::same( + [ + 'yes1' => [ + 'def' => null, + 'type' => 'scalar', + 'since' => 'OnePresenter', + ], + 'yes2' => [ + 'def' => null, + 'type' => 'scalar', + 'since' => 'OnePresenter', + ], + 'yes3' => [ + 'type' => 'mixed', + ], + ], + (new ComponentReflection(OnePresenter::class))->getParameters() + ); + + Assert::same( + [ + 'yes2' => [ + 'type' => 'mixed', + ], + 'yes4' => [ + 'type' => 'mixed', + ], + 'yes1' => [ + 'def' => null, + 'type' => 'scalar', + 'since' => 'OnePresenter', + ], + 'yes3' => [ + 'type' => 'mixed', + ], + ], + (new ComponentReflection(TwoPresenter::class))->getParameters() + ); +} From 7d06f0ed27c13a4f47e455d48dfcf715c0a48490 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 15:27:18 +0100 Subject: [PATCH 05/42] opened 4.0-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e712eb75c..2a933235d 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "4.0-dev" } } } From 1c4fcc5a1056a796e0f4755577a54ac9a91156fe Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 30 Jul 2023 19:32:54 +0200 Subject: [PATCH 06/42] requires PHP 8.0 --- .github/workflows/static-analysis.yml | 2 +- .github/workflows/tests.yml | 4 ++-- composer.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 5424fc71f..25e44dd05 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: none - run: composer install --no-progress --prefer-dist diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aa386a1e9..58b8cf7c8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + php: ['8.0', '8.1', '8.2', '8.3'] fail-fast: false @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 with: - php-version: 7.2 + php-version: 8.0 coverage: none - run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable diff --git a/composer.json b/composer.json index 2a933235d..57ea7e219 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2", + "php": "8.0 - 8.3", "nette/component-model": "^3.0", "nette/http": "^3.0.2", "nette/routing": "^3.0.2", From e0aa96d79a060ddac9ce0093128d1c3977e789d2 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 15:56:28 +0100 Subject: [PATCH 07/42] composer: updated dependencies --- composer.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 57ea7e219..40d55e089 100644 --- a/composer.json +++ b/composer.json @@ -16,25 +16,25 @@ ], "require": { "php": "8.0 - 8.3", - "nette/component-model": "^3.0", - "nette/http": "^3.0.2", + "nette/component-model": "^4.0", + "nette/http": "^4.0", "nette/routing": "^3.0.2", - "nette/utils": "^3.2.1 || ~4.0.0" + "nette/utils": "^4.0" }, "suggest": { "nette/forms": "Allows to use Nette\\Application\\UI\\Form", "latte/latte": "Allows using Latte in templates" }, "require-dev": { - "nette/tester": "^2.3.1", - "nette/di": "^v3.0", - "nette/forms": "^3.0", - "nette/robot-loader": "^3.2", - "nette/security": "^3.0", + "nette/tester": "^2.4", + "nette/di": "^3.1 || ^4.0", + "nette/forms": "^4.0", + "nette/robot-loader": "^3.2 || ^4.0", + "nette/security": "^4.0", "latte/latte": "^2.10.2 || ^3.0.3", - "tracy/tracy": "^2.6", - "mockery/mockery": "^1.0", - "phpstan/phpstan-nette": "^0.12", + "tracy/tracy": "^2.8", + "mockery/mockery": "^1.4", + "phpstan/phpstan-nette": "^1.0", "jetbrains/phpstorm-attributes": "dev-master" }, "conflict": { From aaa8b3caafe5728015463710d0d010ebcf979afd Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 2 Oct 2023 18:03:51 +0200 Subject: [PATCH 08/42] coding style --- .phpstorm.meta.php | 4 +- src/Application/Application.php | 4 +- src/Application/LinkGenerator.php | 2 +- src/Application/MicroPresenter.php | 4 +- src/Application/PresenterFactory.php | 2 +- src/Application/Request.php | 2 +- src/Application/Responses/FileResponse.php | 6 +- src/Application/Routers/RouteList.php | 2 +- src/Application/UI/Component.php | 8 +- src/Application/UI/ComponentReflection.php | 39 +-- src/Application/UI/Control.php | 4 +- src/Application/UI/Presenter.php | 26 +- .../ApplicationDI/ApplicationExtension.php | 12 +- src/Bridges/ApplicationDI/LatteExtension.php | 2 +- .../PresenterFactoryCallback.php | 2 +- .../ApplicationLatte/SnippetDriver.php | 4 +- src/Bridges/ApplicationLatte/Template.php | 6 +- .../ApplicationLatte/TemplateFactory.php | 14 +- src/Bridges/ApplicationLatte/UIMacros.php | 12 +- src/Bridges/ApplicationLatte/UIRuntime.php | 4 +- src/Bridges/ApplicationTracy/RoutingPanel.php | 8 +- tests/Application/Application.run.phpt | 28 +- tests/Application/MicroPresenter.invoke.phpt | 2 +- .../Application/MicroPresenter.response.phpt | 28 +- tests/Application/Presenter.twoDomains.phpt | 2 +- ...PresenterFactory.formatPresenterClass.phpt | 2 +- .../ApplicationExtension.invalidLink.phpt | 8 +- tests/Bridges.DI/LatteExtension.2.phpt | 6 +- tests/Bridges.DI/LatteExtension.basic.phpt | 2 +- .../Template.getParentName().phpt | 2 +- .../TemplateFactory.filters.phpt | 4 +- .../TemplateFactory.nonce.control.phpt | 2 +- .../TemplateFactory.nonce.presenter.phpt | 2 +- tests/Bridges.Latte2/UIMacros.control.3.phpt | 4 +- tests/Bridges.Latte2/UIMacros.control.phpt | 54 ++- .../UIMacros.isLinkCurrent.phpt | 18 +- tests/Bridges.Latte2/UIMacros.link.2.phpt | 67 ++-- tests/Bridges.Latte2/UIMacros.link.phpt | 22 +- .../UIMacros.renderSnippets2.phpt | 4 +- .../TemplateFactory.filters.phpt | 4 +- tests/Bridges.Latte3/renderSnippets7.phpt | 4 +- tests/Bridges.Latte3/{control}.phpt | 3 +- tests/Bridges.Latte3/{link}.2.phpt | 7 +- tests/Responses/FileResponse.range.phpt | 16 +- tests/Routers/Route.errors.phpt | 38 ++- tests/Routers/Route.filter.global.phpt | 2 +- tests/Routers/Route.filter.query.phpt | 8 +- tests/Routers/Route.filter.url.object.phpt | 8 +- tests/Routers/Route.filter.url.phpt | 8 +- .../Routers/Route.optional.autooptional3.phpt | 4 +- tests/Routers/Route.scalarParams.phpt | 58 ++-- tests/Routers/Route.secured.phpt | 2 +- tests/Routers/Route.type.phpt | 2 +- tests/Routers/Route.withHost.secured.phpt | 8 +- tests/Routers/RouteList.addRoute.phpt | 2 +- tests/Routers/RouteList.modules.phpt | 2 +- tests/Routers/RouteList.withModule.phpt | 6 +- .../UI/Component.isLinkCurrent().asserts.php | 62 ++-- tests/UI/Component.redirect().phpt | 2 +- ...ComponentReflection.combineArgs.php80.phpt | 38 ++- tests/UI/ComponentReflection.combineArgs.phpt | 310 +++++++++++------- tests/UI/Presenter.link().persistent.phpt | 6 +- tests/UI/Presenter.link().php74.phpt | 22 +- tests/UI/Presenter.link().phpt | 22 +- tests/UI/Presenter.paramChecking.phpt | 2 +- tests/UI/Presenter.parseDestination().phpt | 7 +- tests/UI/Presenter.storeRequest().phpt | 6 +- 67 files changed, 556 insertions(+), 527 deletions(-) diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index 48e603bc7..af319c059 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -16,7 +16,7 @@ \Nette\Http\IResponse::S304_NOT_MODIFIED, \Nette\Http\IResponse::S305_USE_PROXY, \Nette\Http\IResponse::S307_TEMPORARY_REDIRECT, - \Nette\Http\IResponse::S308_PERMANENT_REDIRECT + \Nette\Http\IResponse::S308_PERMANENT_REDIRECT, ); registerArgumentsSet('nette_http_codes_4xx', \Nette\Http\IResponse::S400_BAD_REQUEST, @@ -45,7 +45,7 @@ \Nette\Http\IResponse::S428_PRECONDITION_REQUIRED, \Nette\Http\IResponse::S429_TOO_MANY_REQUESTS, \Nette\Http\IResponse::S431_REQUEST_HEADER_FIELDS_TOO_LARGE, - \Nette\Http\IResponse::S451_UNAVAILABLE_FOR_LEGAL_REASONS + \Nette\Http\IResponse::S451_UNAVAILABLE_FOR_LEGAL_REASONS, ); expectedArguments(\Nette\Application\UI\Presenter::redirectUrl(), 1, argumentsSet('nette_http_codes_3xx')); diff --git a/src/Application/Application.php b/src/Application/Application.php index dc7c4154d..435dc1d8d 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -71,7 +71,7 @@ public function __construct( IPresenterFactory $presenterFactory, Router $router, Nette\Http\IRequest $httpRequest, - Nette\Http\IResponse $httpResponse + Nette\Http\IResponse $httpResponse, ) { $this->httpRequest = $httpRequest; $this->httpResponse = $httpResponse; @@ -129,7 +129,7 @@ public function createInitialRequest(): Request $params, $this->httpRequest->getPost(), $this->httpRequest->getFiles(), - [Request::SECURED => $this->httpRequest->isSecured()] + [Request::SECURED => $this->httpRequest->isSecured()], ); } diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index 0f828f83e..38bb75df2 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -101,7 +101,7 @@ public function withReferenceUrl(string $url): self return new self( $this->router, new UrlScript($url), - $this->presenterFactory + $this->presenterFactory, ); } } diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 31101baa2..113c48b26 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -40,7 +40,7 @@ final class MicroPresenter implements Application\IPresenter public function __construct( ?Nette\DI\Container $context = null, ?Http\IRequest $httpRequest = null, - ?Router $router = null + ?Router $router = null, ) { $this->context = $context; $this->httpRequest = $httpRequest; @@ -86,7 +86,7 @@ public function run(Application\Request $request): Application\Response foreach ($reflection->getParameters() as $param) { $type = $param->getType(); if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) { - $params[$param->getName()] = $this->context->getByType($type->getName(), false); + $params[$param->getName()] = $this->context->getByType($type->getName(), throw: false); } } } diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index 30ccf853e..48548747e 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -37,7 +37,7 @@ class PresenterFactory implements IPresenterFactory */ public function __construct(?callable $factory = null) { - $this->factory = $factory ?: function (string $class): IPresenter { return new $class; }; + $this->factory = $factory ?: fn(string $class): IPresenter => new $class; } diff --git a/src/Application/Request.php b/src/Application/Request.php index 8075b34c4..22a00dba4 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -65,7 +65,7 @@ public function __construct( array $params = [], array $post = [], array $files = [], - array $flags = [] + array $flags = [], ) { $this->name = $name; $this->method = $method; diff --git a/src/Application/Responses/FileResponse.php b/src/Application/Responses/FileResponse.php index 35ae6d878..8953c3aa0 100644 --- a/src/Application/Responses/FileResponse.php +++ b/src/Application/Responses/FileResponse.php @@ -39,7 +39,7 @@ public function __construct( string $file, ?string $name = null, ?string $contentType = null, - bool $forceDownload = true + bool $forceDownload = true, ) { if (!is_file($file) || !is_readable($file)) { throw new Nette\Application\BadRequestException("File '$file' doesn't exist or is not readable."); @@ -89,7 +89,7 @@ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $htt 'Content-Disposition', ($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->name . '"' - . '; filename*=utf-8\'\'' . rawurlencode($this->name) + . '; filename*=utf-8\'\'' . rawurlencode($this->name), ); $filesize = $length = filesize($this->file); @@ -127,7 +127,7 @@ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $htt $httpResponse->setHeader('Content-Length', (string) $length); while (!feof($handle) && $length > 0) { - echo $s = fread($handle, min(4000000, $length)); + echo $s = fread($handle, min(4_000_000, $length)); $length -= strlen($s); } diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index 441c18f83..062cfe41d 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -72,7 +72,7 @@ public function addRoute( #[Language('TEXT')] string $mask, $metadata = [], - int $flags = 0 + int $flags = 0, ) { $this->add(new Route($mask, $metadata), $flags); return $this; diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index b8ed3259f..def90a0d4 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -70,7 +70,7 @@ public function hasPresenter(): bool */ public function getUniqueId(): string { - return $this->lookupPath(Presenter::class, true); + return $this->lookupPath(Presenter::class); } @@ -78,7 +78,7 @@ protected function createComponent(string $name): ?Nette\ComponentModel\ICompone { $res = parent::createComponent($name); if ($res && !$res instanceof SignalReceiver && !$res instanceof StatePersistent) { - $type = get_class($res); + $type = $res::class; trigger_error("It seems that component '$name' of type $type is not intended to be used in the Presenter.", E_USER_NOTICE); } @@ -165,7 +165,7 @@ public function loadState(array $params): void $name, $this instanceof Presenter ? 'presenter ' . $this->getName() : "component '{$this->getUniqueId()}'", $meta['type'], - is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]) + is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]), )); } @@ -333,7 +333,7 @@ public function redirectPermanent(string $destination, $args = []): void $presenter = $this->getPresenter(); $presenter->redirectUrl( $presenter->createRequest($this, $destination, $args, 'redirect'), - Nette\Http\IResponse::S301_MOVED_PERMANENTLY + Nette\Http\IResponse::S301_MOVED_PERMANENTLY, ); } diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 9d27cd5ab..acf677577 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -84,9 +84,7 @@ public function getParameters(): array */ public function getPersistentParams(): array { - return array_filter($this->getParameters(), function ($param) { - return array_key_exists('since', $param); - }); + return array_filter($this->getParameters(), fn($param) => array_key_exists('since', $param)); } @@ -117,7 +115,7 @@ public function getPersistentComponents(): array */ public function saveState(Component $component, array &$params): void { - $tree = self::getClassesAndTraits(get_class($component)); + $tree = self::getClassesAndTraits($component::class); foreach ($this->getPersistentParams() as $name => $meta) { if (isset($params[$name])) { @@ -140,7 +138,7 @@ public function saveState(Component $component, array &$params): void $name, $component instanceof Presenter ? 'presenter ' . $component->getName() : "component '{$component->getUniqueId()}'", $meta['type'], - is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]) + is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]), )); } @@ -186,7 +184,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a $name, ($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName(), $type, - is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]) + is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]), )); } } elseif ($param->isDefaultValueAvailable()) { @@ -199,7 +197,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a throw new Nette\InvalidArgumentException(sprintf( 'Missing parameter $%s required by %s()', $name, - ($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName() + ($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName(), )); } } @@ -230,25 +228,14 @@ private static function convertSingleType(&$val, string $type): bool { $scalars = ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'true' => 1, 'false' => 1, 'boolean' => 1, 'double' => 1, 'integer' => 1]; $tests = ['iterable' => 1, 'object' => 1, 'array' => 1, 'null' => 1]; - - if (isset($scalars[$type])) { - return self::dataLossConvert($val, $type); - - } elseif (isset($tests[$type])) { - return "is_$type"($val); - - } elseif ($type === 'scalar') { // special historical type - return !is_array($val); - - } elseif ($type === 'mixed') { - return true; - - } elseif ($type === 'callable') { - return false; - - } else { - return $val instanceof $type; - } + return match (true) { + isset($scalars[$type]) => self::dataLossConvert($val, $type), + isset($tests[$type]) => "is_$type"($val), + $type === 'scalar' => !is_array($val), // special historical type + $type === 'mixed' => true, + $type === 'callable' => false, + default => $val instanceof $type, + }; } diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index a2b24afeb..d8b6be269 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -76,12 +76,12 @@ protected function checkTemplateClass(string $class): ?string { if (!class_exists($class)) { return null; - } elseif (!is_a($class, Template::class, true)) { + } elseif (!is_a($class, Template::class, allow_string: true)) { trigger_error(sprintf( '%s: class %s was found but does not implement the %s, so it will not be used for the template.', static::class, $class, - Template::class + Template::class, ), E_USER_NOTICE); return null; } else { diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 28b0b32c2..0addc93cb 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -231,7 +231,7 @@ public function run(Application\Request $request): Application\Response // autoload components foreach ($this->globalParams as $id => $foo) { - $this->getComponent((string) $id, false); + $this->getComponent((string) $id, throw: false); } if ($this->autoCanonicalize) { @@ -340,7 +340,7 @@ public function detectedCsrf(): void protected function checkHttpMethod(): void { if ($this->allowedMethods && - !in_array($method = $this->httpRequest->getMethod(), $this->allowedMethods, true) + !in_array($method = $this->httpRequest->getMethod(), $this->allowedMethods, strict: true) ) { $this->httpResponse->setHeader('Allow', implode(',', $this->allowedMethods)); $this->error("Method $method is not allowed", Nette\Http\IResponse::S405_MethodNotAllowed); @@ -362,7 +362,7 @@ public function processSignal(): void $component = $this->signalReceiver === '' ? $this - : $this->getComponent($this->signalReceiver, false); + : $this->getComponent($this->signalReceiver, throw: false); if ($component === null) { throw new BadSignalException("The signal receiver component '$this->signalReceiver' is not found."); @@ -393,7 +393,7 @@ final public function isSignalReceiver($component, $signal = null): bool if ($component instanceof Nette\ComponentModel\Component) { $component = $component === $this ? '' - : $component->lookupPath(self::class, true); + : $component->lookupPath(self::class); } if ($this->signal === null) { @@ -482,7 +482,7 @@ public function setLayout($layout) */ public function sendTemplate(?Template $template = null): void { - $template = $template ?? $this->getTemplate(); + $template ??= $this->getTemplate(); if (!$template->getFile()) { $template->setFile($this->findTemplateFile()); } @@ -765,7 +765,7 @@ public function canonicalize(?string $destination = null, ...$args): void $this, $destination ?: $this->action, $args + $this->getGlobalState() + $request->getParameters(), - 'redirectX' + 'redirectX', ); } catch (InvalidLinkException $e) { } @@ -813,7 +813,7 @@ protected function createRequest( Component $component, string $destination, array $args, - string $mode + string $mode, ): ?string { // note: createRequest supposes that saveState(), run() & tryCall() behaviour is final @@ -868,7 +868,7 @@ protected function createRequest( // PROCESS SIGNAL ARGUMENTS if (isset($signal)) { // $component must be StatePersistent - $reflection = new ComponentReflection(get_class($component)); + $reflection = new ComponentReflection($component::class); if ($signal === 'this') { // means "no signal" $signal = ''; if (array_key_exists(0, $args)) { @@ -885,11 +885,11 @@ protected function createRequest( $this->invalidLinkMode && ComponentReflection::parseAnnotation(new \ReflectionMethod($component, $method), 'deprecated') ) { - trigger_error("Link to deprecated signal '$signal'" . ($component === $this ? '' : ' in ' . get_class($component)) . " from '{$this->getName()}:{$this->getAction()}'.", E_USER_DEPRECATED); + trigger_error("Link to deprecated signal '$signal'" . ($component === $this ? '' : ' in ' . $component::class) . " from '{$this->getName()}:{$this->getAction()}'.", E_USER_DEPRECATED); } // convert indexed parameters to named - static::argsToParams(get_class($component), $method, $args, [], $missing); + static::argsToParams($component::class, $method, $args, [], $missing); } // counterpart of StatePersistent @@ -1068,7 +1068,7 @@ public static function argsToParams( string $method, array &$args, array $supplemental = [], - ?array &$missing = null + ?array &$missing = null, ): void { $i = 0; @@ -1110,7 +1110,7 @@ public static function argsToParams( $name, $rm->getDeclaringClass()->getName() . '::' . $rm->getName(), $type, - is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]) + is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]), )); } @@ -1427,7 +1427,7 @@ final public function injectPrimary( Http\IResponse $httpResponse, ?Http\Session $session = null, ?Nette\Security\User $user = null, - ?TemplateFactory $templateFactory = null + ?TemplateFactory $templateFactory = null, ) { if ($this->presenterFactory !== null) { throw new Nette\InvalidStateException('Method ' . __METHOD__ . ' is intended for initialization and should not be called more than once.'); diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index 03cefac4f..ef1f7f811 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -42,7 +42,7 @@ public function __construct( bool $debugMode = false, ?array $scanDirs = null, ?string $tempDir = null, - ?Nette\Loaders\RobotLoader $robotLoader = null + ?Nette\Loaders\RobotLoader $robotLoader = null, ) { $this->debugMode = $debugMode; $this->scanDirs = (array) $scanDirs; @@ -60,7 +60,7 @@ public function getConfigSchema(): Nette\Schema\Schema 'mapping' => Expect::arrayOf('string|array'), 'scanDirs' => Expect::anyOf( Expect::arrayOf('string')->default($this->scanDirs)->mergeDefaults(), - false + false, )->firstIsDefault(), 'scanComposer' => Expect::bool(class_exists(ClassLoader::class)), 'scanFilter' => Expect::string('*Presenter'), @@ -96,7 +96,7 @@ public function loadConfiguration() ->setType(Nette\Application\IPresenterFactory::class) ->setFactory(Nette\Application\PresenterFactory::class, [new Definitions\Statement( Nette\Bridges\ApplicationDI\PresenterFactoryCallback::class, - [1 => $this->invalidLinkMode, $touch ?? null] + [1 => $this->invalidLinkMode, $touch ?? null], )]); if ($config->mapping) { @@ -184,9 +184,7 @@ private function findPresenters(): array $classFile = dirname($rc->getFileName()) . '/autoload_classmap.php'; if (is_file($classFile)) { $this->getContainerBuilder()->addDependency($classFile); - $classes = array_merge($classes, array_keys((function ($path) { - return require $path; - })($classFile))); + $classes = array_merge($classes, array_keys((fn($path) => require $path)($classFile))); } } @@ -210,7 +208,7 @@ private function findPresenters(): array /** @internal */ public static function initializeBlueScreenPanel( Tracy\BlueScreen $blueScreen, - Nette\Application\Application $application + Nette\Application\Application $application, ): void { $blueScreen->addPanel(function (?\Throwable $e) use ($application, $blueScreen): ?array { diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 608e7982a..378dd2786 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -113,7 +113,7 @@ public function beforeCompile() public static function initLattePanel( Nette\Application\UI\TemplateFactory $factory, Tracy\Bar $bar, - bool $all = false + bool $all = false, ) { if (!$factory instanceof ApplicationLatte\TemplateFactory) { return; diff --git a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php index f982f3dd8..3728dd9b4 100644 --- a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php +++ b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php @@ -40,7 +40,7 @@ public function __invoke(string $class): Nette\Application\IPresenter { $services = $this->container->findByType($class); if (count($services) > 1) { - $exact = array_keys(array_map([$this->container, 'getServiceType'], $services), $class, true); + $exact = array_keys(array_map([$this->container, 'getServiceType'], $services), $class, strict: true); if (count($exact) === 1) { return $this->container->createService($services[$exact[0]]); } diff --git a/src/Bridges/ApplicationLatte/SnippetDriver.php b/src/Bridges/ApplicationLatte/SnippetDriver.php index 0b6cb0b31..7999db6fd 100644 --- a/src/Bridges/ApplicationLatte/SnippetDriver.php +++ b/src/Bridges/ApplicationLatte/SnippetDriver.php @@ -57,7 +57,7 @@ public function enter(string $name, string $type): void ($this->nestingLevel === 0 && $this->control->isControlInvalid($name)) || ($type === self::TypeDynamic && ($previous = end($this->stack)) && $previous[1] === true) ) { - ob_start(function () {}); + ob_start(fn() => null); $this->nestingLevel = $type === self::TypeArea ? 0 : 1; $obStarted = true; } elseif ($this->nestingLevel > 0) { @@ -66,7 +66,7 @@ public function enter(string $name, string $type): void $this->stack[] = [$name, $obStarted]; if ($name !== '') { - $this->control->redrawControl($name, false); + $this->control->redrawControl($name, redraw: false); } } diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index fbebb4bd2..db495921c 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -110,11 +110,9 @@ public function setTranslator(?Nette\Localization\Translator $translator, ?strin if (version_compare(Latte\Engine::VERSION, '3', '<')) { $this->latte->addFilter( 'translate', - function (Latte\Runtime\FilterInfo $fi, ...$args) use ($translator): string { - return $translator === null + fn(Latte\Runtime\FilterInfo $fi, ...$args): string => $translator === null ? $args[0] - : $translator->translate(...$args); - } + : $translator->translate(...$args), ); } else { $this->latte->addExtension(new Latte\Essential\TranslatorExtension($translator, $language)); diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index a86705048..976d5a2d6 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -45,7 +45,7 @@ public function __construct( ?Nette\Http\IRequest $httpRequest = null, ?Nette\Security\User $user = null, ?Nette\Caching\Storage $cacheStorage = null, - $templateClass = null + $templateClass = null, ) { $this->latteFactory = $latteFactory; $this->httpRequest = $httpRequest; @@ -62,8 +62,8 @@ public function __construct( /** @return Template */ public function createTemplate(?UI\Control $control = null, ?string $class = null): UI\Template { - $class = $class ?? $this->templateClass; - if (!is_a($class, Template::class, true)) { + $class ??= $this->templateClass; + if (!is_a($class, Template::class, allow_string: true)) { throw new Nette\InvalidArgumentException("Class $class does not implement " . Template::class . ' or it does not exist.'); } @@ -86,11 +86,9 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul } } - $latte->addFilter('modifyDate', function ($time, $delta, $unit = null) { - return $time + $latte->addFilter('modifyDate', fn($time, $delta, $unit = null) => $time ? Nette\Utils\DateTime::from($time)->modify($delta . $unit) - : null; - }); + : null); if (!isset($latte->getFilters()['translate'])) { $latte->addFilter('translate', function (Latte\Runtime\FilterInfo $fi): void { @@ -131,7 +129,7 @@ private function setupLatte2( Latte\Engine $latte, ?UI\Control $control, ?UI\Presenter $presenter, - Template $template + Template $template, ): void { if ($latte->onCompile instanceof \Traversable) { diff --git a/src/Bridges/ApplicationLatte/UIMacros.php b/src/Bridges/ApplicationLatte/UIMacros.php index 841e8d9fe..4f512694b 100644 --- a/src/Bridges/ApplicationLatte/UIMacros.php +++ b/src/Bridges/ApplicationLatte/UIMacros.php @@ -38,9 +38,7 @@ public static function install(Latte\Compiler $compiler): void $me = new static($compiler); $me->addMacro('control', [$me, 'macroControl']); - $me->addMacro('href', null, null, function (MacroNode $node, PhpWriter $writer) use ($me): string { - return ' ?> href="macroLink($node, $writer) . ' ?>"addMacro('href', null, null, fn(MacroNode $node, PhpWriter $writer): string => ' ?> href="macroLink($node, $writer) . ' ?>"addMacro('plink', [$me, 'macroLink']); $me->addMacro('link', [$me, 'macroLink']); $me->addMacro('ifCurrent', [$me, 'macroIfCurrent'], '}'); // deprecated; use n:class="$presenter->linkCurrent ? ..." @@ -123,8 +121,8 @@ public function macroControl(MacroNode $node, PhpWriter $writer) . ($node->modifiers === '' ? "\$_tmp->$method($param);" : $writer->write( - "ob_start(function () {}); \$_tmp->$method($param); \$ʟ_fi = new LR\\FilterInfo(%var); echo %modifyContent(ob_get_clean());", - Latte\Engine::CONTENT_HTML + "ob_start(fn() => null); \$_tmp->$method($param); \$ʟ_fi = new LR\\FilterInfo(%var); echo %modifyContent(ob_get_clean());", + Latte\Engine::CONTENT_HTML, ) ); } @@ -143,7 +141,7 @@ public function macroLink(MacroNode $node, PhpWriter $writer) 'echo %escape(%modify(' . ($node->name === 'plink' ? '$this->global->uiPresenter' : '$this->global->uiControl') . '->link(%node.word, %node.array?)))' - . ($node->startLine ? " /* line $node->startLine */;" : ';') + . ($node->startLine ? " /* line $node->startLine */;" : ';'), ); } @@ -160,7 +158,7 @@ public function macroIfCurrent(MacroNode $node, PhpWriter $writer) return $writer->write( $node->args ? 'if ($this->global->uiPresenter->isLinkCurrent(%node.word, %node.array?)) {' - : 'if ($this->global->uiPresenter->getLastCreatedRequestFlag("current")) {' + : 'if ($this->global->uiPresenter->getLastCreatedRequestFlag("current")) {', ); } diff --git a/src/Bridges/ApplicationLatte/UIRuntime.php b/src/Bridges/ApplicationLatte/UIRuntime.php index 81cc2f182..ace3af72d 100644 --- a/src/Bridges/ApplicationLatte/UIRuntime.php +++ b/src/Bridges/ApplicationLatte/UIRuntime.php @@ -26,7 +26,7 @@ final class UIRuntime public static function initialize(Latte\Runtime\Template $template, &$parentName, array $blocks): void { $providers = $template->global; - $blocks = array_filter(array_keys($blocks), function (string $s): bool { return $s[0] !== '_'; }); + $blocks = array_filter(array_keys($blocks), fn(string $s): bool => $s[0] !== '_'); if ( $parentName === null && $blocks @@ -45,7 +45,7 @@ public static function printClass(Latte\Runtime\Template $template, ?string $par $params = $template->getParameters(); $control = $params['control'] ?? $params['presenter'] ?? null; if ($control) { - $name = preg_replace('#(Control|Presenter)$#', '', get_class($control)) . 'Template'; + $name = preg_replace('#(Control|Presenter)$#', '', $control::class) . 'Template'; unset($params[$control instanceof Presenter ? 'control' : 'presenter']); } diff --git a/src/Bridges/ApplicationTracy/RoutingPanel.php b/src/Bridges/ApplicationTracy/RoutingPanel.php index 381fcb69a..9ad50f11c 100644 --- a/src/Bridges/ApplicationTracy/RoutingPanel.php +++ b/src/Bridges/ApplicationTracy/RoutingPanel.php @@ -44,7 +44,7 @@ final class RoutingPanel implements Tracy\IBarPanel public function __construct( Routing\Router $router, Nette\Http\IRequest $httpRequest, - Nette\Application\IPresenterFactory $presenterFactory + Nette\Application\IPresenterFactory $presenterFactory, ) { $this->router = $router; $this->httpRequest = $httpRequest; @@ -74,7 +74,7 @@ public function getPanel(): string $matched = $this->matched; $routers = $this->routers; $source = $this->source; - $hasModule = (bool) array_filter($routers, function (\stdClass $rq): string { return $rq->module; }); + $hasModule = (bool) array_filter($routers, fn(\stdClass $rq): string => $rq->module); $url = $this->httpRequest->getUrl(); $method = $this->httpRequest->getMethod(); require __DIR__ . '/templates/RoutingPanel.panel.phtml'; @@ -91,7 +91,7 @@ private function analyse( string $module = '', ?string $path = null, int $level = -1, - int $flag = 0 + int $flag = 0, ): void { if ($router instanceof Routing\RouteList) { @@ -156,7 +156,7 @@ private function analyse( $this->routers[] = (object) [ 'level' => max(0, $level), 'matched' => $matched, - 'class' => get_class($router), + 'class' => $router::class, 'defaults' => $router instanceof Routing\Route || $router instanceof Routing\SimpleRouter ? $router->getDefaults() : [], 'mask' => $router instanceof Routing\Route ? $router->getMask() : null, 'params' => $params, diff --git a/tests/Application/Application.run.phpt b/tests/Application/Application.run.phpt index 3b7c84382..d1fbad045 100644 --- a/tests/Application/Application.run.phpt +++ b/tests/Application/Application.run.phpt @@ -313,9 +313,11 @@ Assert::noError(function () use ($httpRequest, $httpResponse) { $app->catchExceptions = true; $app->errorPresenter = 'Error'; - Assert::exception(function () use ($app) { - $app->run(); - }, RuntimeException::class, 'Error at shutdown'); + Assert::exception( + fn() => $app->run(), + RuntimeException::class, + 'Error at shutdown', + ); Assert::count(2, $errors); Assert::equal('Error at startup', $errors[0]->getMessage()); @@ -355,9 +357,7 @@ Assert::noError(function () use ($httpRequest, $httpResponse) { $errors[] = $e; }; - Assert::noError(function () use ($app) { - $app->run(); - }); + Assert::noError(fn() => $app->run()); Assert::count(1, $errors); Assert::same('Error on presenter', $errors[0]->getMessage()); @@ -391,18 +391,22 @@ Assert::noError(function () use ($httpRequest, $httpResponse) { // Use default maxLoop $app1 = clone $app; - Assert::exception(function () use ($app1) { - $app1->run(); - }, ApplicationException::class, 'Too many loops detected in application life cycle.'); + Assert::exception( + fn() => $app1->run(), + ApplicationException::class, + 'Too many loops detected in application life cycle.', + ); Assert::count(21, $app1->getRequests()); // Redefine maxLoop $app2 = clone $app; $app2->maxLoop = 2; - Assert::exception(function () use ($app2) { - $app2->run(); - }, ApplicationException::class, 'Too many loops detected in application life cycle.'); + Assert::exception( + fn() => $app2->run(), + ApplicationException::class, + 'Too many loops detected in application life cycle.', + ); Assert::count(3, $app2->getRequests()); }); diff --git a/tests/Application/MicroPresenter.invoke.phpt b/tests/Application/MicroPresenter.invoke.phpt index 7266a4e51..2376d885e 100644 --- a/tests/Application/MicroPresenter.invoke.phpt +++ b/tests/Application/MicroPresenter.invoke.phpt @@ -39,7 +39,7 @@ test('', function () { $presenter->run(new Request('Nette:Micro', 'GET', [ 'callback' => function (stdClass $obj) use (&$log) { - $log[] = get_class($obj); + $log[] = $obj::class; }, ])); Assert::same([ diff --git a/tests/Application/MicroPresenter.response.phpt b/tests/Application/MicroPresenter.response.phpt index a17de3268..ae5d7db32 100644 --- a/tests/Application/MicroPresenter.response.phpt +++ b/tests/Application/MicroPresenter.response.phpt @@ -40,9 +40,7 @@ function createContainer() test('', function () { $presenter = new NetteModule\MicroPresenter(createContainer()); $response = $presenter->run(new Request('Nette:Micro', 'GET', [ - 'callback' => function () { - return 'test'; - }, + 'callback' => fn() => 'test', ])); Assert::type(Nette\Application\Responses\TextResponse::class, $response); @@ -53,9 +51,7 @@ test('', function () { test('', function () { $presenter = new NetteModule\MicroPresenter(createContainer()); $response = $presenter->run(new Request('Nette:Micro', 'GET', [ - 'callback' => function ($param) { - return $param; - }, + 'callback' => fn($param) => $param, 'param' => 'test', ])); @@ -67,9 +63,7 @@ test('', function () { test('', function () { $presenter = new NetteModule\MicroPresenter(createContainer()); $response = $presenter->run(new Request('Nette:Micro', 'GET', [ - 'callback' => function () { - return '{=date(Y)}'; - }, + 'callback' => fn() => '{=date(Y)}', ])); Assert::type(Nette\Application\Responses\TextResponse::class, $response); @@ -80,9 +74,7 @@ test('', function () { test('', function () { $presenter = new NetteModule\MicroPresenter(createContainer()); $response = $presenter->run(new Request('Nette:Micro', 'GET', [ - 'callback' => function () { - return [new SplFileInfo(Tester\FileMock::create('{$param}')), []]; - }, + 'callback' => fn() => [new SplFileInfo(Tester\FileMock::create('{$param}')), []], 'param' => 'test', ])); @@ -96,9 +88,7 @@ test('', function () { $response = $presenter->run(new Request('Nette:Micro', 'GET', [ 'callback' => function ($presenter) { - $template = $presenter->createTemplate(null, function () { - return new Latte\Engine; - }); + $template = $presenter->createTemplate(null, fn() => new Latte\Engine); $template->getLatte()->setLoader(new Latte\Loaders\StringLoader); $template->setFile('test'); @@ -116,9 +106,7 @@ test('', function () { $response = $presenter->run(new Request('Nette:Micro', 'GET', [ 'callback' => function ($presenter) { - $template = $presenter->createTemplate(null, function () { - return new Latte\Engine; - }); + $template = $presenter->createTemplate(null, fn() => new Latte\Engine); $template->getLatte()->setLoader(new Latte\Loaders\FileLoader); $template->setFile(Tester\FileMock::create('{$param}')); $template->setParameters(['param' => 'test']); @@ -139,9 +127,7 @@ test('', function () { $response = $presenter->run(new Request('Nette:Micro', 'GET', [ 'callback' => function ($presenter) use ($filename) { - $template = $presenter->createTemplate(null, function () { - return new Latte\Engine; - }); + $template = $presenter->createTemplate(null, fn() => new Latte\Engine); $template->getLatte()->setLoader(new Latte\Loaders\FileLoader); $template->setFile($filename); $template->setParameters(['param' => 'test']); diff --git a/tests/Application/Presenter.twoDomains.phpt b/tests/Application/Presenter.twoDomains.phpt index 78a4fcb57..78df3898b 100644 --- a/tests/Application/Presenter.twoDomains.phpt +++ b/tests/Application/Presenter.twoDomains.phpt @@ -32,7 +32,7 @@ function testLink($domain) Mockery::mock(Nette\Application\IPresenterFactory::class), new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $request = new Application\Request('Test', Http\Request::GET, []); diff --git a/tests/Application/PresenterFactory.formatPresenterClass.phpt b/tests/Application/PresenterFactory.formatPresenterClass.phpt index 694c3017e..786c74a72 100644 --- a/tests/Application/PresenterFactory.formatPresenterClass.phpt +++ b/tests/Application/PresenterFactory.formatPresenterClass.phpt @@ -80,5 +80,5 @@ Assert::exception( ]); }, Nette\InvalidStateException::class, - 'Invalid mapping mask for module *.' + 'Invalid mapping mask for module *.', ); diff --git a/tests/Bridges.DI/ApplicationExtension.invalidLink.phpt b/tests/Bridges.DI/ApplicationExtension.invalidLink.phpt index 6768f0310..7f02c95b9 100644 --- a/tests/Bridges.DI/ApplicationExtension.invalidLink.phpt +++ b/tests/Bridges.DI/ApplicationExtension.invalidLink.phpt @@ -39,7 +39,7 @@ test('', function () { $container = new Container4; Assert::same( Presenter::InvalidLinkTextual, - $container->getService('presenter')->invalidLinkMode + $container->getService('presenter')->invalidLinkMode, ); }); @@ -59,7 +59,7 @@ test('', function () { $container = new Container5; Assert::same( Presenter::InvalidLinkWarning | Presenter::InvalidLinkTextual, - $container->getService('presenter')->invalidLinkMode + $container->getService('presenter')->invalidLinkMode, ); }); @@ -79,7 +79,7 @@ test('', function () { $container = new Container6; Assert::same( Presenter::InvalidLinkWarning, - $container->getService('presenter')->invalidLinkMode + $container->getService('presenter')->invalidLinkMode, ); }); @@ -99,6 +99,6 @@ test('', function () { $container = new Container7; Assert::same( Presenter::InvalidLinkWarning, - $container->getService('presenter')->invalidLinkMode + $container->getService('presenter')->invalidLinkMode, ); }); diff --git a/tests/Bridges.DI/LatteExtension.2.phpt b/tests/Bridges.DI/LatteExtension.2.phpt index 529b314da..ec591fbe2 100644 --- a/tests/Bridges.DI/LatteExtension.2.phpt +++ b/tests/Bridges.DI/LatteExtension.2.phpt @@ -22,7 +22,7 @@ class LoremIpsumMacros extends Latte\Macros\MacroSet { $me = new static($compiler); $me->addMacro('lorem', 'lorem'); - Notes::add(get_class($me)); + Notes::add($me::class); } } @@ -33,7 +33,7 @@ class IpsumLoremMacros extends Latte\Macros\MacroSet { $me = new static($compiler); $me->addMacro('ipsum', 'ipsum'); - Notes::add(get_class($me)); + Notes::add($me::class); } } @@ -44,7 +44,7 @@ class FooMacros extends Latte\Macros\MacroSet { $me = new static($compiler); $me->addMacro('foo', 'foo'); - Notes::add(get_class($me)); + Notes::add($me::class); } } diff --git a/tests/Bridges.DI/LatteExtension.basic.phpt b/tests/Bridges.DI/LatteExtension.basic.phpt index 80b093a28..97eae58cc 100644 --- a/tests/Bridges.DI/LatteExtension.basic.phpt +++ b/tests/Bridges.DI/LatteExtension.basic.phpt @@ -52,7 +52,7 @@ services: ', 'neon')); $compiler = new DI\Compiler; -$compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension('', false)); +$compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension('', debugMode: false)); $compiler->addExtension('another', new AnotherExtension); $code = $compiler->addConfig($config)->compile(); eval($code); diff --git a/tests/Bridges.Latte2/Template.getParentName().phpt b/tests/Bridges.Latte2/Template.getParentName().phpt index ad39fbb92..1253c4a4e 100644 --- a/tests/Bridges.Latte2/Template.getParentName().phpt +++ b/tests/Bridges.Latte2/Template.getParentName().phpt @@ -43,7 +43,7 @@ Assert::same('file.latte', $template->getParentName()); $template = $latte->createTemplate( '{extends $file} {block name}...{/block}', - ['file' => 'file.latte'] + ['file' => 'file.latte'], ); $template->prepare(); Assert::same('file.latte', $template->getParentName()); diff --git a/tests/Bridges.Latte2/TemplateFactory.filters.phpt b/tests/Bridges.Latte2/TemplateFactory.filters.phpt index 2f0dc06a0..57e879543 100644 --- a/tests/Bridges.Latte2/TemplateFactory.filters.phpt +++ b/tests/Bridges.Latte2/TemplateFactory.filters.phpt @@ -41,7 +41,7 @@ setlocale(LC_TIME, 'C'); date_default_timezone_set('Europe/Prague'); Assert::null($latte->invokeFilter('modifyDate', [null, null])); -Assert::same('1978-01-24 11:40:00', (string) $latte->invokeFilter('modifyDate', [254400000, '+1 day'])); +Assert::same('1978-01-24 11:40:00', (string) $latte->invokeFilter('modifyDate', [254_400_000, '+1 day'])); Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', ['1978-05-05', '+1 day'])); Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', [new DateTime('1978-05-05'), '1day'])); -Assert::same('1978-01-22 11:40:00', (string) $latte->invokeFilter('modifyDate', [254400000, -1, 'day'])); +Assert::same('1978-01-22 11:40:00', (string) $latte->invokeFilter('modifyDate', [254_400_000, -1, 'day'])); diff --git a/tests/Bridges.Latte2/TemplateFactory.nonce.control.phpt b/tests/Bridges.Latte2/TemplateFactory.nonce.control.phpt index 884de3846..850629b36 100644 --- a/tests/Bridges.Latte2/TemplateFactory.nonce.control.phpt +++ b/tests/Bridges.Latte2/TemplateFactory.nonce.control.phpt @@ -35,5 +35,5 @@ $latte->setLoader(new Latte\Loaders\StringLoader); Assert::match( '', - $latte->renderToString('') + $latte->renderToString(''), ); diff --git a/tests/Bridges.Latte2/TemplateFactory.nonce.presenter.phpt b/tests/Bridges.Latte2/TemplateFactory.nonce.presenter.phpt index 1109e6f57..1ef2df0e8 100644 --- a/tests/Bridges.Latte2/TemplateFactory.nonce.presenter.phpt +++ b/tests/Bridges.Latte2/TemplateFactory.nonce.presenter.phpt @@ -38,5 +38,5 @@ $latte->setLoader(new Latte\Loaders\StringLoader); Assert::match( '', - $latte->renderToString('') + $latte->renderToString(''), ); diff --git a/tests/Bridges.Latte2/UIMacros.control.3.phpt b/tests/Bridges.Latte2/UIMacros.control.3.phpt index af40b47a6..f5d6e23d2 100644 --- a/tests/Bridges.Latte2/UIMacros.control.3.phpt +++ b/tests/Bridges.Latte2/UIMacros.control.3.phpt @@ -38,12 +38,12 @@ Assert::exception(function () use ($latte) { Assert::same( '
&', - $latte->renderToString('
renderToString('
', - $latte->renderToString('
') + $latte->renderToString('
'), ); Assert::exception(function () use ($latte) { diff --git a/tests/Bridges.Latte2/UIMacros.control.phpt b/tests/Bridges.Latte2/UIMacros.control.phpt index 7595a348c..01c403e38 100644 --- a/tests/Bridges.Latte2/UIMacros.control.phpt +++ b/tests/Bridges.Latte2/UIMacros.control.phpt @@ -23,68 +23,66 @@ UIMacros::install($latte->getCompiler()); // {control ...} Assert::match( '%A% $this->global->uiControl->getComponent("form");%A%->render();%A%', - $latte->compile('{control form}') + $latte->compile('{control form}'), ); @Assert::match( <<<'XX' -%A% - /* line 1 */ $_tmp = $this->global->uiControl->getComponent("form"); - if ($_tmp instanceof Nette\Application\UI\Renderable) $_tmp->redrawControl(null, false); - ob_start(function () {}); - $_tmp->render(); - $ʟ_fi = new LR\FilterInfo('html'); - echo $this->filters->filterContent('filter', $ʟ_fi, ob_get_clean()); -%A% -XX - , - $latte->compile('{control form|filter}') + %A% + /* line 1 */ $_tmp = $this->global->uiControl->getComponent("form"); + if ($_tmp instanceof Nette\Application\UI\Renderable) $_tmp->redrawControl(null, false); + ob_start(function () {}); + $_tmp->render(); + $ʟ_fi = new LR\FilterInfo('html'); + echo $this->filters->filterContent('filter', $ʟ_fi, ob_get_clean()); + %A% + XX, + $latte->compile('{control form|filter}'), ); // @deprecated Assert::match( <<<'XX' -%A% - /* line 1 */ if (is_object($form)) $_tmp = $form; - else $_tmp = $this->global->uiControl->getComponent($form); - if ($_tmp instanceof Nette\Application\UI\Renderable) $_tmp->redrawControl(null, false); - $_tmp->render(); -%A% -XX - , - $latte->compile('{control $form}') + %A% + /* line 1 */ if (is_object($form)) $_tmp = $form; + else $_tmp = $this->global->uiControl->getComponent($form); + if ($_tmp instanceof Nette\Application\UI\Renderable) $_tmp->redrawControl(null, false); + $_tmp->render(); + %A% + XX, + $latte->compile('{control $form}'), ); Assert::match( '%A% $this->global->uiControl->getComponent("form");%A%->renderType();%A%', - $latte->compile('{control form:type}') + $latte->compile('{control form:type}'), ); Assert::match( '%A% $this->global->uiControl->getComponent("form");%A%->{"render$type"}();%A%', - $latte->compile('{control form:$type}') + $latte->compile('{control form:$type}'), ); Assert::match( '%A% $this->global->uiControl->getComponent("form");%A%->renderType(\'param\');%A%', - $latte->compile('{control form:type param}') + $latte->compile('{control form:type param}'), ); Assert::match( '%A% $this->global->uiControl->getComponent("form");%A%->render(array_merge([], $params, []));%A%', - $latte->compile('{control form (expand) $params}') + $latte->compile('{control form (expand) $params}'), ); Assert::match( '%A% $this->global->uiControl->getComponent("form");%A%->renderType([\'param\' => 123]);%A%', - $latte->compile('{control form:type param => 123}') + $latte->compile('{control form:type param => 123}'), ); Assert::match( '%A% $this->global->uiControl->getComponent("form");%A%->renderType([\'param\' => 123]);%A%', - $latte->compile('{control form:type, param => 123}') + $latte->compile('{control form:type, param => 123}'), ); Assert::match( '%A% $this->global->uiControl->getComponent("form");%A%->renderType(param: 123);%A%', - $latte->compile('{control form:type, param: 123}') + $latte->compile('{control form:type, param: 123}'), ); diff --git a/tests/Bridges.Latte2/UIMacros.isLinkCurrent.phpt b/tests/Bridges.Latte2/UIMacros.isLinkCurrent.phpt index d2a0eeb11..579a8fd4b 100644 --- a/tests/Bridges.Latte2/UIMacros.isLinkCurrent.phpt +++ b/tests/Bridges.Latte2/UIMacros.isLinkCurrent.phpt @@ -35,20 +35,20 @@ Assert::matchFile( __DIR__ . '/expected/UIMacros.isLinkCurrent.php', $latte->compile( <<<'XX' -n:href before n:class + n:href before n:class -n:href after n:class + n:href after n:class -href before n:class + href before n:class -href after n:class + href after n:class -{ifCurrent}empty{/ifCurrent} + {ifCurrent}empty{/ifCurrent} -{ifCurrent default}default{/ifCurrent} + {ifCurrent default}default{/ifCurrent} -custom function + custom function -XX - ) + XX, + ), ); diff --git a/tests/Bridges.Latte2/UIMacros.link.2.phpt b/tests/Bridges.Latte2/UIMacros.link.2.phpt index efa955b66..83a441c31 100644 --- a/tests/Bridges.Latte2/UIMacros.link.2.phpt +++ b/tests/Bridges.Latte2/UIMacros.link.2.phpt @@ -60,66 +60,63 @@ $params['action'] = 'login'; $params['arr'] = ['link' => 'login', 'param' => 123]; Assert::match(<<<'EOD' -plink:['Homepage:'] + plink:['Homepage:'] -plink:['Homepage:'] + plink:['Homepage:'] -plink:['Homepage:action'] + plink:['Homepage:action'] -plink:['Homepage:action'] + plink:['Homepage:action'] -plink:['Homepage:action',10,20,'{one}&two'] + plink:['Homepage:action',10,20,'{one}&two'] -plink:['Homepage:action#hash',10,20,'{one}&two'] + plink:['Homepage:action#hash',10,20,'{one}&two'] -plink:['#hash'] + plink:['#hash'] -plink:[':',10] + plink:[':',10] -plink:{'0':'default','1':10,'a':20,'b':30} + plink:{'0':'default','1':10,'a':20,'b':30} -link:['login'] + link:['login'] - + - + - + - + - -EOD + + EOD, strtr($latte->renderToString(<<<'EOD' + {plink Homepage:} - , strtr($latte->renderToString(<<<'EOD' -{plink Homepage:} + {plink Homepage: } -{plink Homepage: } + {plink Homepage:action } -{plink Homepage:action } + {plink 'Homepage:action' } -{plink 'Homepage:action' } + {plink Homepage:action 10, 20, '{one}&two'} -{plink Homepage:action 10, 20, '{one}&two'} + {plink Homepage:action#hash 10, 20, '{one}&two'} -{plink Homepage:action#hash 10, 20, '{one}&two'} + {plink #hash} -{plink #hash} + {plink : 10 } -{plink : 10 } + {plink default 10, 'a' => 20, 'b' => 30} -{plink default 10, 'a' => 20, 'b' => 30} + {link $action} -{link $action} + - + - + - + - - - -EOD - , $params), [''' => "'", ''' => "'", '{' => '{'])); + + EOD, $params), [''' => "'", ''' => "'", '{' => '{'])); diff --git a/tests/Bridges.Latte2/UIMacros.link.phpt b/tests/Bridges.Latte2/UIMacros.link.phpt index eef952030..52fda3fb0 100644 --- a/tests/Bridges.Latte2/UIMacros.link.phpt +++ b/tests/Bridges.Latte2/UIMacros.link.phpt @@ -23,46 +23,46 @@ UIMacros::install($latte->getCompiler()); // {link ...} Assert::contains( '$this->global->uiControl->link("p")', - $latte->compile('{link p}') + $latte->compile('{link p}'), ); Assert::contains( '($this->filters->filter)($this->global->uiControl->link("p"))', - $latte->compile('{link p|filter}') + $latte->compile('{link p|filter}'), ); Assert::contains( '$this->global->uiControl->link("p:a")', - $latte->compile('{link p:a}') + $latte->compile('{link p:a}'), ); Assert::contains( '$this->global->uiControl->link($dest)', - $latte->compile('{link $dest}') + $latte->compile('{link $dest}'), ); Assert::contains( '$this->global->uiControl->link($p:$a)', - $latte->compile('{link $p:$a}') + $latte->compile('{link $p:$a}'), ); Assert::contains( '$this->global->uiControl->link("$p:$a")', - $latte->compile('{link "$p:$a"}') + $latte->compile('{link "$p:$a"}'), ); Assert::contains( '$this->global->uiControl->link("p:a")', - $latte->compile('{link "p:a"}') + $latte->compile('{link "p:a"}'), ); Assert::contains( '$this->global->uiControl->link(\'p:a\')', - $latte->compile('{link \'p:a\'}') + $latte->compile('{link \'p:a\'}'), ); Assert::contains( '$this->global->uiControl->link("p", [\'param\'])', - $latte->compile('{link p param}') + $latte->compile('{link p param}'), ); Assert::contains( '$this->global->uiControl->link("p", [\'param\' => 123])', - $latte->compile('{link p param => 123}') + $latte->compile('{link p param => 123}'), ); Assert::contains( '$this->global->uiControl->link("p", [\'param\' => 123])', - $latte->compile('{link p, param => 123}') + $latte->compile('{link p, param => 123}'), ); diff --git a/tests/Bridges.Latte2/UIMacros.renderSnippets2.phpt b/tests/Bridges.Latte2/UIMacros.renderSnippets2.phpt index db25a5426..58a72d170 100644 --- a/tests/Bridges.Latte2/UIMacros.renderSnippets2.phpt +++ b/tests/Bridges.Latte2/UIMacros.renderSnippets2.phpt @@ -56,9 +56,7 @@ class TestPresenter extends Nette\Application\UI\Presenter { public function createComponentMulti() { - return new Nette\Application\UI\Multiplier(function () { - return new InnerControl; - }); + return new Nette\Application\UI\Multiplier(fn() => new InnerControl); } diff --git a/tests/Bridges.Latte3/TemplateFactory.filters.phpt b/tests/Bridges.Latte3/TemplateFactory.filters.phpt index 116e5bf01..4dc4de013 100644 --- a/tests/Bridges.Latte3/TemplateFactory.filters.phpt +++ b/tests/Bridges.Latte3/TemplateFactory.filters.phpt @@ -42,7 +42,7 @@ setlocale(LC_TIME, 'C'); date_default_timezone_set('Europe/Prague'); Assert::null($latte->invokeFilter('modifyDate', [null, null])); -Assert::same('1978-01-24 11:40:00', (string) $latte->invokeFilter('modifyDate', [254400000, '+1 day'])); +Assert::same('1978-01-24 11:40:00', (string) $latte->invokeFilter('modifyDate', [254_400_000, '+1 day'])); Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', ['1978-05-05', '+1 day'])); Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', [new DateTime('1978-05-05'), '1day'])); -Assert::same('1978-01-22 11:40:00', (string) $latte->invokeFilter('modifyDate', [254400000, -1, 'day'])); +Assert::same('1978-01-22 11:40:00', (string) $latte->invokeFilter('modifyDate', [254_400_000, -1, 'day'])); diff --git a/tests/Bridges.Latte3/renderSnippets7.phpt b/tests/Bridges.Latte3/renderSnippets7.phpt index 0f7af1821..910145bbc 100644 --- a/tests/Bridges.Latte3/renderSnippets7.phpt +++ b/tests/Bridges.Latte3/renderSnippets7.phpt @@ -196,7 +196,7 @@ $dataSets = [ foreach ($dataSets as $data) { //snippet mode $control = new ControlMock; - $control->invalid = array_fill_keys($data[3], true); + $control->invalid = array_fill_keys($data[3], value: true); $engine = new Latte\Engine; $engine->setLoader(new Latte\Loaders\StringLoader($data[0])); @@ -209,7 +209,7 @@ foreach ($dataSets as $data) { //non snippet mode $control = new ControlMock; $control->snippetMode = false; - $control->invalid = array_fill_keys($data[3], true); + $control->invalid = array_fill_keys($data[3], value: true); $engine = new Latte\Engine; $engine->setLoader(new Latte\Loaders\StringLoader($data[0])); diff --git a/tests/Bridges.Latte3/{control}.phpt b/tests/Bridges.Latte3/{control}.phpt index 0b22e87d8..dd6223618 100644 --- a/tests/Bridges.Latte3/{control}.phpt +++ b/tests/Bridges.Latte3/{control}.phpt @@ -50,8 +50,7 @@ Assert::match( %A% $ʟ_tmp->renderType() /* line 1 */; %A% - XX - , + XX, $latte->compile('{control form:type}'), ); diff --git a/tests/Bridges.Latte3/{link}.2.phpt b/tests/Bridges.Latte3/{link}.2.phpt index 3b5a63cbc..8f4e46772 100644 --- a/tests/Bridges.Latte3/{link}.2.phpt +++ b/tests/Bridges.Latte3/{link}.2.phpt @@ -88,9 +88,7 @@ Assert::match(<<<'EOD' - EOD - - , strtr($latte->renderToString(<<<'EOD' + EOD, strtr($latte->renderToString(<<<'EOD' {plink Homepage:} {plink Homepage: } @@ -120,5 +118,4 @@ Assert::match(<<<'EOD' - EOD - , $params), [''' => "'", ''' => "'", '{' => '{'])); + EOD, $params), [''' => "'", ''' => "'", '{' => '{'])); diff --git a/tests/Responses/FileResponse.range.phpt b/tests/Responses/FileResponse.range.phpt index b34a83261..575757227 100644 --- a/tests/Responses/FileResponse.range.phpt +++ b/tests/Responses/FileResponse.range.phpt @@ -23,7 +23,7 @@ test('', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=10-20']), - $response = new Http\Response + $response = new Http\Response, ); Assert::same(substr($origData, 10, 11), ob_get_clean()); Assert::same(206, $response->getCode()); @@ -34,7 +34,7 @@ test('', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=10-10']), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, 10, 1), ob_get_clean()); }); @@ -44,7 +44,7 @@ test('', function () use ($fileResponse, $origData, $file) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=10-' . filesize($file)]), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, 10), ob_get_clean()); }); @@ -54,7 +54,7 @@ test('prefix', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=20-']), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, 20), ob_get_clean()); }); @@ -64,7 +64,7 @@ test('prefix', function () use ($fileResponse, $origData, $file) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=' . (filesize($file) - 1) . '-']), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, -1), ob_get_clean()); }); @@ -74,7 +74,7 @@ test('prefix', function () use ($fileResponse, $file) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=' . filesize($file) . '-']), - $response = new Http\Response + $response = new Http\Response, ); Assert::same('', ob_get_clean()); Assert::same(416, $response->getCode()); @@ -85,7 +85,7 @@ test('suffix', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=-20']), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, -20), ob_get_clean()); }); @@ -95,7 +95,7 @@ test('suffix', function () use ($fileResponse, $origData, $file) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=-' . filesize($file)]), - new Http\Response + new Http\Response, ); Assert::same($origData, ob_get_clean()); }); diff --git a/tests/Routers/Route.errors.phpt b/tests/Routers/Route.errors.phpt index dc6338138..2cb4f3f83 100644 --- a/tests/Routers/Route.errors.phpt +++ b/tests/Routers/Route.errors.phpt @@ -13,18 +13,26 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::exception(function () { - $route = new Route('[a'); -}, Nette\InvalidArgumentException::class, "Unexpected '[' in mask '[a'."); - -Assert::exception(function () { - $route = new Route('a]'); -}, Nette\InvalidArgumentException::class, "Missing '[' in mask 'a]'."); - -Assert::exception(function () { - $route = new Route('///action>'); -}, Nette\InvalidArgumentException::class, "Unexpected '/action>' in mask '/action>'."); +Assert::exception( + fn() => new Route('[a'), + Nette\InvalidArgumentException::class, + "Unexpected '[' in mask '[a'.", +); + +Assert::exception( + fn() => new Route('a]'), + Nette\InvalidArgumentException::class, + "Missing '[' in mask 'a]'.", +); + +Assert::exception( + fn() => new Route('// new Route('/action>'), + Nette\InvalidArgumentException::class, + "Unexpected '/action>' in mask '/action>'.", +); diff --git a/tests/Routers/Route.filter.global.phpt b/tests/Routers/Route.filter.global.phpt index 9f648d095..660017f95 100644 --- a/tests/Routers/Route.filter.global.phpt +++ b/tests/Routers/Route.filter.global.phpt @@ -82,5 +82,5 @@ testRouteIn($route, '/cs/abc-cs/def-cs', [ Assert::same( 'http://example.com/cs/abc-cs/def-cs?test=testvalue', - testRouteOut($route, ['presenter' => 'Abc', 'lang' => 'cs', 'action' => 'def', 'test' => 'testvalue']) + testRouteOut($route, ['presenter' => 'Abc', 'lang' => 'cs', 'action' => 'def', 'test' => 'testvalue']), ); diff --git a/tests/Routers/Route.filter.query.phpt b/tests/Routers/Route.filter.query.phpt index 7d70be6d7..eb2aae981 100644 --- a/tests/Routers/Route.filter.query.phpt +++ b/tests/Routers/Route.filter.query.phpt @@ -16,12 +16,8 @@ require __DIR__ . '/Route.php'; $route = new Route(' ? action=', [ 'presenter' => [ - Route::FILTER_IN => function ($s) { - return strrev($s); - }, - Route::FILTER_OUT => function ($s) { - return strtoupper(strrev($s)); - }, + Route::FILTER_IN => fn($s) => strrev($s), + Route::FILTER_OUT => fn($s) => strtoupper(strrev($s)), ], ]); diff --git a/tests/Routers/Route.filter.url.object.phpt b/tests/Routers/Route.filter.url.object.phpt index d8082a52a..f9d23091b 100644 --- a/tests/Routers/Route.filter.url.object.phpt +++ b/tests/Routers/Route.filter.url.object.phpt @@ -24,12 +24,8 @@ $identityMap[2] = new RouterObject(2); $route = new Route('', [ 'presenter' => 'presenter', 'parameter' => [ - Route::FILTER_IN => function ($s) use ($identityMap) { - return $identityMap[$s] ?? null; - }, - Route::FILTER_OUT => function ($obj) { - return $obj instanceof RouterObject ? $obj->getId() : null; - }, + Route::FILTER_IN => fn($s) => $identityMap[$s] ?? null, + Route::FILTER_OUT => fn($obj) => $obj instanceof RouterObject ? $obj->getId() : null, ], ]); diff --git a/tests/Routers/Route.filter.url.phpt b/tests/Routers/Route.filter.url.phpt index 0bf25218a..d96abff62 100644 --- a/tests/Routers/Route.filter.url.phpt +++ b/tests/Routers/Route.filter.url.phpt @@ -16,12 +16,8 @@ require __DIR__ . '/Route.php'; $route = new Route('', [ 'presenter' => [ - Route::FILTER_IN => function ($s) { - return strrev($s); - }, - Route::FILTER_OUT => function ($s) { - return strrev($s); - }, + Route::FILTER_IN => fn($s) => strrev($s), + Route::FILTER_OUT => fn($s) => strrev($s), ], ]); diff --git a/tests/Routers/Route.optional.autooptional3.phpt b/tests/Routers/Route.optional.autooptional3.phpt index 020192b63..1034f58e0 100644 --- a/tests/Routers/Route.optional.autooptional3.phpt +++ b/tests/Routers/Route.optional.autooptional3.phpt @@ -37,10 +37,10 @@ Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'default' => 'abc' Assert::same( 'http://example.com/homepage/123/xyz', - testRouteOut($route, ['presenter' => 'Homepage', 'action' => 'default', 'required' => 'xyz']) + testRouteOut($route, ['presenter' => 'Homepage', 'action' => 'default', 'required' => 'xyz']), ); Assert::same( 'http://example.com/homepage/abc/xyz', - testRouteOut($route, ['presenter' => 'Homepage', 'action' => 'default', 'required' => 'xyz', 'default' => 'abc']) + testRouteOut($route, ['presenter' => 'Homepage', 'action' => 'default', 'required' => 'xyz', 'default' => 'abc']), ); diff --git a/tests/Routers/Route.scalarParams.phpt b/tests/Routers/Route.scalarParams.phpt index 7791a9020..4f475fea3 100644 --- a/tests/Routers/Route.scalarParams.phpt +++ b/tests/Routers/Route.scalarParams.phpt @@ -21,22 +21,22 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => null])); @@ -51,27 +51,27 @@ test('', function () { Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => ''])); @@ -85,27 +85,27 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => ''])); @@ -119,27 +119,27 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => ''])); @@ -153,27 +153,27 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => ''])); @@ -187,26 +187,26 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); }); diff --git a/tests/Routers/Route.secured.phpt b/tests/Routers/Route.secured.phpt index f5a0a79a4..195bb73e9 100644 --- a/tests/Routers/Route.secured.phpt +++ b/tests/Routers/Route.secured.phpt @@ -22,6 +22,6 @@ $route = new Route('', [ $url = $route->constructUrl( ['presenter' => 'Presenter', 'param' => 'any'], - new UrlScript('https://example.org') + new UrlScript('https://example.org'), ); Assert::same('https://example.org/any', $url); diff --git a/tests/Routers/Route.type.phpt b/tests/Routers/Route.type.phpt index 2faeb7a9b..bea846714 100644 --- a/tests/Routers/Route.type.phpt +++ b/tests/Routers/Route.type.phpt @@ -20,5 +20,5 @@ $params = ['id' => 5, 'presenter' => 'p']; Assert::same( 'http://example.com/?presenter=p', - $route->constructUrl($params, new Nette\Http\UrlScript('http://example.com')) + $route->constructUrl($params, new Nette\Http\UrlScript('http://example.com')), ); diff --git a/tests/Routers/Route.withHost.secured.phpt b/tests/Routers/Route.withHost.secured.phpt index 4ec0c0389..97c1d0a49 100644 --- a/tests/Routers/Route.withHost.secured.phpt +++ b/tests/Routers/Route.withHost.secured.phpt @@ -23,13 +23,13 @@ $route = new Route('//example.org/test', [ $url = $route->constructUrl( ['presenter' => 'Default', 'action' => 'default'], - new UrlScript('https://example.org') + new UrlScript('https://example.org'), ); Assert::same('https://example.org/test', $url); $url = $route->constructUrl( ['presenter' => 'Default', 'action' => 'default'], - new UrlScript('https://example.com') + new UrlScript('https://example.com'), ); Assert::same('https://example.org/test', $url); @@ -42,12 +42,12 @@ $route = new Route('https://example.org/test', [ $url = $route->constructUrl( ['presenter' => 'Default', 'action' => 'default'], - new UrlScript('https://example.org') + new UrlScript('https://example.org'), ); Assert::same('https://example.org/test', $url); $url = $route->constructUrl( ['presenter' => 'Default', 'action' => 'default'], - new UrlScript('https://example.com') + new UrlScript('https://example.com'), ); Assert::same('https://example.org/test', $url); diff --git a/tests/Routers/RouteList.addRoute.phpt b/tests/Routers/RouteList.addRoute.phpt index 57703b365..fd6ab423a 100644 --- a/tests/Routers/RouteList.addRoute.phpt +++ b/tests/Routers/RouteList.addRoute.phpt @@ -24,7 +24,7 @@ testRouteIn( $list, '/hello', ['presenter' => 'hello', 'test' => 'testvalue'], - '/hello?test=testvalue' + '/hello?test=testvalue', ); testRouteIn($list, '/none'); diff --git a/tests/Routers/RouteList.modules.phpt b/tests/Routers/RouteList.modules.phpt index d6086a333..db2aff0d2 100644 --- a/tests/Routers/RouteList.modules.phpt +++ b/tests/Routers/RouteList.modules.phpt @@ -35,5 +35,5 @@ testRouteIn( 'action' => 'default', 'test' => 'testvalue', ], - '/auth/?test=testvalue' + '/auth/?test=testvalue', ); diff --git a/tests/Routers/RouteList.withModule.phpt b/tests/Routers/RouteList.withModule.phpt index f9344cce5..01a067750 100644 --- a/tests/Routers/RouteList.withModule.phpt +++ b/tests/Routers/RouteList.withModule.phpt @@ -26,21 +26,21 @@ testRouteIn( $list, '/foo', ['presenter' => 'A:foo', 'test' => 'testvalue'], - '/foo?test=testvalue' + '/foo?test=testvalue', ); testRouteIn( $list, '/bar', ['presenter' => 'A:B:bar', 'test' => 'testvalue'], - '/bar?test=testvalue' + '/bar?test=testvalue', ); testRouteIn( $list, '/hello', ['presenter' => 'C:hello', 'test' => 'testvalue'], - '/hello?test=testvalue' + '/hello?test=testvalue', ); testRouteIn($list, '/none'); diff --git a/tests/UI/Component.isLinkCurrent().asserts.php b/tests/UI/Component.isLinkCurrent().asserts.php index d50da099e..4c0a1a5ad 100644 --- a/tests/UI/Component.isLinkCurrent().asserts.php +++ b/tests/UI/Component.isLinkCurrent().asserts.php @@ -23,7 +23,7 @@ function callIsComponentLinkCurrent( Application\UI\Component $component, Application\Request $request, $destination, - array $args + array $args, ): bool { $url = new Http\UrlScript('http://localhost/index.php', '/index.php'); @@ -35,7 +35,7 @@ function callIsComponentLinkCurrent( $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $presenter->onStartup[] = function () use (&$res, $component, $destination, $args) { $res = $component->isLinkCurrent($destination, $args); @@ -48,31 +48,31 @@ function callIsComponentLinkCurrent( Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:default', - [] + [], )); Assert::false(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:default', - ['int' => 2] + ['int' => 2], )); Assert::false(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, [Application\UI\Presenter::ActionKey => 'otherAction']), 'Test:default', - [] + [], )); Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, [Application\UI\Presenter::ActionKey => 'otherAction']), 'Test:otherAction', - [] + [], )); Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:default', - ['bool' => true] + ['bool' => true], )); Assert::true(callIsLinkCurrent( @@ -81,7 +81,7 @@ function callIsComponentLinkCurrent( [ 'bool' => true, 'int' => 1, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -90,7 +90,7 @@ function callIsComponentLinkCurrent( [ 'bool' => false, 'int' => 1, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -99,7 +99,7 @@ function callIsComponentLinkCurrent( [ 'bool' => false, 'int' => 2, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -108,7 +108,7 @@ function callIsComponentLinkCurrent( [ 'bool' => true, 'int' => 1, - ] + ], )); Assert::true(callIsLinkCurrent( @@ -117,31 +117,31 @@ function callIsComponentLinkCurrent( [ 'bool' => true, 'int' => 1, - ] + ], )); Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:*', - [] + [], )); Assert::false(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:*', - ['float' => 1.0] + ['float' => 1.0], )); Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true, 'float' => 1.0]), 'Test:*', - ['float' => 1.0] + ['float' => 1.0], )); Assert::false(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true, 'float' => 1.0]), 'Test:*', - ['float' => 2.0] + ['float' => 2.0], )); Assert::true(callIsLinkCurrent( @@ -149,7 +149,7 @@ function callIsComponentLinkCurrent( 'Test:*', [ 'int' => 1, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -157,7 +157,7 @@ function callIsComponentLinkCurrent( 'Test:*', [ 'int' => 1, - ] + ], )); Assert::true(callIsLinkCurrent( @@ -167,7 +167,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'Test:default', - [] + [], )); Assert::true(callIsLinkCurrent( @@ -177,7 +177,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'signal!', - [] + [], )); Assert::false(callIsLinkCurrent( @@ -187,7 +187,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'otherSignal!', - [] + [], )); @@ -201,7 +201,7 @@ function callIsComponentLinkCurrent( 'Test:default', [ Application\UI\Presenter::ActionKey => 'otherAction', - ] + ], )); Assert::false(callIsLinkCurrent( @@ -213,7 +213,7 @@ function callIsComponentLinkCurrent( 'Test:otherAction', [ Application\UI\Presenter::ActionKey => 'default', - ] + ], )); @@ -227,7 +227,7 @@ function callIsComponentLinkCurrent( 'signal!', [ Application\UI\Presenter::SignalKey => 'otherSignal', - ] + ], )); Assert::false(callIsLinkCurrent( @@ -239,7 +239,7 @@ function callIsComponentLinkCurrent( 'otherSignal!', [ Application\UI\Presenter::SignalKey => 'signal', - ] + ], )); @@ -256,7 +256,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'click!', - [] + [], )); $testPresenter = new TestPresenter; @@ -271,7 +271,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'otherSignal!', - [] + [], )); $testPresenter = new TestPresenter; @@ -289,7 +289,7 @@ function callIsComponentLinkCurrent( 'click!', [ 'x' => 1, - ] + ], )); $testPresenter = new TestPresenter; @@ -307,7 +307,7 @@ function callIsComponentLinkCurrent( 'click!', [ 'x' => 2, - ] + ], )); $testPresenter = new TestPresenter; @@ -326,7 +326,7 @@ function callIsComponentLinkCurrent( 'test:click!', [ 'x' => 1, - ] + ], )); $testPresenter = new TestPresenter; @@ -345,5 +345,5 @@ function callIsComponentLinkCurrent( 'test:click!', [ 'x' => 2, - ] + ], )); diff --git a/tests/UI/Component.redirect().phpt b/tests/UI/Component.redirect().phpt index 2a749c432..1894fe1ed 100644 --- a/tests/UI/Component.redirect().phpt +++ b/tests/UI/Component.redirect().phpt @@ -38,7 +38,7 @@ $presenter->injectPrimary( null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript('http://localhost')), - new Http\Response + new Http\Response, ); diff --git a/tests/UI/ComponentReflection.combineArgs.php80.phpt b/tests/UI/ComponentReflection.combineArgs.php80.phpt index f34392077..15f3745ae 100644 --- a/tests/UI/ComponentReflection.combineArgs.php80.phpt +++ b/tests/UI/ComponentReflection.combineArgs.php80.phpt @@ -27,19 +27,27 @@ test('', function () { Assert::same([1, 'abc'], Reflection::combineArgs($method, ['intArray' => '1', 'strArray' => 'abc'])); Assert::same([[1], [2]], Reflection::combineArgs($method, ['intArray' => [1], 'strArray' => [2]])); - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, []); - }, Nette\InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion()'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['intArray' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['intArray' => null]); - }, Nette\InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion()'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['intArray' => new stdClass]); - }, Nette\InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given.'); + Assert::exception( + fn() => Reflection::combineArgs($method, []), + Nette\InvalidArgumentException::class, + 'Missing parameter $intArray required by MyPresenter::hintsUnion()' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['intArray' => '']), + Nette\InvalidArgumentException::class, + 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['intArray' => null]), + Nette\InvalidArgumentException::class, + 'Missing parameter $intArray required by MyPresenter::hintsUnion()' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['intArray' => new stdClass]), + Nette\InvalidArgumentException::class, + 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given.' + ); }); diff --git a/tests/UI/ComponentReflection.combineArgs.phpt b/tests/UI/ComponentReflection.combineArgs.phpt index 5b13b8687..090c8e07b 100644 --- a/tests/UI/ComponentReflection.combineArgs.phpt +++ b/tests/UI/ComponentReflection.combineArgs.phpt @@ -29,7 +29,7 @@ class MyPresenter ?bool $bool = null, ?string $str = null, ?array $arr = null, - ?iterable $iter = null + ?iterable $iter = null, ) { } @@ -44,7 +44,7 @@ class MyPresenter bool $bool = false, string $str = '', array $arr = [], - iterable $iter = [] + iterable $iter = [], ) { } @@ -69,9 +69,11 @@ test('', function () { Assert::same([0, false, '', ''], Reflection::combineArgs($method, ['int' => 0, 'bool' => false, 'str' => '', 'arr' => ''])); Assert::equal([null, null, null, new stdClass], Reflection::combineArgs($method, ['arr' => new stdClass])); - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => []]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::params() must be scalar, array given.'); + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => []]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::params() must be scalar, array given.' + ); }); @@ -81,33 +83,47 @@ test('', function () { Assert::same([1, true, 'abc', [1], [2]], Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => 'abc', 'arr' => [1], 'iter' => [2]])); Assert::same([0, false, '', [], []], Reflection::combineArgs($method, ['int' => 0, 'bool' => false, 'str' => ''])); // missing 'arr', 'iter' - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, []); - }, Nette\InvalidArgumentException::class, 'Missing parameter $int required by MyPresenter::hints()'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hints() must be int, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => null]); - }, Nette\InvalidArgumentException::class, 'Missing parameter $int required by MyPresenter::hints()'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => new stdClass]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hints() must be int, stdClass given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => []]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hints() must be int, array given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $bool passed to MyPresenter::hints() must be bool, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $arr passed to MyPresenter::hints() must be array, string given.'); + Assert::exception( + fn() => Reflection::combineArgs($method, []), + Nette\InvalidArgumentException::class, + 'Missing parameter $int required by MyPresenter::hints()' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '']), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hints() must be int, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => null]), + Nette\InvalidArgumentException::class, + 'Missing parameter $int required by MyPresenter::hints()' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => new stdClass]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hints() must be int, stdClass given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => []]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hints() must be int, array given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), + Nette\InvalidArgumentException::class, + 'Argument $bool passed to MyPresenter::hints() must be bool, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), + Nette\InvalidArgumentException::class, + 'Argument $arr passed to MyPresenter::hints() must be array, string given.' + ); }); @@ -119,25 +135,35 @@ test('', function () { Assert::same([1, true, 'abc', [1], [1]], Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => 'abc', 'arr' => [1], 'iter' => [1]])); Assert::same([0, false, '', [], []], Reflection::combineArgs($method, ['int' => 0, 'bool' => false, 'str' => '', 'arr' => [], 'iter' => []])); - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hintsNulls() must be int, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => new stdClass]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hintsNulls() must be int, stdClass given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => []]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hintsNulls() must be int, array given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $bool passed to MyPresenter::hintsNulls() must be bool, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $arr passed to MyPresenter::hintsNulls() must be array, string given.'); + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '']), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hintsNulls() must be int, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => new stdClass]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hintsNulls() must be int, stdClass given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => []]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hintsNulls() must be int, array given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), + Nette\InvalidArgumentException::class, + 'Argument $bool passed to MyPresenter::hintsNulls() must be bool, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), + Nette\InvalidArgumentException::class, + 'Argument $arr passed to MyPresenter::hintsNulls() must be array, string given.' + ); }); @@ -149,25 +175,35 @@ test('', function () { Assert::same([1, true, 'abc', [1], [1]], Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => 'abc', 'arr' => [1], 'iter' => [1]])); Assert::same([0, false, '', [], []], Reflection::combineArgs($method, ['int' => 0, 'bool' => false, 'str' => '', 'arr' => [], 'iter' => []])); - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hintsNullable() must be int, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => new stdClass]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hintsNullable() must be int, stdClass given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => []]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hintsNullable() must be int, array given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $bool passed to MyPresenter::hintsNullable() must be bool, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $arr passed to MyPresenter::hintsNullable() must be array, string given.'); + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '']), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hintsNullable() must be int, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => new stdClass]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hintsNullable() must be int, stdClass given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => []]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hintsNullable() must be int, array given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), + Nette\InvalidArgumentException::class, + 'Argument $bool passed to MyPresenter::hintsNullable() must be bool, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), + Nette\InvalidArgumentException::class, + 'Argument $arr passed to MyPresenter::hintsNullable() must be array, string given.' + ); }); @@ -179,25 +215,35 @@ test('', function () { Assert::same([1, true, 'abc', [1], [1]], Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => 'abc', 'arr' => [1], 'iter' => [1]])); Assert::same([0, false, '', [], []], Reflection::combineArgs($method, ['int' => 0, 'bool' => false, 'str' => '', 'arr' => [], 'iter' => []])); - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hintsDefaults() must be int, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => new stdClass]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hintsDefaults() must be int, stdClass given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => []]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::hintsDefaults() must be int, array given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $bool passed to MyPresenter::hintsDefaults() must be bool, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $arr passed to MyPresenter::hintsDefaults() must be array, string given.'); + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '']), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hintsDefaults() must be int, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => new stdClass]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hintsDefaults() must be int, stdClass given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => []]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::hintsDefaults() must be int, array given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), + Nette\InvalidArgumentException::class, + 'Argument $bool passed to MyPresenter::hintsDefaults() must be bool, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), + Nette\InvalidArgumentException::class, + 'Argument $arr passed to MyPresenter::hintsDefaults() must be array, string given.' + ); }); @@ -209,25 +255,35 @@ test('', function () { Assert::same([1, true, 'abc', [1]], Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => 'abc', 'arr' => [1]])); Assert::same([0, false, '', []], Reflection::combineArgs($method, ['int' => 0, 'bool' => false, 'str' => '', 'arr' => []])); - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::defaults() must be integer, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => new stdClass]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::defaults() must be integer, stdClass given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => []]); - }, Nette\InvalidArgumentException::class, 'Argument $int passed to MyPresenter::defaults() must be integer, array given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $bool passed to MyPresenter::defaults() must be boolean, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $arr passed to MyPresenter::defaults() must be array, string given.'); + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '']), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::defaults() must be integer, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => new stdClass]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::defaults() must be integer, stdClass given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => []]), + Nette\InvalidArgumentException::class, + 'Argument $int passed to MyPresenter::defaults() must be integer, array given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), + Nette\InvalidArgumentException::class, + 'Argument $bool passed to MyPresenter::defaults() must be boolean, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), + Nette\InvalidArgumentException::class, + 'Argument $arr passed to MyPresenter::defaults() must be array, string given.' + ); }); @@ -236,19 +292,27 @@ test('', function () { Assert::equal([new stdClass, new stdClass, new stdClass], Reflection::combineArgs($method, ['req' => new stdClass, 'opt' => new stdClass, 'nullable' => new stdClass])); - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, []); - }, Nette\InvalidArgumentException::class, 'Missing parameter $req required by MyPresenter::objects()'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['req' => null, 'nullable' => null, 'opt' => null]); - }, Nette\InvalidArgumentException::class, 'Missing parameter $req required by MyPresenter::objects()'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['req' => $method, 'opt' => null]); - }, Nette\InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, ReflectionMethod given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['req' => [], 'opt' => null]); - }, Nette\InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.'); + Assert::exception( + fn() => Reflection::combineArgs($method, []), + Nette\InvalidArgumentException::class, + 'Missing parameter $req required by MyPresenter::objects()' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['req' => null, 'nullable' => null, 'opt' => null]), + Nette\InvalidArgumentException::class, + 'Missing parameter $req required by MyPresenter::objects()' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['req' => $method, 'opt' => null]), + Nette\InvalidArgumentException::class, + 'Argument $req passed to MyPresenter::objects() must be stdClass, ReflectionMethod given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['req' => [], 'opt' => null]), + Nette\InvalidArgumentException::class, + 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.' + ); }); diff --git a/tests/UI/Presenter.link().persistent.phpt b/tests/UI/Presenter.link().persistent.phpt index d29769e39..bd8861d0e 100644 --- a/tests/UI/Presenter.link().persistent.phpt +++ b/tests/UI/Presenter.link().persistent.phpt @@ -138,9 +138,7 @@ $url = new Http\UrlScript('http://localhost/index.php', '/index.php'); $presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class); $presenterFactory->shouldReceive('getPresenterClass') - ->andReturnUsing(function ($presenter) { - return $presenter . 'Presenter'; - }); + ->andReturnUsing(fn($presenter) => $presenter . 'Presenter'); $presenter = new TestPresenter; $presenter->injectPrimary( @@ -148,7 +146,7 @@ $presenter->injectPrimary( $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $presenter->invalidLinkMode = TestPresenter::InvalidLinkWarning; diff --git a/tests/UI/Presenter.link().php74.phpt b/tests/UI/Presenter.link().php74.phpt index 1bac7e36a..4c87c94aa 100644 --- a/tests/UI/Presenter.link().php74.phpt +++ b/tests/UI/Presenter.link().php74.phpt @@ -227,15 +227,19 @@ class TestPresenter extends Application\UI\Presenter // warning invalid link mode $this->invalidLinkMode = self::InvalidLinkWarning; - Assert::error(function () { - $this->link('params', ['p' => null, 'pbool' => 'a']); - }, E_USER_WARNING, "Invalid link: Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given."); + Assert::error( + fn() => $this->link('params', ['p' => null, 'pbool' => 'a']), + E_USER_WARNING, + "Invalid link: Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given." + ); // exception invalid link mode $this->invalidLinkMode = self::InvalidLinkException; - Assert::exception(function () { - $this->link('params', ['p' => null, 'pbool' => 'a']); - }, Nette\Application\UI\InvalidLinkException::class, "Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given."); + Assert::exception( + fn() => $this->link('params', ['p' => null, 'pbool' => 'a']), + Nette\Application\UI\InvalidLinkException::class, + "Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given." + ); $this->p = null; // null in persistent parameter means default Assert::same('/index.php?action=params&presenter=Test', $this->link('params')); @@ -300,9 +304,7 @@ $url = new Http\UrlScript('http://localhost/index.php', '/index.php'); $presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class); $presenterFactory->shouldReceive('getPresenterClass') - ->andReturnUsing(function ($presenter) { - return $presenter . 'Presenter'; - }); + ->andReturnUsing(fn($presenter) => $presenter . 'Presenter'); $presenter = new TestPresenter; $presenter->injectPrimary( @@ -310,7 +312,7 @@ $presenter->injectPrimary( $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $presenter->invalidLinkMode = TestPresenter::InvalidLinkWarning; diff --git a/tests/UI/Presenter.link().phpt b/tests/UI/Presenter.link().phpt index a0d3cc90d..5191f0d1d 100644 --- a/tests/UI/Presenter.link().phpt +++ b/tests/UI/Presenter.link().phpt @@ -213,15 +213,19 @@ class TestPresenter extends Application\UI\Presenter // warning invalid link mode $this->invalidLinkMode = self::InvalidLinkWarning; - Assert::error(function () { - $this->link('params', ['p' => null, 'pbool' => 'a']); - }, E_USER_WARNING, "Invalid link: Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given."); + Assert::error( + fn() => $this->link('params', ['p' => null, 'pbool' => 'a']), + E_USER_WARNING, + "Invalid link: Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given." + ); // exception invalid link mode $this->invalidLinkMode = self::InvalidLinkException; - Assert::exception(function () { - $this->link('params', ['p' => null, 'pbool' => 'a']); - }, Nette\Application\UI\InvalidLinkException::class, "Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given."); + Assert::exception( + fn() => $this->link('params', ['p' => null, 'pbool' => 'a']), + Nette\Application\UI\InvalidLinkException::class, + "Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given." + ); $this->p = null; // null in persistent parameter means default Assert::same('/index.php?action=params&presenter=Test', $this->link('params')); @@ -286,9 +290,7 @@ $url = new Http\UrlScript('http://localhost/index.php', '/index.php'); $presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class); $presenterFactory->shouldReceive('getPresenterClass') - ->andReturnUsing(function ($presenter) { - return $presenter . 'Presenter'; - }); + ->andReturnUsing(fn($presenter) => $presenter . 'Presenter'); $presenter = new TestPresenter; $presenter->injectPrimary( @@ -296,7 +298,7 @@ $presenter->injectPrimary( $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $presenter->invalidLinkMode = TestPresenter::InvalidLinkWarning; diff --git a/tests/UI/Presenter.paramChecking.phpt b/tests/UI/Presenter.paramChecking.phpt index f792d4e3a..0eb443e86 100644 --- a/tests/UI/Presenter.paramChecking.phpt +++ b/tests/UI/Presenter.paramChecking.phpt @@ -21,7 +21,7 @@ $presenter->injectPrimary( null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), - new Http\Response + new Http\Response, ); diff --git a/tests/UI/Presenter.parseDestination().phpt b/tests/UI/Presenter.parseDestination().phpt index a5b68905d..bb95c4e17 100644 --- a/tests/UI/Presenter.parseDestination().phpt +++ b/tests/UI/Presenter.parseDestination().phpt @@ -58,6 +58,7 @@ Assert::same([ 'fragment' => '#fragment', ], Presenter::parseDestination('a:b?a=b&c=d#fragment')); -Assert::exception(function () { - Presenter::parseDestination(''); -}, InvalidLinkException::class); +Assert::exception( + fn() => Presenter::parseDestination(''), + InvalidLinkException::class, +); diff --git a/tests/UI/Presenter.storeRequest().phpt b/tests/UI/Presenter.storeRequest().phpt index c61482497..022249f6e 100644 --- a/tests/UI/Presenter.storeRequest().phpt +++ b/tests/UI/Presenter.storeRequest().phpt @@ -35,7 +35,7 @@ class MockSession extends Http\Session public function getSection( string $section, - string $class = Nette\Http\SessionSection::class + string $class = Nette\Http\SessionSection::class, ): Nette\Http\SessionSection { return $this->testSection; @@ -125,7 +125,7 @@ test('', function () { new Http\Request(new Http\UrlScript), new Http\Response, $session = new MockSession, - $user = new MockUser + $user = new MockUser, ); $section = $session->testSection = new MockSessionSection($session); @@ -151,7 +151,7 @@ test('', function () { new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), new Http\Response, - $session = new MockSession + $session = new MockSession, ); $section = $session->testSection = new MockSessionSection($session); From 64c5a647f4103048e6887638f1a9406ec150f9bf Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 2 Oct 2023 18:05:19 +0200 Subject: [PATCH 09/42] removed support for PHP 7 --- src/Application/UI/Component.php | 2 +- src/Application/UI/ComponentReflection.php | 9 ++-- src/Application/UI/Link.php | 12 +---- src/Application/UI/Presenter.php | 4 +- src/Bridges/ApplicationLatte/Template.php | 13 +---- tests/Bridges.DI/LatteExtension.basic.phpt | 1 - .../Template.getParentName().phpt | 2 - .../TemplateFactory.customTemplate.phpt | 1 - .../TemplateFactory.filters.phpt | 1 - .../TemplateFactory.nonce.control.phpt | 1 - .../TemplateFactory.nonce.presenter.phpt | 1 - .../TemplateFactory.onCreate.phpt | 1 - tests/Bridges.Latte3/isLinkCurrent().phpt | 1 - tests/Bridges.Latte3/n-snippet.2.phpt | 2 - tests/Bridges.Latte3/n-snippet.block.phpt | 2 - tests/Bridges.Latte3/n-snippet.dynamic.phpt | 2 - tests/Bridges.Latte3/n-snippet.phpt | 2 - tests/Bridges.Latte3/renderSnippets.phpt | 1 - tests/Bridges.Latte3/renderSnippets2.phpt | 1 - tests/Bridges.Latte3/renderSnippets3.phpt | 1 - tests/Bridges.Latte3/renderSnippets4.phpt | 1 - tests/Bridges.Latte3/renderSnippets5.phpt | 1 - tests/Bridges.Latte3/renderSnippets6.phpt | 1 - tests/Bridges.Latte3/renderSnippets7.phpt | 2 - tests/Bridges.Latte3/{control}.2.phpt | 1 - tests/Bridges.Latte3/{control}.3.phpt | 1 - tests/Bridges.Latte3/{control}.phpt | 1 - tests/Bridges.Latte3/{ifCurrent}.phpt | 2 - tests/Bridges.Latte3/{link}.2.phpt | 1 - tests/Bridges.Latte3/{link}.phpt | 1 - tests/Bridges.Latte3/{snippet}.dynamic.phpt | 2 - tests/Bridges.Latte3/{snippet}.phpt | 2 - ...ComponentReflection.combineArgs.php80.phpt | 53 ------------------- tests/UI/ComponentReflection.combineArgs.phpt | 37 +++++++++++++ 34 files changed, 47 insertions(+), 119 deletions(-) delete mode 100644 tests/UI/ComponentReflection.combineArgs.php80.phpt diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index def90a0d4..8b35b9dd2 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -131,7 +131,7 @@ public function checkRequirements($element): void $element instanceof \ReflectionMethod && substr($element->getName(), 0, 6) === 'handle' && !ComponentReflection::parseAnnotation($element, 'crossOrigin') - && (PHP_VERSION_ID < 80000 || !$element->getAttributes(Nette\Application\Attributes\CrossOrigin::class)) + && !$element->getAttributes(Nette\Application\Attributes\CrossOrigin::class) && !$this->getPresenter()->getHttpRequest()->isSameSite() ) { $this->getPresenter()->detectedCsrf(); diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index acf677577..c8946e52d 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -48,8 +48,9 @@ public function getParameters(): array foreach ($this->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) { if ($prop->isStatic()) { continue; - } elseif (self::parseAnnotation($prop, 'persistent') - || (PHP_VERSION_ID >= 80000 && $prop->getAttributes(Nette\Application\Attributes\Persistent::class)) + } elseif ( + self::parseAnnotation($prop, 'persistent') + || $prop->getAttributes(Nette\Application\Attributes\Persistent::class) ) { $default = $defaults[$prop->getName()] ?? null; $params[$prop->getName()] = [ @@ -57,7 +58,7 @@ public function getParameters(): array 'type' => self::getPropertyType($prop, $default), 'since' => $isPresenter ? Nette\Utils\Reflection::getPropertyDeclaringClass($prop)->getName() : null, ]; - } elseif (PHP_VERSION_ID >= 80000 && $prop->getAttributes(Nette\Application\Attributes\Parameter::class)) { + } elseif ($prop->getAttributes(Nette\Application\Attributes\Parameter::class)) { $params[$prop->getName()] = [ 'type' => (string) ($prop->getType() ?? 'mixed'), ]; @@ -298,7 +299,7 @@ public static function getParameterType(\ReflectionParameter $param): string public static function getPropertyType(\ReflectionProperty $prop, $default): string { - $type = PHP_VERSION_ID < 70400 ? null : $prop->getType(); + $type = $prop->getType(); return $type ? ($type instanceof \ReflectionNamedType ? $type->getName() : (string) $type) : ($default === null ? 'scalar' : gettype($default)); diff --git a/src/Application/UI/Link.php b/src/Application/UI/Link.php index 6f52c09cd..048e27214 100644 --- a/src/Application/UI/Link.php +++ b/src/Application/UI/Link.php @@ -103,16 +103,6 @@ public function isLinkCurrent(): bool */ public function __toString(): string { - try { - return $this->component->link($this->destination, $this->params); - - } catch (\Throwable $e) { - if (func_num_args() || PHP_VERSION_ID >= 70400) { - throw $e; - } - - trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR); - return ''; - } + return $this->component->link($this->destination, $this->params); } } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 0addc93cb..a8007bf7f 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -1200,9 +1200,7 @@ public function restoreRequest(string $key): void public static function getPersistentComponents(): array { $rc = new \ReflectionClass(static::class); - $attrs = PHP_VERSION_ID >= 80000 - ? $rc->getAttributes(Application\Attributes\Persistent::class) - : null; + $attrs = $rc->getAttributes(Application\Attributes\Persistent::class); return $attrs ? $attrs[0]->getArguments() : (array) ComponentReflection::parseAnnotation($rc, 'persistent'); diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index db495921c..593c0c626 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -63,16 +63,7 @@ public function renderToString(?string $file = null, array $params = []): string */ public function __toString(): string { - try { - return $this->latte->renderToString($this->file, $this->getParameters()); - } catch (\Throwable $e) { - if (func_num_args() || PHP_VERSION_ID >= 70400) { - throw $e; - } - - trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR); - return ''; - } + return $this->latte->renderToString($this->file, $this->getParameters()); } @@ -148,7 +139,7 @@ final public function getParameters(): array { $res = []; foreach ((new \ReflectionObject($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) { - if (PHP_VERSION_ID < 70400 || $prop->isInitialized($this)) { + if ($prop->isInitialized($this)) { $res[$prop->getName()] = $prop->getValue($this); } } diff --git a/tests/Bridges.DI/LatteExtension.basic.phpt b/tests/Bridges.DI/LatteExtension.basic.phpt index 97eae58cc..1ee2f1416 100644 --- a/tests/Bridges.DI/LatteExtension.basic.phpt +++ b/tests/Bridges.DI/LatteExtension.basic.phpt @@ -2,7 +2,6 @@ /** * Test: LatteExtension v3 - * @phpVersion 8.0 */ declare(strict_types=1); diff --git a/tests/Bridges.Latte3/Template.getParentName().phpt b/tests/Bridges.Latte3/Template.getParentName().phpt index 9a4eaf96d..f007ab01c 100644 --- a/tests/Bridges.Latte3/Template.getParentName().phpt +++ b/tests/Bridges.Latte3/Template.getParentName().phpt @@ -1,7 +1,5 @@ '1', 'strArray' => 'abc'])); - Assert::same([[1], [2]], Reflection::combineArgs($method, ['intArray' => [1], 'strArray' => [2]])); - - Assert::exception( - fn() => Reflection::combineArgs($method, []), - Nette\InvalidArgumentException::class, - 'Missing parameter $intArray required by MyPresenter::hintsUnion()' - ); - - Assert::exception( - fn() => Reflection::combineArgs($method, ['intArray' => '']), - Nette\InvalidArgumentException::class, - 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given.' - ); - - Assert::exception( - fn() => Reflection::combineArgs($method, ['intArray' => null]), - Nette\InvalidArgumentException::class, - 'Missing parameter $intArray required by MyPresenter::hintsUnion()' - ); - - Assert::exception( - fn() => Reflection::combineArgs($method, ['intArray' => new stdClass]), - Nette\InvalidArgumentException::class, - 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given.' - ); -}); diff --git a/tests/UI/ComponentReflection.combineArgs.phpt b/tests/UI/ComponentReflection.combineArgs.phpt index 090c8e07b..3506cd3b2 100644 --- a/tests/UI/ComponentReflection.combineArgs.phpt +++ b/tests/UI/ComponentReflection.combineArgs.phpt @@ -57,6 +57,11 @@ class MyPresenter public function objects(stdClass $req, ?stdClass $nullable, ?stdClass $opt = null) { } + + + public function hintsUnion(int|array $intArray, string|array $strArray) + { + } } @@ -316,3 +321,35 @@ test('', function () { 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.' ); }); + + +test('', function () { + $method = new ReflectionMethod('MyPresenter', 'hintsUnion'); + + Assert::same([1, 'abc'], Reflection::combineArgs($method, ['intArray' => '1', 'strArray' => 'abc'])); + Assert::same([[1], [2]], Reflection::combineArgs($method, ['intArray' => [1], 'strArray' => [2]])); + + Assert::exception( + fn() => Reflection::combineArgs($method, []), + Nette\InvalidArgumentException::class, + 'Missing parameter $intArray required by MyPresenter::hintsUnion()' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['intArray' => '']), + Nette\InvalidArgumentException::class, + 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given.' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['intArray' => null]), + Nette\InvalidArgumentException::class, + 'Missing parameter $intArray required by MyPresenter::hintsUnion()' + ); + + Assert::exception( + fn() => Reflection::combineArgs($method, ['intArray' => new stdClass]), + Nette\InvalidArgumentException::class, + 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given.' + ); +}); From c4d5de2a6bb19b9220c5615707321b590d72ec3d Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 4 May 2022 12:57:58 +0200 Subject: [PATCH 10/42] removed deprecated stuff --- src/Application/PresenterFactory.php | 19 ---------- src/Application/Routers/Route.php | 22 +---------- src/Application/Routers/RouteList.php | 18 +-------- src/Application/Routers/SimpleRouter.php | 37 +------------------ src/Application/UI/Component.php | 14 ++----- src/Application/UI/Form.php | 14 ++----- src/Application/UI/Presenter.php | 21 ----------- src/Bridges/ApplicationDI/LatteExtension.php | 7 +--- .../ApplicationDI/RoutingExtension.php | 11 +----- tests/Bridges.DI/RoutingExtension.basic.phpt | 29 --------------- tests/Routers/Route.oneWay.phpt | 26 ------------- 11 files changed, 15 insertions(+), 203 deletions(-) delete mode 100644 tests/Routers/Route.oneWay.phpt diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index 48548747e..a82e6ba7e 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -123,23 +123,4 @@ public function formatPresenterClass(string $presenter): string return $mapping[0]; } - - - /** - * Formats presenter name from class name. - * @internal - */ - public function unformatPresenterClass(string $class): ?string - { - trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED); - foreach ($this->mapping as $module => $mapping) { - $mapping = str_replace(['\\', '*'], ['\\\\', '(\w+)'], $mapping); - if (preg_match("#^\\\\?$mapping[0]((?:$mapping[1])*)$mapping[2]$#Di", $class, $matches)) { - return ($module === '*' ? '' : $module . ':') - . preg_replace("#$mapping[1]#iA", '$1:', $matches[1]) . $matches[3]; - } - } - - return null; - } } diff --git a/src/Application/Routers/Route.php b/src/Application/Routers/Route.php index 9e4808b56..971689c70 100644 --- a/src/Application/Routers/Route.php +++ b/src/Application/Routers/Route.php @@ -40,15 +40,12 @@ class Route extends Nette\Routing\Route implements Nette\Routing\Router ], ]; - /** @var int */ - private $flags; - /** * @param string $mask e.g. '//' * @param array|string|\Closure $metadata default values or metadata or callback for NetteModule\MicroPresenter */ - public function __construct(string $mask, $metadata = [], int $flags = 0) + public function __construct(string $mask, array|string|\Closure $metadata = []) { if (is_string($metadata)) { [$presenter, $action] = Nette\Application\Helpers::splitName($metadata); @@ -67,12 +64,7 @@ public function __construct(string $mask, $metadata = [], int $flags = 0) ]; } - if ($flags) { - trigger_error(__METHOD__ . '() parameter $flags is deprecated, use RouteList::addRoute(..., ..., $flags) instead.', E_USER_DEPRECATED); - } - $this->defaultMeta += self::UIMeta; - $this->flags = $flags; parent::__construct($mask, $metadata); } @@ -108,10 +100,6 @@ public function match(Nette\Http\IRequest $httpRequest): ?array */ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string { - if ($this->flags & self::ONE_WAY) { - return null; - } - $metadata = $this->getMetadata(); if (isset($metadata[self::ModuleKey])) { // try split into module and [submodule:]presenter parts $presenter = $params[self::PresenterKey]; @@ -147,14 +135,6 @@ public function getConstantParameters(): array } - /** @deprecated */ - public function getFlags(): int - { - trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED); - return $this->flags; - } - - /********************* Inflectors ****************d*g**/ diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index 062cfe41d..75d568ec1 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -16,7 +16,7 @@ /** * The router broker. */ -class RouteList extends Nette\Routing\RouteList implements Nette\Routing\Router, \ArrayAccess, \Countable, \IteratorAggregate +class RouteList extends Nette\Routing\RouteList implements Nette\Routing\Router, \ArrayAccess { private const PresenterKey = 'presenter'; @@ -98,14 +98,6 @@ public function getModule(): ?string } - /** @deprecated */ - public function count(): int - { - trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED); - return count($this->getRouters()); - } - - /** * @param mixed $index * @param Nette\Routing\Router $router @@ -157,14 +149,6 @@ public function offsetUnset($index): void $this->modify($index, null); } - - - /** @deprecated */ - public function getIterator(): \ArrayIterator - { - trigger_error(__METHOD__ . '() is deprecated, use getRouters().', E_USER_DEPRECATED); - return new \ArrayIterator($this->getRouters()); - } } diff --git a/src/Application/Routers/SimpleRouter.php b/src/Application/Routers/SimpleRouter.php index deb6e0fde..90e99487c 100644 --- a/src/Application/Routers/SimpleRouter.php +++ b/src/Application/Routers/SimpleRouter.php @@ -18,15 +18,10 @@ */ final class SimpleRouter extends Nette\Routing\SimpleRouter implements Nette\Routing\Router { - private const - PresenterKey = 'presenter', - ModuleKey = 'module'; + private const PresenterKey = 'presenter'; - /** @var int */ - private $flags; - - public function __construct($defaults = [], int $flags = 0) + public function __construct(array $defaults = []) { if (is_string($defaults)) { [$presenter, $action] = Nette\Application\Helpers::splitName($defaults); @@ -40,36 +35,8 @@ public function __construct($defaults = [], int $flags = 0) ]; } - if (isset($defaults[self::ModuleKey])) { - throw new Nette\DeprecatedException(__METHOD__ . '() parameter module is deprecated, use RouteList::withModule() instead.'); - } elseif ($flags) { - trigger_error(__METHOD__ . '() parameter $flags is deprecated, use RouteList::add(..., $flags) instead.', E_USER_DEPRECATED); - } - - $this->flags = $flags; parent::__construct($defaults); } - - - /** - * Constructs absolute URL from array. - */ - public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string - { - if ($this->flags & self::ONE_WAY) { - return null; - } - - return parent::constructUrl($params, $refUrl); - } - - - /** @deprecated */ - public function getFlags(): int - { - trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED); - return $this->flags; - } } diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 8b35b9dd2..ab06cd978 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -37,14 +37,9 @@ abstract class Component extends Nette\ComponentModel\Container implements Signa * Returns the presenter where this component belongs to. * @return Presenter */ - public function getPresenter(): ?Presenter + public function getPresenter(): Presenter { - if (func_num_args()) { - trigger_error(__METHOD__ . '() parameter $throw is deprecated, use getPresenterIfExists()', E_USER_DEPRECATED); - $throw = func_get_arg(0); - } - - return $this->lookup(Presenter::class, $throw ?? true); + return $this->lookup(Presenter::class, throw: true); } @@ -53,14 +48,13 @@ public function getPresenter(): ?Presenter */ public function getPresenterIfExists(): ?Presenter { - return $this->lookup(Presenter::class, false); + return $this->lookup(Presenter::class, throw: false); } - /** @deprecated */ public function hasPresenter(): bool { - return (bool) $this->lookup(Presenter::class, false); + return (bool) $this->lookup(Presenter::class, throw: false); } diff --git a/src/Application/UI/Form.php b/src/Application/UI/Form.php index 62582e9fc..ffa9fa2c8 100644 --- a/src/Application/UI/Form.php +++ b/src/Application/UI/Form.php @@ -66,14 +66,9 @@ protected function validateParent(Nette\ComponentModel\IContainer $parent): void /** * Returns the presenter where this component belongs to. */ - final public function getPresenter(): ?Presenter + final public function getPresenter(): Presenter { - if (func_num_args()) { - trigger_error(__METHOD__ . '() parameter $throw is deprecated, use getPresenterIfExists()', E_USER_DEPRECATED); - $throw = func_get_arg(0); - } - - return $this->lookup(Presenter::class, $throw ?? true); + return $this->lookup(Presenter::class, throw: true); } @@ -82,14 +77,13 @@ final public function getPresenter(): ?Presenter */ final public function getPresenterIfExists(): ?Presenter { - return $this->lookup(Presenter::class, false); + return $this->lookup(Presenter::class, throw: false); } - /** @deprecated */ public function hasPresenter(): bool { - return (bool) $this->lookup(Presenter::class, false); + return (bool) $this->lookup(Presenter::class, throw: false); } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index a8007bf7f..d3ea38545 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -25,7 +25,6 @@ * @property string $view * @property string|bool $layout * @property-read \stdClass $payload - * @property-read Nette\DI\Container $context * @property-read Nette\Http\Session $session * @property-read Nette\Security\User $user */ @@ -122,9 +121,6 @@ abstract class Presenter extends Control implements Application\IPresenter /** @var array|null */ private $lastCreatedRequestFlag; - /** @var Nette\DI\Container */ - private $context; - /** @var Nette\Http\IRequest */ private $httpRequest; @@ -177,7 +173,6 @@ final public function getPresenterIfExists(): self } - /** @deprecated */ final public function hasPresenter(): bool { return true; @@ -1431,7 +1426,6 @@ final public function injectPrimary( throw new Nette\InvalidStateException('Method ' . __METHOD__ . ' is intended for initialization and should not be called more than once.'); } - $this->context = $context; $this->presenterFactory = $presenterFactory; $this->router = $router; $this->httpRequest = $httpRequest; @@ -1442,21 +1436,6 @@ final public function injectPrimary( } - /** - * Gets the context. - * @deprecated - */ - public function getContext(): Nette\DI\Container - { - if (!$this->context) { - throw new Nette\InvalidStateException('Context has not been set.'); - } - - trigger_error(__METHOD__ . '() is deprecated, use dependency injection.', E_USER_DEPRECATED); - return $this->context; - } - - final public function getHttpRequest(): Http\IRequest { return $this->httpRequest; diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 378dd2786..3dbc846dc 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -39,7 +39,6 @@ public function getConfigSchema(): Nette\Schema\Schema { return Expect::structure([ 'debugger' => Expect::anyOf(true, false, 'all'), - 'xhtml' => Expect::bool(false)->deprecated(), 'macros' => Expect::arrayOf('string'), 'extensions' => Expect::arrayOf('string|Nette\DI\Definitions\Statement'), 'templateClass' => Expect::string(), @@ -59,7 +58,7 @@ public function loadConfiguration() $config = $this->config; $builder = $this->getContainerBuilder(); - $latteFactory = $builder->addFactoryDefinition($this->prefix('latteFactory')) + $builder->addFactoryDefinition($this->prefix('latteFactory')) ->setImplement(ApplicationLatte\LatteFactory::class) ->getResultDefinition() ->setFactory(Latte\Engine::class) @@ -68,10 +67,6 @@ public function loadConfiguration() ->addSetup('setStrictTypes', [$config->strictTypes]); if (version_compare(Latte\Engine::VERSION, '3', '<')) { - $latteFactory->addSetup('setContentType', [$config->xhtml ? Latte\Compiler::CONTENT_XHTML : Latte\Compiler::CONTENT_HTML]); - if ($config->xhtml) { - $latteFactory->addSetup('Nette\Utils\Html::$xhtml = ?', [true]); - } foreach ($config->macros as $macro) { $this->addMacro($macro); } diff --git a/src/Bridges/ApplicationDI/RoutingExtension.php b/src/Bridges/ApplicationDI/RoutingExtension.php index c506d59ac..374ac927c 100644 --- a/src/Bridges/ApplicationDI/RoutingExtension.php +++ b/src/Bridges/ApplicationDI/RoutingExtension.php @@ -35,7 +35,6 @@ public function getConfigSchema(): Nette\Schema\Schema return Expect::structure([ 'debugger' => Expect::bool(), 'routes' => Expect::arrayOf('string'), - 'routeClass' => Expect::string()->deprecated(), 'cache' => Expect::bool(false), ]); } @@ -52,14 +51,8 @@ public function loadConfiguration() $router = $builder->addDefinition($this->prefix('router')) ->setFactory(Nette\Application\Routers\RouteList::class); - if ($this->config->routeClass) { - foreach ($this->config->routes as $mask => $action) { - $router->addSetup('$service[] = new ' . $this->config->routeClass . '(?, ?)', [$mask, $action]); - } - } else { - foreach ($this->config->routes as $mask => $action) { - $router->addSetup('$service->addRoute(?, ?)', [$mask, $action]); - } + foreach ($this->config->routes as $mask => $action) { + $router->addSetup('$service->addRoute(?, ?)', [$mask, $action]); } if ($this->name === 'routing') { diff --git a/tests/Bridges.DI/RoutingExtension.basic.phpt b/tests/Bridges.DI/RoutingExtension.basic.phpt index f8f35d1f4..a8e13d1a6 100644 --- a/tests/Bridges.DI/RoutingExtension.basic.phpt +++ b/tests/Bridges.DI/RoutingExtension.basic.phpt @@ -14,11 +14,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -class Route extends Nette\Application\Routers\Route -{ -} - - test('', function () { $loader = new DI\Config\Loader; $config = $loader->load(Tester\FileMock::create(' @@ -36,33 +31,9 @@ test('', function () { $container = new Container1; $router = $container->getService('router'); Assert::type(Nette\Application\Routers\RouteList::class, $router); - @Assert::count(2, $router); // @ is deprecated Assert::same('index.php', $router[0]->getMask()); Assert::same('item/', $router[1]->getMask()); Assert::type(Nette\Application\Routers\RouteList::class, $router); Assert::type(Nette\Application\Routers\Route::class, $router[0]); }); - - -test('', function () { - $loader = new DI\Config\Loader; - $config = $loader->load(Tester\FileMock::create(' - routing: - routeClass: - Route - routes: - item/: Homepage:detail - ', 'neon')); - - $compiler = new DI\Compiler; - $compiler->addExtension('routing', new RoutingExtension(false)); - $code = @$compiler->addConfig($config)->setClassName('Container2')->compile(); // @ routingClass is deprecated - eval($code); - - $container = new Container2; - $router = $container->getService('router'); - - Assert::type(Nette\Application\Routers\RouteList::class, $router); - Assert::type(Route::class, $router[0]); -}); diff --git a/tests/Routers/Route.oneWay.phpt b/tests/Routers/Route.oneWay.phpt deleted file mode 100644 index c9578d790..000000000 --- a/tests/Routers/Route.oneWay.phpt +++ /dev/null @@ -1,26 +0,0 @@ -/', [ // @ is deprecated - 'presenter' => 'Default', - 'action' => 'default', -], Route::ONE_WAY); - -testRouteIn($route, '/presenter/action/', [ - 'presenter' => 'Presenter', - 'action' => 'action', - 'test' => 'testvalue', -], null); From 41c5a84a3a0e10d52e8d225bb9924c447096ef96 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 20 Dec 2022 00:39:00 +0100 Subject: [PATCH 11/42] removed compatibility for old class names --- src/Application/UI/Component.php | 3 --- src/Application/UI/ComponentReflection.php | 3 --- src/compatibility.php | 28 ---------------------- 3 files changed, 34 deletions(-) delete mode 100644 src/compatibility.php diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index ab06cd978..2533ff040 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -341,6 +341,3 @@ public function error(string $message = '', int $httpCode = Nette\Http\IResponse throw new Nette\Application\BadRequestException($message, $httpCode); } } - - -class_exists(PresenterComponent::class); diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index c8946e52d..60d2a720b 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -364,6 +364,3 @@ public static function getClassesAndTraits(string $class): array return $res; } } - - -class_exists(PresenterComponentReflection::class); diff --git a/src/compatibility.php b/src/compatibility.php deleted file mode 100644 index cf55aa4bc..000000000 --- a/src/compatibility.php +++ /dev/null @@ -1,28 +0,0 @@ - Date: Mon, 2 Oct 2023 18:15:23 +0200 Subject: [PATCH 12/42] added property typehints --- src/Application/Application.php | 45 +++--- src/Application/ErrorPresenter.php | 3 +- src/Application/LinkGenerator.php | 9 +- src/Application/MicroPresenter.php | 12 +- src/Application/PresenterFactory.php | 5 +- src/Application/Request.php | 18 +-- src/Application/Responses/FileResponse.php | 15 +- src/Application/Responses/ForwardResponse.php | 3 +- src/Application/Responses/JsonResponse.php | 6 +- .../Responses/RedirectResponse.php | 6 +- src/Application/Responses/TextResponse.php | 3 +- src/Application/Routers/CliRouter.php | 3 +- src/Application/Routers/RouteList.php | 3 +- src/Application/UI/BadSignalException.php | 1 - src/Application/UI/Component.php | 5 +- src/Application/UI/ComponentReflection.php | 12 +- src/Application/UI/Control.php | 16 +-- src/Application/UI/Form.php | 2 +- src/Application/UI/Link.php | 9 +- src/Application/UI/Presenter.php | 129 ++++++------------ src/Application/exceptions.php | 2 - .../ApplicationDI/ApplicationExtension.php | 17 +-- src/Bridges/ApplicationDI/LatteExtension.php | 6 +- .../PresenterFactoryCallback.php | 9 +- .../ApplicationDI/RoutingExtension.php | 3 +- .../ApplicationLatte/DefaultTemplate.php | 21 +-- .../ApplicationLatte/SnippetBridge.php | 8 +- src/Bridges/ApplicationLatte/Template.php | 6 +- .../ApplicationLatte/TemplateFactory.php | 22 +-- src/Bridges/ApplicationLatte/UIMacros.php | 6 +- src/Bridges/ApplicationTracy/RoutingPanel.php | 21 +-- tests/Bridges.DI/LatteExtension.2.phpt | 3 +- tests/Bridges.Latte3/ControlMock.php | 2 +- .../TemplateFactory.customTemplate.phpt | 2 +- tests/Routers/Route.filter.url.object.phpt | 3 +- tests/bootstrap.php | 2 +- 36 files changed, 145 insertions(+), 293 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index 435dc1d8d..ff78fe910 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -21,50 +21,37 @@ class Application { use Nette\SmartObject; - /** @var int */ - public $maxLoop = 20; + public int $maxLoop = 20; - /** @var bool enable fault barrier? */ - public $catchExceptions; - - /** @var string|null */ - public $errorPresenter; + /** enable fault barrier? */ + public bool $catchExceptions = false; + public ?string $errorPresenter = null; /** @var array Occurs before the application loads presenter */ - public $onStartup = []; + public array $onStartup = []; /** @var array Occurs before the application shuts down */ - public $onShutdown = []; + public array $onShutdown = []; /** @var array Occurs when a new request is received */ - public $onRequest = []; + public array $onRequest = []; /** @var array Occurs when a presenter is created */ - public $onPresenter = []; + public array $onPresenter = []; /** @var array Occurs when a new response is ready for dispatch */ - public $onResponse = []; + public array $onResponse = []; /** @var array Occurs when an unhandled exception occurs in the application */ - public $onError = []; + public array $onError = []; /** @var Request[] */ - private $requests = []; - - /** @var IPresenter|null */ - private $presenter; - - /** @var Nette\Http\IRequest */ - private $httpRequest; - - /** @var Nette\Http\IResponse */ - private $httpResponse; - - /** @var IPresenterFactory */ - private $presenterFactory; - - /** @var Router */ - private $router; + private array $requests = []; + private ?IPresenter $presenter = null; + private Nette\Http\IRequest $httpRequest; + private Nette\Http\IResponse $httpResponse; + private IPresenterFactory $presenterFactory; + private Router $router; public function __construct( diff --git a/src/Application/ErrorPresenter.php b/src/Application/ErrorPresenter.php index 3d9ba4031..a71d594bb 100644 --- a/src/Application/ErrorPresenter.php +++ b/src/Application/ErrorPresenter.php @@ -22,8 +22,7 @@ final class ErrorPresenter implements Application\IPresenter { use Nette\SmartObject; - /** @var ILogger|null */ - private $logger; + private ?ILogger $logger; public function __construct(?ILogger $logger = null) diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index 38bb75df2..e8641fcb4 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -21,14 +21,11 @@ final class LinkGenerator { use Nette\SmartObject; - /** @var Router */ - private $router; + private Router $router; - /** @var UrlScript */ - private $refUrl; + private UrlScript $refUrl; - /** @var IPresenterFactory|null */ - private $presenterFactory; + private ?IPresenterFactory $presenterFactory; public function __construct(Router $router, UrlScript $refUrl, ?IPresenterFactory $presenterFactory = null) diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 113c48b26..e33b7a56a 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -24,17 +24,13 @@ final class MicroPresenter implements Application\IPresenter { use Nette\SmartObject; - /** @var Nette\DI\Container|null */ - private $context; + private ?Nette\DI\Container $context; - /** @var Nette\Http\IRequest|null */ - private $httpRequest; + private ?Nette\Http\IRequest $httpRequest; - /** @var Router|null */ - private $router; + private ?Router $router; - /** @var Application\Request|null */ - private $request; + private ?Application\Request $request; public function __construct( diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index a82e6ba7e..c2b0834f5 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -20,13 +20,12 @@ class PresenterFactory implements IPresenterFactory use Nette\SmartObject; /** @var array[] of module => splited mask */ - private $mapping = [ + private array $mapping = [ '*' => ['', '*Module\\', '*Presenter'], 'Nette' => ['NetteModule\\', '*\\', '*Presenter'], ]; - /** @var array */ - private $cache = []; + private array $cache = []; /** @var callable */ private $factory; diff --git a/src/Application/Request.php b/src/Application/Request.php index 22a00dba4..73c4f4f65 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -37,23 +37,17 @@ final class Request /** flag */ public const VARYING = 'varying'; - /** @var string|null */ - private $method; + private ?string $method; - /** @var array */ - private $flags = []; + private array $flags = []; - /** @var string */ - private $name; + private string $name; - /** @var array */ - private $params; + private array $params; - /** @var array */ - private $post; + private array $post; - /** @var array */ - private $files; + private array $files; /** diff --git a/src/Application/Responses/FileResponse.php b/src/Application/Responses/FileResponse.php index 8953c3aa0..2667f7858 100644 --- a/src/Application/Responses/FileResponse.php +++ b/src/Application/Responses/FileResponse.php @@ -19,20 +19,15 @@ final class FileResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var bool */ - public $resuming = true; + public bool $resuming = true; - /** @var string */ - private $file; + private string $file; - /** @var string */ - private $contentType; + private string $contentType; - /** @var string */ - private $name; + private string $name; - /** @var bool */ - private $forceDownload; + private bool $forceDownload; public function __construct( diff --git a/src/Application/Responses/ForwardResponse.php b/src/Application/Responses/ForwardResponse.php index 43cd9dc91..f2ee36e50 100644 --- a/src/Application/Responses/ForwardResponse.php +++ b/src/Application/Responses/ForwardResponse.php @@ -19,8 +19,7 @@ final class ForwardResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var Nette\Application\Request */ - private $request; + private Nette\Application\Request $request; public function __construct(Nette\Application\Request $request) diff --git a/src/Application/Responses/JsonResponse.php b/src/Application/Responses/JsonResponse.php index 39e4b1cd7..b50fec9bc 100644 --- a/src/Application/Responses/JsonResponse.php +++ b/src/Application/Responses/JsonResponse.php @@ -19,11 +19,9 @@ final class JsonResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var mixed */ - private $payload; + private mixed $payload; - /** @var string */ - private $contentType; + private string $contentType; public function __construct($payload, ?string $contentType = null) diff --git a/src/Application/Responses/RedirectResponse.php b/src/Application/Responses/RedirectResponse.php index 1ffb11a29..fda1a378a 100644 --- a/src/Application/Responses/RedirectResponse.php +++ b/src/Application/Responses/RedirectResponse.php @@ -20,11 +20,9 @@ final class RedirectResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var string */ - private $url; + private string $url; - /** @var int */ - private $httpCode; + private int $httpCode; public function __construct(string $url, int $httpCode = Http\IResponse::S302_FOUND) diff --git a/src/Application/Responses/TextResponse.php b/src/Application/Responses/TextResponse.php index 20dc07bf6..5806c1983 100644 --- a/src/Application/Responses/TextResponse.php +++ b/src/Application/Responses/TextResponse.php @@ -19,8 +19,7 @@ final class TextResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var mixed */ - private $source; + private mixed $source; /** diff --git a/src/Application/Routers/CliRouter.php b/src/Application/Routers/CliRouter.php index 35a7b1dc6..225b6624c 100644 --- a/src/Application/Routers/CliRouter.php +++ b/src/Application/Routers/CliRouter.php @@ -21,8 +21,7 @@ final class CliRouter implements Nette\Routing\Router private const PresenterKey = 'action'; - /** @var array */ - private $defaults; + private array $defaults; public function __construct(array $defaults = []) diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index 75d568ec1..c2b57a078 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -20,8 +20,7 @@ class RouteList extends Nette\Routing\RouteList implements Nette\Routing\Router, { private const PresenterKey = 'presenter'; - /** @var string|null */ - private $module; + private ?string $module; public function __construct(?string $module = null) diff --git a/src/Application/UI/BadSignalException.php b/src/Application/UI/BadSignalException.php index 3c9ade6c2..4946473f2 100644 --- a/src/Application/UI/BadSignalException.php +++ b/src/Application/UI/BadSignalException.php @@ -17,6 +17,5 @@ */ class BadSignalException extends Nette\Application\BadRequestException { - /** @var int */ protected $code = 403; } diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 2533ff040..9bfef9169 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -27,10 +27,9 @@ abstract class Component extends Nette\ComponentModel\Container implements Signa use Nette\ComponentModel\ArrayAccess; /** @var array Occurs when component is attached to presenter */ - public $onAnchor = []; + public array $onAnchor = []; - /** @var array */ - protected $params = []; + protected array $params = []; /** diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 60d2a720b..7c505becb 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -22,14 +22,14 @@ final class ComponentReflection extends \ReflectionClass { use Nette\SmartObject; - /** @var array getPersistentParams cache */ - private static $ppCache = []; + /** getPersistentParams cache */ + private static array $ppCache = []; - /** @var array getPersistentComponents cache */ - private static $pcCache = []; + /** getPersistentComponents cache */ + private static array $pcCache = []; - /** @var array isMethodCallable cache */ - private static $mcCache = []; + /** isMethodCallable cache */ + private static array $mcCache = []; /** diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index d8b6be269..a9130f0f8 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -19,17 +19,13 @@ */ abstract class Control extends Component implements Renderable { - /** @var bool */ - public $snippetMode; + public bool $snippetMode = false; - /** @var TemplateFactory */ - private $templateFactory; + private TemplateFactory $templateFactory; - /** @var Template */ - private $template; + private Template $template; - /** @var array */ - private $invalidSnippets = []; + private array $invalidSnippets = []; /********************* template factory ****************d*g**/ @@ -44,7 +40,7 @@ final public function setTemplateFactory(TemplateFactory $templateFactory) final public function getTemplate(): Template { - if ($this->template === null) { + if (!isset($this->template)) { $this->template = $this->createTemplate(); } @@ -60,7 +56,7 @@ protected function createTemplate(/*string $class = null*/): Template $class = func_num_args() // back compatibility ? func_get_arg(0) : $this->formatTemplateClass(); - $templateFactory = $this->templateFactory ?: $this->getPresenter()->getTemplateFactory(); + $templateFactory = $this->templateFactory ?? $this->getPresenter()->getTemplateFactory(); return $templateFactory->createTemplate($this, $class); } diff --git a/src/Application/UI/Form.php b/src/Application/UI/Form.php index ffa9fa2c8..0a4455b15 100644 --- a/src/Application/UI/Form.php +++ b/src/Application/UI/Form.php @@ -18,7 +18,7 @@ class Form extends Nette\Forms\Form implements SignalReceiver { /** @var array Occurs when form is attached to presenter */ - public $onAnchor = []; + public array $onAnchor = []; /** @var bool */ protected $crossOrigin = false; diff --git a/src/Application/UI/Link.php b/src/Application/UI/Link.php index 048e27214..4e922fa9e 100644 --- a/src/Application/UI/Link.php +++ b/src/Application/UI/Link.php @@ -20,14 +20,11 @@ final class Link { use Nette\SmartObject; - /** @var Component */ - private $component; + private Component $component; - /** @var string */ - private $destination; + private string $destination; - /** @var array */ - private $params; + private array $params; /** diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index d3ea38545..8b6a8fbb7 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -55,95 +55,46 @@ abstract class Presenter extends Control implements Application\IPresenter public const FLASH_KEY = self::FlashKey; public const DEFAULT_ACTION = self::DefaultAction; - /** @var int */ - public $invalidLinkMode; + public int $invalidLinkMode = 0; /** @var array Occurs when the presenter is starting */ - public $onStartup = []; + public array $onStartup = []; /** @var array Occurs when the presenter is rendering after beforeRender */ - public $onRender = []; + public array $onRender = []; /** @var array Occurs when the presenter is shutting down */ - public $onShutdown = []; - - /** @var bool automatically call canonicalize() */ - public $autoCanonicalize = true; - - /** @var bool use absolute Urls or paths? */ - public $absoluteUrls = false; - - /** @var string[] */ - public $allowedMethods = ['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'PATCH']; - - /** @var Nette\Application\Request|null */ - private $request; - - /** @var Nette\Application\Response */ - private $response; - - /** @var array */ - private $globalParams = []; - - /** @var array */ - private $globalState; - - /** @var array|null */ - private $globalStateSinces; - - /** @var string */ - private $action; - - /** @var string */ - private $view; - - /** @var string|bool */ - private $layout; - - /** @var \stdClass */ - private $payload; - - /** @var string */ - private $signalReceiver; - - /** @var string|null */ - private $signal; - - /** @var bool */ - private $ajaxMode; - - /** @var bool */ - private $startupCheck; - - /** @var Nette\Application\Request|null */ - private $lastCreatedRequest; - - /** @var array|null */ - private $lastCreatedRequestFlag; - - /** @var Nette\Http\IRequest */ - private $httpRequest; - - /** @var Nette\Http\IResponse */ - private $httpResponse; - - /** @var Nette\Http\Session */ - private $session; - - /** @var Nette\Application\IPresenterFactory */ - private $presenterFactory; - - /** @var Nette\Routing\Router */ - private $router; - - /** @var Nette\Security\User */ - private $user; - - /** @var TemplateFactory */ - private $templateFactory; - - /** @var Nette\Http\UrlScript */ - private $refUrlCache; + public array $onShutdown = []; + + /** automatically call canonicalize() */ + public bool $autoCanonicalize = true; + + /** use absolute Urls or paths? */ + public bool $absoluteUrls = false; + public array $allowedMethods = ['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'PATCH']; + private ?Nette\Application\Request $request = null; + private ?Nette\Application\Response $response = null; + private array $globalParams = []; + private array $globalState; + private ?array $globalStateSinces; + private string $action = ''; + private string $view = ''; + private string|bool $layout = ''; + private \stdClass $payload; + private string $signalReceiver; + private ?string $signal = null; + private bool $ajaxMode; + private bool $startupCheck = false; + private ?Nette\Application\Request $lastCreatedRequest; + private ?array $lastCreatedRequestFlag; + private Nette\Http\IRequest $httpRequest; + private Nette\Http\IResponse $httpResponse; + private ?Nette\Http\Session $session = null; + private ?Nette\Application\IPresenterFactory $presenterFactory = null; + private ?Nette\Routing\Router $router = null; + private ?Nette\Security\User $user = null; + private ?TemplateFactory $templateFactory = null; + private Nette\Http\UrlScript $refUrlCache; public function __construct() @@ -201,7 +152,7 @@ public function isModuleCurrent(string $module): bool public function run(Application\Request $request): Application\Response { $this->request = $request; - $this->payload = $this->payload ?: new \stdClass; + $this->payload ??= new \stdClass; $this->setParent($this->getParent(), $request->getPresenterName()); if (!$this->httpResponse->isSent()) { @@ -351,7 +302,7 @@ protected function checkHttpMethod(): void */ public function processSignal(): void { - if ($this->signal === null) { + if (!isset($this->signal)) { return; } @@ -621,7 +572,7 @@ final public function getPayload(): \stdClass */ public function isAjax(): bool { - if ($this->ajaxMode === null) { + if (!isset($this->ajaxMode)) { $this->ajaxMode = $this->httpRequest->isAjax(); } @@ -1024,7 +975,7 @@ public static function parseDestination(string $destination): array */ protected function requestToUrl(Application\Request $request, ?bool $relative = null): string { - if ($this->refUrlCache === null) { + if (!isset($this->refUrlCache)) { $url = $this->httpRequest->getUrl(); $this->refUrlCache = new Http\UrlScript($url->withoutUserInfo()->getHostUrl() . $url->getScriptPath()); } @@ -1209,7 +1160,7 @@ protected function getGlobalState(?string $forClass = null): array { $sinces = &$this->globalStateSinces; - if ($this->globalState === null) { + if (!isset($this->globalState)) { $state = []; foreach ($this->globalParams as $id => $params) { $prefix = $id . self::NAME_SEPARATOR; @@ -1422,7 +1373,7 @@ final public function injectPrimary( ?Nette\Security\User $user = null, ?TemplateFactory $templateFactory = null, ) { - if ($this->presenterFactory !== null) { + if (isset($this->presenterFactory)) { throw new Nette\InvalidStateException('Method ' . __METHOD__ . ' is intended for initialization and should not be called more than once.'); } diff --git a/src/Application/exceptions.php b/src/Application/exceptions.php index 35127eb18..3ada5038b 100644 --- a/src/Application/exceptions.php +++ b/src/Application/exceptions.php @@ -42,7 +42,6 @@ class InvalidPresenterException extends \Exception */ class BadRequestException extends \Exception { - /** @var int */ protected $code = Http\IResponse::S404_NOT_FOUND; @@ -64,6 +63,5 @@ public function getHttpCode(): int */ class ForbiddenRequestException extends BadRequestException { - /** @var int */ protected $code = Http\IResponse::S403_FORBIDDEN; } diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index ef1f7f811..a22a0bdb8 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -22,20 +22,15 @@ */ final class ApplicationExtension extends Nette\DI\CompilerExtension { - /** @var bool */ - private $debugMode; + private bool $debugMode; - /** @var array */ - private $scanDirs; + private array $scanDirs; - /** @var Nette\Loaders\RobotLoader|null */ - private $robotLoader; + private ?Nette\Loaders\RobotLoader $robotLoader; - /** @var int */ - private $invalidLinkMode; + private int $invalidLinkMode; - /** @var string|null */ - private $tempDir; + private ?string $tempDir; public function __construct( @@ -56,7 +51,7 @@ public function getConfigSchema(): Nette\Schema\Schema return Expect::structure([ 'debugger' => Expect::bool(), 'errorPresenter' => Expect::string('Nette:Error')->dynamic(), - 'catchExceptions' => Expect::bool()->dynamic(), + 'catchExceptions' => Expect::bool(false)->dynamic(), 'mapping' => Expect::arrayOf('string|array'), 'scanDirs' => Expect::anyOf( Expect::arrayOf('string')->default($this->scanDirs)->mergeDefaults(), diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 3dbc846dc..0d40e6a26 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -21,11 +21,9 @@ */ final class LatteExtension extends Nette\DI\CompilerExtension { - /** @var bool */ - private $debugMode; + private bool $debugMode; - /** @var string */ - private $tempDir; + private string $tempDir; public function __construct(string $tempDir, bool $debugMode = false) diff --git a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php index 3728dd9b4..d9d932ec7 100644 --- a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php +++ b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php @@ -18,14 +18,11 @@ */ final class PresenterFactoryCallback { - /** @var Nette\DI\Container */ - private $container; + private Nette\DI\Container $container; - /** @var int */ - private $invalidLinkMode; + private int $invalidLinkMode; - /** @var string|null */ - private $touchToRefresh; + private ?string $touchToRefresh; public function __construct(Nette\DI\Container $container, int $invalidLinkMode, ?string $touchToRefresh) diff --git a/src/Bridges/ApplicationDI/RoutingExtension.php b/src/Bridges/ApplicationDI/RoutingExtension.php index 374ac927c..62d5d3949 100644 --- a/src/Bridges/ApplicationDI/RoutingExtension.php +++ b/src/Bridges/ApplicationDI/RoutingExtension.php @@ -20,8 +20,7 @@ */ final class RoutingExtension extends Nette\DI\CompilerExtension { - /** @var bool */ - private $debugMode; + private bool $debugMode; public function __construct(bool $debugMode = false) diff --git a/src/Bridges/ApplicationLatte/DefaultTemplate.php b/src/Bridges/ApplicationLatte/DefaultTemplate.php index 21eb5792d..e80193dde 100644 --- a/src/Bridges/ApplicationLatte/DefaultTemplate.php +++ b/src/Bridges/ApplicationLatte/DefaultTemplate.php @@ -21,23 +21,14 @@ #[\AllowDynamicProperties] final class DefaultTemplate extends Template { - /** @var Nette\Application\UI\Presenter */ - public $presenter; - - /** @var Nette\Application\UI\Control */ - public $control; - - /** @var Nette\Security\User */ - public $user; - - /** @var string */ - public $baseUrl; - - /** @var string */ - public $basePath; + public Nette\Application\IPresenter $presenter; + public Nette\Application\UI\Control $control; + public Nette\Security\User $user; + public string $baseUrl; + public string $basePath; /** @var \stdClass[] */ - public $flashes = []; + public array $flashes = []; /** diff --git a/src/Bridges/ApplicationLatte/SnippetBridge.php b/src/Bridges/ApplicationLatte/SnippetBridge.php index 9a586228e..66109abba 100644 --- a/src/Bridges/ApplicationLatte/SnippetBridge.php +++ b/src/Bridges/ApplicationLatte/SnippetBridge.php @@ -23,11 +23,9 @@ class SnippetBridge implements ISnippetBridge { use Nette\SmartObject; - /** @var Control */ - private $control; + private Control $control; - /** @var \stdClass|null */ - private $payload; + private \stdClass $payload; public function __construct(Control $control) @@ -70,7 +68,7 @@ public function getHtmlId($name): string public function addSnippet($name, $content): void { - if ($this->payload === null) { + if (!isset($this->payload)) { $this->payload = $this->control->getPresenter()->getPayload(); } diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index 593c0c626..41ff4921d 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -18,11 +18,9 @@ */ class Template implements Nette\Application\UI\Template { - /** @var Latte\Engine */ - private $latte; + private Latte\Engine $latte; - /** @var string */ - private $file; + private ?string $file = null; public function __construct(Latte\Engine $latte) diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 976d5a2d6..099afa405 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -22,22 +22,12 @@ class TemplateFactory implements UI\TemplateFactory use Nette\SmartObject; /** @var array Occurs when a new template is created */ - public $onCreate = []; - - /** @var LatteFactory */ - private $latteFactory; - - /** @var Nette\Http\IRequest|null */ - private $httpRequest; - - /** @var Nette\Security\User|null */ - private $user; - - /** @var Nette\Caching\Storage|null */ - private $cacheStorage; - - /** @var string */ - private $templateClass; + public array $onCreate = []; + private LatteFactory $latteFactory; + private ?Nette\Http\IRequest $httpRequest; + private ?Nette\Security\User $user; + private ?Nette\Caching\Storage $cacheStorage; + private string $templateClass; public function __construct( diff --git a/src/Bridges/ApplicationLatte/UIMacros.php b/src/Bridges/ApplicationLatte/UIMacros.php index 4f512694b..0ff1fb87b 100644 --- a/src/Bridges/ApplicationLatte/UIMacros.php +++ b/src/Bridges/ApplicationLatte/UIMacros.php @@ -26,11 +26,9 @@ */ final class UIMacros extends Latte\Macros\MacroSet { - /** @var bool|string */ - private $extends; + private bool|string $extends; - /** @var string|null */ - private $printTemplate; + private ?string $printTemplate = null; public static function install(Latte\Compiler $compiler): void diff --git a/src/Bridges/ApplicationTracy/RoutingPanel.php b/src/Bridges/ApplicationTracy/RoutingPanel.php index 9ad50f11c..c04a3f50c 100644 --- a/src/Bridges/ApplicationTracy/RoutingPanel.php +++ b/src/Bridges/ApplicationTracy/RoutingPanel.php @@ -22,23 +22,14 @@ final class RoutingPanel implements Tracy\IBarPanel { use Nette\SmartObject; - /** @var Routing\Router */ - private $router; - - /** @var Nette\Http\IRequest */ - private $httpRequest; - - /** @var Nette\Application\IPresenterFactory */ - private $presenterFactory; + private Routing\Router $router; + private Nette\Http\IRequest $httpRequest; + private Nette\Application\IPresenterFactory $presenterFactory; /** @var \stdClass[] */ - private $routers = []; - - /** @var array|null */ - private $matched; - - /** @var \ReflectionClass|\ReflectionMethod */ - private $source; + private array $routers = []; + private ?array $matched = null; + private \ReflectionClass|\ReflectionMethod|null $source = null; public function __construct( diff --git a/tests/Bridges.DI/LatteExtension.2.phpt b/tests/Bridges.DI/LatteExtension.2.phpt index ec591fbe2..8144950b6 100644 --- a/tests/Bridges.DI/LatteExtension.2.phpt +++ b/tests/Bridges.DI/LatteExtension.2.phpt @@ -51,8 +51,7 @@ class FooMacros extends Latte\Macros\MacroSet class NonStaticMacrosFactory { - /** @var string */ - private $parameter; + private string $parameter; public function __construct($parameter) diff --git a/tests/Bridges.Latte3/ControlMock.php b/tests/Bridges.Latte3/ControlMock.php index f5e6606a6..90eea12e6 100644 --- a/tests/Bridges.Latte3/ControlMock.php +++ b/tests/Bridges.Latte3/ControlMock.php @@ -5,7 +5,7 @@ class ControlMock extends Nette\Application\UI\Control { - public $snippetMode = true; + public bool $snippetMode = true; public $payload = []; diff --git a/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt b/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt index 71d0e08ae..af5630b7a 100644 --- a/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt +++ b/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt @@ -23,7 +23,7 @@ Tester\Environment::bypassFinals(); class TemplateMock extends Template { - private $file = 'ko'; + private string $file = 'ko'; public function render(?string $file = null, array $params = []): void diff --git a/tests/Routers/Route.filter.url.object.phpt b/tests/Routers/Route.filter.url.object.phpt index f9d23091b..39a30a13a 100644 --- a/tests/Routers/Route.filter.url.object.phpt +++ b/tests/Routers/Route.filter.url.object.phpt @@ -54,8 +54,7 @@ Assert::null(testRouteOut($route, [ class RouterObject { - /** @var int */ - private $id; + private int $id; public function __construct($id) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 91c483705..83f9370e5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -52,7 +52,7 @@ function test(string $title, Closure $function): void class Notes { - public static $notes = []; + public static array $notes = []; public static function add($message): void From 535e6ec8daf7758da4b85c602a29c4e4a03c588f Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 19:51:16 +0100 Subject: [PATCH 13/42] added PHP 8 typehints --- src/Application/LinkGenerator.php | 2 +- src/Application/PresenterFactory.php | 3 +- src/Application/Request.php | 24 ++++------ src/Application/Responses/JsonResponse.php | 5 +- src/Application/Responses/TextResponse.php | 10 +--- src/Application/Routers/RouteList.php | 16 ++----- src/Application/Routers/SimpleRouter.php | 2 +- src/Application/UI/Component.php | 5 +- src/Application/UI/ComponentReflection.php | 4 +- src/Application/UI/Control.php | 3 +- src/Application/UI/Link.php | 6 +-- src/Application/UI/MethodReflection.php | 3 +- src/Application/UI/Presenter.php | 48 +++++++------------ src/Application/UI/Template.php | 3 +- .../ApplicationLatte/DefaultTemplate.php | 6 +-- src/Bridges/ApplicationLatte/Template.php | 13 ++--- .../ApplicationLatte/TemplateFactory.php | 3 +- .../TemplateFactory.customTemplate.phpt | 3 +- tests/UI/Control.formatTemplateClass.phpt | 2 +- tests/UI/Presenter.formatTemplateClass.phpt | 2 +- tests/UI/Presenter.link().persistent.phpt | 2 +- tests/UI/Presenter.link().php74.phpt | 2 +- tests/UI/Presenter.link().phpt | 2 +- tests/UI/Presenter.parameters.phpt | 2 +- tests/UI/Presenter.storeRequest().phpt | 7 +-- 25 files changed, 60 insertions(+), 118 deletions(-) diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index e8641fcb4..56e14e251 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -93,7 +93,7 @@ public function link(string $dest, array $params = []): string } - public function withReferenceUrl(string $url): self + public function withReferenceUrl(string $url): static { return new self( $this->router, diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index c2b0834f5..674938e2a 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -83,9 +83,8 @@ public function getPresenterClass(string &$name): string /** * Sets mapping as pairs [module => mask] - * @return static */ - public function setMapping(array $mapping) + public function setMapping(array $mapping): static { foreach ($mapping as $module => $mask) { if (is_string($mask)) { diff --git a/src/Application/Request.php b/src/Application/Request.php index 73c4f4f65..fbdcf28d3 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -72,9 +72,8 @@ public function __construct( /** * Sets the presenter name. - * @return static */ - public function setPresenterName(string $name) + public function setPresenterName(string $name): static { $this->name = $name; return $this; @@ -92,9 +91,8 @@ public function getPresenterName(): string /** * Sets variables provided to the presenter. - * @return static */ - public function setParameters(array $params) + public function setParameters(array $params): static { $this->params = $params; return $this; @@ -112,9 +110,8 @@ public function getParameters(): array /** * Returns a parameter provided to the presenter. - * @return mixed */ - public function getParameter(string $key) + public function getParameter(string $key): mixed { return $this->params[$key] ?? null; } @@ -122,9 +119,8 @@ public function getParameter(string $key) /** * Sets variables provided to the presenter via POST. - * @return static */ - public function setPost(array $params) + public function setPost(array $params): static { $this->post = $params; return $this; @@ -134,9 +130,8 @@ public function setPost(array $params) /** * Returns a variable provided to the presenter via POST. * If no key is passed, returns the entire array. - * @return mixed */ - public function getPost(?string $key = null) + public function getPost(?string $key = null): mixed { return func_num_args() === 0 ? $this->post @@ -146,9 +141,8 @@ public function getPost(?string $key = null) /** * Sets all uploaded files. - * @return static */ - public function setFiles(array $files) + public function setFiles(array $files): static { $this->files = $files; return $this; @@ -166,9 +160,8 @@ public function getFiles(): array /** * Sets the method. - * @return static */ - public function setMethod(?string $method) + public function setMethod(?string $method): static { $this->method = $method; return $this; @@ -195,9 +188,8 @@ public function isMethod(string $method): bool /** * Sets the flag. - * @return static */ - public function setFlag(string $flag, bool $value = true) + public function setFlag(string $flag, bool $value = true): static { $this->flags[$flag] = $value; return $this; diff --git a/src/Application/Responses/JsonResponse.php b/src/Application/Responses/JsonResponse.php index b50fec9bc..0ac3d2512 100644 --- a/src/Application/Responses/JsonResponse.php +++ b/src/Application/Responses/JsonResponse.php @@ -31,10 +31,7 @@ public function __construct($payload, ?string $contentType = null) } - /** - * @return mixed - */ - public function getPayload() + public function getPayload(): mixed { return $this->payload; } diff --git a/src/Application/Responses/TextResponse.php b/src/Application/Responses/TextResponse.php index 5806c1983..439a2b32d 100644 --- a/src/Application/Responses/TextResponse.php +++ b/src/Application/Responses/TextResponse.php @@ -22,19 +22,13 @@ final class TextResponse implements Nette\Application\Response private mixed $source; - /** - * @param mixed $source - */ - public function __construct($source) + public function __construct(mixed $source) { $this->source = $source; } - /** - * @return mixed - */ - public function getSource() + public function getSource(): mixed { return $this->source; } diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index c2b57a078..d1f88b7eb 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -63,25 +63,19 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri } - /** - * @param array|string|\Closure $metadata default values or metadata or callback for NetteModule\MicroPresenter - * @return static - */ public function addRoute( #[Language('TEXT')] string $mask, $metadata = [], int $flags = 0, - ) { + ): static + { $this->add(new Route($mask, $metadata), $flags); return $this; } - /** - * @return static - */ - public function withModule(string $module) + public function withModule(string $module): static { $router = new static; $router->module = $module . ':'; @@ -113,11 +107,9 @@ public function offsetSet($index, $router): void /** * @param int $index - * @return mixed * @throws Nette\OutOfRangeException */ - #[\ReturnTypeWillChange] - public function offsetGet($index) + public function offsetGet($index): mixed { if (!$this->offsetExists($index)) { throw new Nette\OutOfRangeException('Offset invalid or out of range'); diff --git a/src/Application/Routers/SimpleRouter.php b/src/Application/Routers/SimpleRouter.php index 90e99487c..35d2c8ad9 100644 --- a/src/Application/Routers/SimpleRouter.php +++ b/src/Application/Routers/SimpleRouter.php @@ -21,7 +21,7 @@ final class SimpleRouter extends Nette\Routing\SimpleRouter implements Nette\Rou private const PresenterKey = 'presenter'; - public function __construct(array $defaults = []) + public function __construct(array|string $defaults = []) { if (is_string($defaults)) { [$presenter, $action] = Nette\Application\Helpers::splitName($defaults); diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 9bfef9169..4f100d3f5 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -34,7 +34,6 @@ abstract class Component extends Nette\ComponentModel\Container implements Signa /** * Returns the presenter where this component belongs to. - * @return Presenter */ public function getPresenter(): Presenter { @@ -91,7 +90,6 @@ protected function validateParent(Nette\ComponentModel\IContainer $parent): void /** * Calls public method if exists. - * @return bool does method exist? */ protected function tryCall(string $method, array $params): bool { @@ -183,9 +181,8 @@ public function saveState(array &$params): void /** * Returns component param. - * @return mixed */ - final public function getParameter(string $name) + final public function getParameter(string $name): mixed { if (func_num_args() > 1) { $default = func_get_arg(1); diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 7c505becb..563a2f979 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -265,7 +265,6 @@ private static function dataLossConvert(&$val, string $type): bool /** * Returns an annotation value. - * @param \ReflectionClass|\ReflectionMethod $ref */ public static function parseAnnotation(\Reflector $ref, string $name): ?array { @@ -317,9 +316,8 @@ public function hasAnnotation(string $name): bool /** * Returns an annotation value. - * @return mixed */ - public function getAnnotation(string $name) + public function getAnnotation(string $name): mixed { $res = self::parseAnnotation($this, $name); return $res ? end($res) : null; diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index a9130f0f8..d03914bf1 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -97,9 +97,8 @@ public function templatePrepareFilters(Template $template): void /** * Saves the message to template, that can be displayed after redirect. - * @param string|\stdClass|Nette\HtmlStringable $message */ - public function flashMessage($message, string $type = 'info'): \stdClass + public function flashMessage(string|\stdClass|Nette\HtmlStringable $message, string $type = 'info'): \stdClass { $id = $this->getParameterId('flash'); $flash = $message instanceof \stdClass ? $message : (object) [ diff --git a/src/Application/UI/Link.php b/src/Application/UI/Link.php index 4e922fa9e..687a331b2 100644 --- a/src/Application/UI/Link.php +++ b/src/Application/UI/Link.php @@ -58,9 +58,8 @@ public function getDestination(): string /** * Changes link parameter. - * @return static */ - public function setParameter(string $key, $value) + public function setParameter(string $key, $value): static { $this->params[$key] = $value; return $this; @@ -69,9 +68,8 @@ public function setParameter(string $key, $value) /** * Returns link parameter. - * @return mixed */ - public function getParameter(string $key) + public function getParameter(string $key): mixed { return $this->params[$key] ?? null; } diff --git a/src/Application/UI/MethodReflection.php b/src/Application/UI/MethodReflection.php index c676e3331..6e3c8cba0 100644 --- a/src/Application/UI/MethodReflection.php +++ b/src/Application/UI/MethodReflection.php @@ -30,9 +30,8 @@ public function hasAnnotation(string $name): bool /** * Returns an annotation value. - * @return mixed */ - public function getAnnotation(string $name) + public function getAnnotation(string $name): mixed { $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 8b6a8fbb7..9a2fdd514 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -112,13 +112,13 @@ final public function getRequest(): ?Application\Request /** * Returns self. */ - final public function getPresenter(): self + final public function getPresenter(): static { return $this; } - final public function getPresenterIfExists(): self + final public function getPresenterIfExists(): static { return $this; } @@ -255,17 +255,13 @@ protected function beforeRender() /** * Common render method. - * @return void */ - protected function afterRender() + protected function afterRender(): void { } - /** - * @return void - */ - protected function shutdown(Application\Response $response) + protected function shutdown(Application\Response $response): void { } @@ -332,9 +328,8 @@ final public function getSignal(): ?array /** * Checks if the signal receiver is the given one. - * @param Component|string $component */ - final public function isSignalReceiver($component, $signal = null): bool + final public function isSignalReceiver(Nette\ComponentModel\Component|string $component, $signal = null): bool { if ($component instanceof Nette\ComponentModel\Component) { $component = $component === $this @@ -391,9 +386,8 @@ final public function getView(): string /** * Changes current view. Any name is allowed. - * @return static */ - public function setView(string $view) + public function setView(string $view): static { $this->view = $view; return $this; @@ -402,9 +396,8 @@ public function setView(string $view) /** * Returns current layout name. - * @return string|bool */ - final public function getLayout() + final public function getLayout(): string|bool { return $this->layout; } @@ -412,10 +405,8 @@ final public function getLayout() /** * Changes or disables layout. - * @param string|bool $layout - * @return static */ - public function setLayout($layout) + public function setLayout(string|bool $layout): static { $this->layout = $layout === false ? false : (string) $layout; return $this; @@ -538,9 +529,6 @@ public static function formatRenderMethod(string $view): string } - /** - * @param string $class - */ protected function createTemplate(/*string $class = null*/): Template { $class = func_num_args() // back compatibility @@ -593,11 +581,10 @@ public function sendPayload(): void /** * Sends JSON data to the output. - * @param mixed $data * @throws Nette\Application\AbortException * @return never */ - public function sendJson($data): void + public function sendJson(mixed $data): void { $this->sendResponse(new Responses\JsonResponse($data)); } @@ -631,12 +618,11 @@ public function terminate(): void /** * Forward to another presenter or action. - * @param string|Nette\Application\Request $destination * @param array|mixed $args * @throws Nette\Application\AbortException * @return never */ - public function forward($destination, $args = []): void + public function forward(string|Nette\Application\Request $destination, $args = []): void { if ($destination instanceof Application\Request) { $this->sendResponse(new Responses\ForwardResponse($destination)); @@ -729,12 +715,15 @@ public function canonicalize(?string $destination = null, ...$args): void /** * Attempts to cache the sent entity by its last modification date. - * @param string|int|\DateTimeInterface $lastModified * @param string $etag strong entity tag validator * @param string $expire like '20 minutes' * @throws Nette\Application\AbortException */ - public function lastModified($lastModified, ?string $etag = null, ?string $expire = null): void + public function lastModified( + string|int|\DateTimeInterface $lastModified, + ?string $etag = null, + ?string $expire = null, + ): void { if ($expire !== null) { $this->httpResponse->setExpiration($expire); @@ -751,7 +740,6 @@ public function lastModified($lastModified, ?string $etag = null, ?string $expir * Request/URL factory. * @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]" * @param string $mode forward|redirect|link - * @return string|null URL * @throws InvalidLinkException * @internal */ @@ -1097,7 +1085,6 @@ protected function handleInvalidLink(InvalidLinkException $e): string /** * Stores current request to session. - * @return string key */ public function storeRequest(string $expiration = '+ 10 minutes'): string { @@ -1399,10 +1386,7 @@ final public function getHttpResponse(): Http\IResponse } - /** - * @return Http\Session|Http\SessionSection - */ - final public function getSession(?string $namespace = null) + final public function getSession(?string $namespace = null): Http\Session|Http\SessionSection { if (!$this->session) { throw new Nette\InvalidStateException('Service Session has not been set.'); diff --git a/src/Application/UI/Template.php b/src/Application/UI/Template.php index b4374d3fd..d50339577 100644 --- a/src/Application/UI/Template.php +++ b/src/Application/UI/Template.php @@ -22,9 +22,8 @@ function render(): void; /** * Sets the path to the template file. - * @return static */ - function setFile(string $file); + function setFile(string $file): static; /** * Returns the path to the template file. diff --git a/src/Bridges/ApplicationLatte/DefaultTemplate.php b/src/Bridges/ApplicationLatte/DefaultTemplate.php index e80193dde..bd93e1997 100644 --- a/src/Bridges/ApplicationLatte/DefaultTemplate.php +++ b/src/Bridges/ApplicationLatte/DefaultTemplate.php @@ -33,9 +33,8 @@ final class DefaultTemplate extends Template /** * Adds new template parameter. - * @return static */ - public function add(string $name, $value) + public function add(string $name, $value): static { if (property_exists($this, $name)) { throw new Nette\InvalidStateException("The variable '$name' already exists."); @@ -48,9 +47,8 @@ public function add(string $name, $value) /** * Sets all parameters. - * @return static */ - public function setParameters(array $params) + public function setParameters(array $params): static { return Nette\Utils\Arrays::toObject($params, $this); } diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index 41ff4921d..28cfdacb6 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -57,7 +57,6 @@ public function renderToString(?string $file = null, array $params = []): string /** * Renders template to string. - * @param can throw exceptions? (hidden parameter) */ public function __toString(): string { @@ -70,9 +69,8 @@ public function __toString(): string /** * Registers run-time filter. - * @return static */ - public function addFilter(?string $name, callable $callback) + public function addFilter(?string $name, callable $callback): static { $this->latte->addFilter($name, $callback); return $this; @@ -81,9 +79,8 @@ public function addFilter(?string $name, callable $callback) /** * Registers run-time function. - * @return static */ - public function addFunction(string $name, callable $callback) + public function addFunction(string $name, callable $callback): static { $this->latte->addFunction($name, $callback); return $this; @@ -92,9 +89,8 @@ public function addFunction(string $name, callable $callback) /** * Sets translate adapter. - * @return static */ - public function setTranslator(?Nette\Localization\Translator $translator, ?string $language = null) + public function setTranslator(?Nette\Localization\Translator $translator, ?string $language = null): static { if (version_compare(Latte\Engine::VERSION, '3', '<')) { $this->latte->addFilter( @@ -115,9 +111,8 @@ public function setTranslator(?Nette\Localization\Translator $translator, ?strin /** * Sets the path to the template file. - * @return static */ - public function setFile(string $file) + public function setFile(string $file): static { $this->file = $file; return $this; diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 099afa405..e688ed200 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -49,8 +49,7 @@ public function __construct( } - /** @return Template */ - public function createTemplate(?UI\Control $control = null, ?string $class = null): UI\Template + public function createTemplate(?UI\Control $control = null, ?string $class = null): Template { $class ??= $this->templateClass; if (!is_a($class, Template::class, allow_string: true)) { diff --git a/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt b/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt index af5630b7a..e484c1f87 100644 --- a/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt +++ b/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt @@ -32,9 +32,10 @@ class TemplateMock extends Template } - public function setFile(string $file) + public function setFile(string $file): static { $this->file = $file; + return $this; } diff --git a/tests/UI/Control.formatTemplateClass.phpt b/tests/UI/Control.formatTemplateClass.phpt index 789d6b952..4d66a4a49 100644 --- a/tests/UI/Control.formatTemplateClass.phpt +++ b/tests/UI/Control.formatTemplateClass.phpt @@ -35,7 +35,7 @@ class CTemplate implements Nette\Application\UI\Template } - public function setFile(string $file) + public function setFile(string $file): static { } diff --git a/tests/UI/Presenter.formatTemplateClass.phpt b/tests/UI/Presenter.formatTemplateClass.phpt index 80388035f..b9ed33bb7 100644 --- a/tests/UI/Presenter.formatTemplateClass.phpt +++ b/tests/UI/Presenter.formatTemplateClass.phpt @@ -35,7 +35,7 @@ class CTemplate implements Nette\Application\UI\Template } - public function setFile(string $file) + public function setFile(string $file): static { } diff --git a/tests/UI/Presenter.link().persistent.phpt b/tests/UI/Presenter.link().persistent.phpt index bd8861d0e..558858f94 100644 --- a/tests/UI/Presenter.link().persistent.phpt +++ b/tests/UI/Presenter.link().persistent.phpt @@ -54,7 +54,7 @@ class TestPresenter extends BasePresenter public $p2; - protected function startup() + protected function startup(): void { parent::startup(); diff --git a/tests/UI/Presenter.link().php74.phpt b/tests/UI/Presenter.link().php74.phpt index 4c87c94aa..4e1243a87 100644 --- a/tests/UI/Presenter.link().php74.phpt +++ b/tests/UI/Presenter.link().php74.phpt @@ -70,7 +70,7 @@ class TestPresenter extends Application\UI\Presenter public ?bool $pbooln = null; - protected function startup() + protected function startup(): void { parent::startup(); $this['mycontrol'] = new TestControl; diff --git a/tests/UI/Presenter.link().phpt b/tests/UI/Presenter.link().phpt index 5191f0d1d..eb8926058 100644 --- a/tests/UI/Presenter.link().phpt +++ b/tests/UI/Presenter.link().phpt @@ -63,7 +63,7 @@ class TestPresenter extends Application\UI\Presenter public $pbool = true; - protected function startup() + protected function startup(): void { parent::startup(); $this['mycontrol'] = new TestControl; diff --git a/tests/UI/Presenter.parameters.phpt b/tests/UI/Presenter.parameters.phpt index c55be4093..945eed562 100644 --- a/tests/UI/Presenter.parameters.phpt +++ b/tests/UI/Presenter.parameters.phpt @@ -25,7 +25,7 @@ class TestPresenter extends Application\UI\Presenter } - protected function startup() + protected function startup(): void { parent::startup(); throw new Application\AbortException; diff --git a/tests/UI/Presenter.storeRequest().phpt b/tests/UI/Presenter.storeRequest().phpt index 022249f6e..e25726643 100644 --- a/tests/UI/Presenter.storeRequest().phpt +++ b/tests/UI/Presenter.storeRequest().phpt @@ -74,10 +74,11 @@ class MockSessionSection extends Nette\Http\SessionSection } - public function setExpiration($expiraton, $variables = null) + public function setExpiration(?string $expiraton, string|array|null $variables = null): static { $this->testExpiration = $expiraton; $this->testExpirationVariables = $variables; + return $this; } @@ -93,7 +94,7 @@ class MockSessionSection extends Nette\Http\SessionSection } - public function offsetGet($name) + public function offsetGet($name): mixed { } @@ -110,7 +111,7 @@ class MockUser extends Security\User } - public function getId() + public function getId(): string|int { return 'test_id'; } From 2d5ac40ae71936db21ca2b4ce8566f754b8e1f33 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 12 Dec 2021 17:32:07 +0100 Subject: [PATCH 14/42] used constructor promotion --- src/Application/ErrorPresenter.php | 9 ++---- src/Application/LinkGenerator.php | 17 ++++------- src/Application/MicroPresenter.php | 15 ++-------- src/Application/Request.php | 30 ++++--------------- .../ApplicationDI/ApplicationExtension.php | 15 ++-------- .../PresenterFactoryCallback.php | 17 ++++------- .../ApplicationLatte/TemplateFactory.php | 16 +++------- 7 files changed, 29 insertions(+), 90 deletions(-) diff --git a/src/Application/ErrorPresenter.php b/src/Application/ErrorPresenter.php index a71d594bb..77f79e4a7 100644 --- a/src/Application/ErrorPresenter.php +++ b/src/Application/ErrorPresenter.php @@ -22,12 +22,9 @@ final class ErrorPresenter implements Application\IPresenter { use Nette\SmartObject; - private ?ILogger $logger; - - - public function __construct(?ILogger $logger = null) - { - $this->logger = $logger; + public function __construct( + private ?ILogger $logger = null, + ) { } diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index 56e14e251..dcf2b9824 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -21,18 +21,11 @@ final class LinkGenerator { use Nette\SmartObject; - private Router $router; - - private UrlScript $refUrl; - - private ?IPresenterFactory $presenterFactory; - - - public function __construct(Router $router, UrlScript $refUrl, ?IPresenterFactory $presenterFactory = null) - { - $this->router = $router; - $this->refUrl = $refUrl; - $this->presenterFactory = $presenterFactory; + public function __construct( + private Router $router, + private UrlScript $refUrl, + private ?IPresenterFactory $presenterFactory = null, + ) { } diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index e33b7a56a..24426e0f1 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -24,23 +24,14 @@ final class MicroPresenter implements Application\IPresenter { use Nette\SmartObject; - private ?Nette\DI\Container $context; - - private ?Nette\Http\IRequest $httpRequest; - - private ?Router $router; - private ?Application\Request $request; public function __construct( - ?Nette\DI\Container $context = null, - ?Http\IRequest $httpRequest = null, - ?Router $router = null, + private ?Nette\DI\Container $context = null, + private ?Nette\Http\IRequest $httpRequest = null, + private ?Router $router = null, ) { - $this->context = $context; - $this->httpRequest = $httpRequest; - $this->router = $router; } diff --git a/src/Application/Request.php b/src/Application/Request.php index fbdcf28d3..557db970d 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -37,36 +37,18 @@ final class Request /** flag */ public const VARYING = 'varying'; - private ?string $method; - - private array $flags = []; - - private string $name; - - private array $params; - - private array $post; - - private array $files; - /** * @param string $name presenter name (module:module:presenter) */ public function __construct( - string $name, - ?string $method = null, - array $params = [], - array $post = [], - array $files = [], - array $flags = [], + private string $name, + private ?string $method = null, + private array $params = [], + private array $post = [], + private array $files = [], + private array $flags = [], ) { - $this->name = $name; - $this->method = $method; - $this->params = $params; - $this->post = $post; - $this->files = $files; - $this->flags = $flags; } diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index a22a0bdb8..8250806ea 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -22,27 +22,18 @@ */ final class ApplicationExtension extends Nette\DI\CompilerExtension { - private bool $debugMode; - private array $scanDirs; - private ?Nette\Loaders\RobotLoader $robotLoader; - private int $invalidLinkMode; - private ?string $tempDir; - public function __construct( - bool $debugMode = false, + private bool $debugMode = false, ?array $scanDirs = null, - ?string $tempDir = null, - ?Nette\Loaders\RobotLoader $robotLoader = null, + private ?string $tempDir = null, + private ?Nette\Loaders\RobotLoader $robotLoader = null, ) { - $this->debugMode = $debugMode; $this->scanDirs = (array) $scanDirs; - $this->tempDir = $tempDir; - $this->robotLoader = $robotLoader; } diff --git a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php index d9d932ec7..42b5f21eb 100644 --- a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php +++ b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php @@ -18,18 +18,11 @@ */ final class PresenterFactoryCallback { - private Nette\DI\Container $container; - - private int $invalidLinkMode; - - private ?string $touchToRefresh; - - - public function __construct(Nette\DI\Container $container, int $invalidLinkMode, ?string $touchToRefresh) - { - $this->container = $container; - $this->invalidLinkMode = $invalidLinkMode; - $this->touchToRefresh = $touchToRefresh; + public function __construct( + private Nette\DI\Container $container, + private int $invalidLinkMode, + private ?string $touchToRefresh, + ) { } diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index e688ed200..252eadc7b 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -23,24 +23,16 @@ class TemplateFactory implements UI\TemplateFactory /** @var array Occurs when a new template is created */ public array $onCreate = []; - private LatteFactory $latteFactory; - private ?Nette\Http\IRequest $httpRequest; - private ?Nette\Security\User $user; - private ?Nette\Caching\Storage $cacheStorage; private string $templateClass; public function __construct( - LatteFactory $latteFactory, - ?Nette\Http\IRequest $httpRequest = null, - ?Nette\Security\User $user = null, - ?Nette\Caching\Storage $cacheStorage = null, + private LatteFactory $latteFactory, + private ?Nette\Http\IRequest $httpRequest = null, + private ?Nette\Security\User $user = null, + private ?Nette\Caching\Storage $cacheStorage = null, $templateClass = null, ) { - $this->latteFactory = $latteFactory; - $this->httpRequest = $httpRequest; - $this->user = $user; - $this->cacheStorage = $cacheStorage; if ($templateClass && (!class_exists($templateClass) || !is_a($templateClass, Template::class, true))) { throw new Nette\InvalidArgumentException("Class $templateClass does not implement " . Template::class . ' or it does not exist.'); } From fd002ee6d6158dae6b753d9a142dae736f1fcd67 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Jul 2021 12:44:47 +0200 Subject: [PATCH 15/42] used native PHP 8 features --- src/Application/Application.php | 2 +- src/Application/UI/Component.php | 4 +- src/Application/UI/ComponentReflection.php | 12 ++-- src/Application/UI/Presenter.php | 6 +- src/Bridges/ApplicationDI/LatteExtension.php | 8 +-- .../TemplateFactory.customTemplate.phpt | 4 +- .../FileResponse.contentDisposition.phpt | 2 +- tests/Responses/FileResponse.range.phpt | 16 ++--- tests/UI/ComponentReflection.combineArgs.phpt | 72 +++++++++---------- tests/UI/ComponentReflection.convertType.phpt | 20 ------ tests/UI/Presenter.link().persistent.phpt | 2 +- tests/UI/Presenter.link().php74.phpt | 20 +++--- tests/UI/Presenter.link().phpt | 20 +++--- tests/UI/Presenter.paramChecking.phpt | 14 ++-- 14 files changed, 91 insertions(+), 111 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index ff78fe910..4d0ac0cd9 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -105,7 +105,7 @@ public function createInitialRequest(): Request throw new BadRequestException('No route for HTTP request.'); } elseif (!is_string($presenter)) { throw new Nette\InvalidStateException('Missing presenter in route definition.'); - } elseif (Nette\Utils\Strings::startsWith($presenter, 'Nette:') && $presenter !== 'Nette:Micro') { + } elseif (str_starts_with($presenter, 'Nette:') && $presenter !== 'Nette:Micro') { throw new BadRequestException('Invalid request. Presenter is not achievable.'); } diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 4f100d3f5..a02e6468f 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -120,7 +120,7 @@ public function checkRequirements($element): void { if ( $element instanceof \ReflectionMethod - && substr($element->getName(), 0, 6) === 'handle' + && str_starts_with($element->getName(), 'handle') && !ComponentReflection::parseAnnotation($element, 'crossOrigin') && !$element->getAttributes(Nette\Application\Attributes\CrossOrigin::class) && !$this->getPresenter()->getHttpRequest()->isSameSite() @@ -156,7 +156,7 @@ public function loadState(array $params): void $name, $this instanceof Presenter ? 'presenter ' . $this->getName() : "component '{$this->getUniqueId()}'", $meta['type'], - is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]), + get_debug_type($params[$name]), )); } diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 563a2f979..bb2fc67b5 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -139,7 +139,7 @@ public function saveState(Component $component, array &$params): void $name, $component instanceof Presenter ? 'presenter ' . $component->getName() : "component '{$component->getUniqueId()}'", $meta['type'], - is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]), + get_debug_type($params[$name]), )); } @@ -185,7 +185,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a $name, ($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName(), $type, - is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]), + get_debug_type($args[$name]), )); } } elseif ($param->isDefaultValueAvailable()) { @@ -227,7 +227,7 @@ public static function convertType(&$val, string $types): bool */ private static function convertSingleType(&$val, string $type): bool { - $scalars = ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'true' => 1, 'false' => 1, 'boolean' => 1, 'double' => 1, 'integer' => 1]; + $scalars = ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'true' => 1, 'false' => 1]; $tests = ['iterable' => 1, 'object' => 1, 'array' => 1, 'null' => 1]; return match (true) { isset($scalars[$type]) => self::dataLossConvert($val, $type), @@ -247,7 +247,7 @@ private static function dataLossConvert(&$val, string $type): bool } $tmp = ($val === false ? '0' : (string) $val); - if ($type === 'double' || $type === 'float') { + if ($type === 'float') { $tmp = preg_replace('#\.0*$#D', '', $tmp); } @@ -292,7 +292,7 @@ public static function getParameterType(\ReflectionParameter $param): string $type = $param->getType(); return $type ? ($type instanceof \ReflectionNamedType ? $type->getName() : (string) $type) - : ($default === null ? 'scalar' : gettype($default)); + : ($default === null ? 'scalar' : get_debug_type($default)); } @@ -301,7 +301,7 @@ public static function getPropertyType(\ReflectionProperty $prop, $default): str $type = $prop->getType(); return $type ? ($type instanceof \ReflectionNamedType ? $type->getName() : (string) $type) - : ($default === null ? 'scalar' : gettype($default)); + : ($default === null ? 'scalar' : get_debug_type($default)); } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 9a2fdd514..46ab07999 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -142,7 +142,7 @@ public function getUniqueId(): string public function isModuleCurrent(string $module): bool { $current = Helpers::splitName($this->getName())[0]; - return Nette\Utils\Strings::startsWith($current . ':', ltrim($module . ':', ':')); + return str_starts_with($current . ':', ltrim($module . ':', ':')); } @@ -808,7 +808,7 @@ protected function createRequest( if (array_key_exists(0, $args)) { throw new InvalidLinkException("Unable to pass parameters to 'this!' signal."); } - } elseif (strpos($signal, self::NAME_SEPARATOR) === false) { + } elseif (!str_contains($signal, self::NAME_SEPARATOR)) { // counterpart of signalReceived() & tryCall() $method = $component->formatSignalMethod($signal); if (!$reflection->hasCallableMethod($method)) { @@ -1044,7 +1044,7 @@ public static function argsToParams( $name, $rm->getDeclaringClass()->getName() . '::' . $rm->getName(), $type, - is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]), + get_debug_type($args[$name]), )); } diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 0d40e6a26..2036fb7df 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -132,16 +132,16 @@ public function addMacro(string $macro): void $definition = $builder->getDefinition($this->prefix('latteFactory'))->getResultDefinition(); if (($macro[0] ?? null) === '@') { - if (strpos($macro, '::') === false) { - $method = 'install'; - } else { + if (str_contains($macro, '::')) { [$macro, $method] = explode('::', $macro); + } else { + $method = 'install'; } $definition->addSetup('?->onCompile[] = function ($engine) { ?->' . $method . '($engine->getCompiler()); }', ['@self', $macro]); } else { - if (strpos($macro, '::') === false && class_exists($macro)) { + if (!str_contains($macro, '::') && class_exists($macro)) { $macro .= '::install'; } diff --git a/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt b/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt index e484c1f87..976f99b78 100644 --- a/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt +++ b/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt @@ -54,7 +54,7 @@ test('', function () { }); Assert::exception( - fn() => new TemplateFactory(Mockery::mock(LatteFactory::class), null, null, null, stdClass::class), + fn() => new TemplateFactory(Mockery::mock(LatteFactory::class), templateClass: stdClass::class), Nette\InvalidArgumentException::class, 'Class stdClass does not implement Nette\Bridges\ApplicationLatte\Template or it does not exist.', ); @@ -63,7 +63,7 @@ Assert::exception( test('', function () { $latteFactory = Mockery::mock(LatteFactory::class); $latteFactory->shouldReceive('create')->andReturn(new Latte\Engine); - $factory = new TemplateFactory($latteFactory, null, null, null, TemplateMock::class); + $factory = new TemplateFactory($latteFactory, templateClass: TemplateMock::class); $template = $factory->createTemplate(); Assert::type(TemplateMock::class, $template); Assert::type(UI\Template::class, $template); diff --git a/tests/Responses/FileResponse.contentDisposition.phpt b/tests/Responses/FileResponse.contentDisposition.phpt index 1650b54ad..173b8680d 100644 --- a/tests/Responses/FileResponse.contentDisposition.phpt +++ b/tests/Responses/FileResponse.contentDisposition.phpt @@ -36,7 +36,7 @@ test('', function () { test('', function () { $file = __FILE__; - $fileResponse = new FileResponse($file, null, null, false); + $fileResponse = new FileResponse($file, forceDownload: false); $origData = file_get_contents($file); $fileInfo = pathinfo($file); diff --git a/tests/Responses/FileResponse.range.phpt b/tests/Responses/FileResponse.range.phpt index 575757227..99c380854 100644 --- a/tests/Responses/FileResponse.range.phpt +++ b/tests/Responses/FileResponse.range.phpt @@ -22,7 +22,7 @@ $origData = file_get_contents($file); test('', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( - new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=10-20']), + new Http\Request(new Http\UrlScript, headers: ['range' => 'bytes=10-20']), $response = new Http\Response, ); Assert::same(substr($origData, 10, 11), ob_get_clean()); @@ -33,7 +33,7 @@ test('', function () use ($fileResponse, $origData) { test('', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( - new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=10-10']), + new Http\Request(new Http\UrlScript, headers: ['range' => 'bytes=10-10']), new Http\Response, ); Assert::same(substr($origData, 10, 1), ob_get_clean()); @@ -43,7 +43,7 @@ test('', function () use ($fileResponse, $origData) { test('', function () use ($fileResponse, $origData, $file) { ob_start(); $fileResponse->send( - new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=10-' . filesize($file)]), + new Http\Request(new Http\UrlScript, headers: ['range' => 'bytes=10-' . filesize($file)]), new Http\Response, ); Assert::same(substr($origData, 10), ob_get_clean()); @@ -53,7 +53,7 @@ test('', function () use ($fileResponse, $origData, $file) { test('prefix', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( - new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=20-']), + new Http\Request(new Http\UrlScript, headers: ['range' => 'bytes=20-']), new Http\Response, ); Assert::same(substr($origData, 20), ob_get_clean()); @@ -63,7 +63,7 @@ test('prefix', function () use ($fileResponse, $origData) { test('prefix', function () use ($fileResponse, $origData, $file) { ob_start(); $fileResponse->send( - new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=' . (filesize($file) - 1) . '-']), + new Http\Request(new Http\UrlScript, headers: ['range' => 'bytes=' . (filesize($file) - 1) . '-']), new Http\Response, ); Assert::same(substr($origData, -1), ob_get_clean()); @@ -73,7 +73,7 @@ test('prefix', function () use ($fileResponse, $origData, $file) { test('prefix', function () use ($fileResponse, $file) { ob_start(); $fileResponse->send( - new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=' . filesize($file) . '-']), + new Http\Request(new Http\UrlScript, headers: ['range' => 'bytes=' . filesize($file) . '-']), $response = new Http\Response, ); Assert::same('', ob_get_clean()); @@ -84,7 +84,7 @@ test('prefix', function () use ($fileResponse, $file) { test('suffix', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( - new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=-20']), + new Http\Request(new Http\UrlScript, headers: ['range' => 'bytes=-20']), new Http\Response, ); Assert::same(substr($origData, -20), ob_get_clean()); @@ -94,7 +94,7 @@ test('suffix', function () use ($fileResponse, $origData) { test('suffix', function () use ($fileResponse, $origData, $file) { ob_start(); $fileResponse->send( - new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=-' . filesize($file)]), + new Http\Request(new Http\UrlScript, headers: ['range' => 'bytes=-' . filesize($file)]), new Http\Response, ); Assert::same($origData, ob_get_clean()); diff --git a/tests/UI/ComponentReflection.combineArgs.phpt b/tests/UI/ComponentReflection.combineArgs.phpt index 3506cd3b2..aa22439b6 100644 --- a/tests/UI/ComponentReflection.combineArgs.phpt +++ b/tests/UI/ComponentReflection.combineArgs.phpt @@ -77,7 +77,7 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, ['int' => []]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::params() must be scalar, array given.' + 'Argument $int passed to MyPresenter::params() must be scalar, array given.', ); }); @@ -91,43 +91,43 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, []), Nette\InvalidArgumentException::class, - 'Missing parameter $int required by MyPresenter::hints()' + 'Missing parameter $int required by MyPresenter::hints()', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '']), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hints() must be int, string given.' + 'Argument $int passed to MyPresenter::hints() must be int, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => null]), Nette\InvalidArgumentException::class, - 'Missing parameter $int required by MyPresenter::hints()' + 'Missing parameter $int required by MyPresenter::hints()', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => new stdClass]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hints() must be int, stdClass given.' + 'Argument $int passed to MyPresenter::hints() must be int, stdClass given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => []]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hints() must be int, array given.' + 'Argument $int passed to MyPresenter::hints() must be int, array given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), Nette\InvalidArgumentException::class, - 'Argument $bool passed to MyPresenter::hints() must be bool, string given.' + 'Argument $bool passed to MyPresenter::hints() must be bool, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), Nette\InvalidArgumentException::class, - 'Argument $arr passed to MyPresenter::hints() must be array, string given.' + 'Argument $arr passed to MyPresenter::hints() must be array, string given.', ); }); @@ -143,31 +143,31 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '']), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNulls() must be int, string given.' + 'Argument $int passed to MyPresenter::hintsNulls() must be int, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => new stdClass]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNulls() must be int, stdClass given.' + 'Argument $int passed to MyPresenter::hintsNulls() must be int, stdClass given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => []]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNulls() must be int, array given.' + 'Argument $int passed to MyPresenter::hintsNulls() must be int, array given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), Nette\InvalidArgumentException::class, - 'Argument $bool passed to MyPresenter::hintsNulls() must be bool, string given.' + 'Argument $bool passed to MyPresenter::hintsNulls() must be bool, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), Nette\InvalidArgumentException::class, - 'Argument $arr passed to MyPresenter::hintsNulls() must be array, string given.' + 'Argument $arr passed to MyPresenter::hintsNulls() must be array, string given.', ); }); @@ -183,31 +183,31 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '']), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNullable() must be int, string given.' + 'Argument $int passed to MyPresenter::hintsNullable() must be int, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => new stdClass]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNullable() must be int, stdClass given.' + 'Argument $int passed to MyPresenter::hintsNullable() must be int, stdClass given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => []]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNullable() must be int, array given.' + 'Argument $int passed to MyPresenter::hintsNullable() must be int, array given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), Nette\InvalidArgumentException::class, - 'Argument $bool passed to MyPresenter::hintsNullable() must be bool, string given.' + 'Argument $bool passed to MyPresenter::hintsNullable() must be bool, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), Nette\InvalidArgumentException::class, - 'Argument $arr passed to MyPresenter::hintsNullable() must be array, string given.' + 'Argument $arr passed to MyPresenter::hintsNullable() must be array, string given.', ); }); @@ -223,31 +223,31 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '']), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsDefaults() must be int, string given.' + 'Argument $int passed to MyPresenter::hintsDefaults() must be int, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => new stdClass]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsDefaults() must be int, stdClass given.' + 'Argument $int passed to MyPresenter::hintsDefaults() must be int, stdClass given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => []]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsDefaults() must be int, array given.' + 'Argument $int passed to MyPresenter::hintsDefaults() must be int, array given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), Nette\InvalidArgumentException::class, - 'Argument $bool passed to MyPresenter::hintsDefaults() must be bool, string given.' + 'Argument $bool passed to MyPresenter::hintsDefaults() must be bool, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), Nette\InvalidArgumentException::class, - 'Argument $arr passed to MyPresenter::hintsDefaults() must be array, string given.' + 'Argument $arr passed to MyPresenter::hintsDefaults() must be array, string given.', ); }); @@ -263,31 +263,31 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '']), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::defaults() must be integer, string given.' + 'Argument $int passed to MyPresenter::defaults() must be int, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => new stdClass]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::defaults() must be integer, stdClass given.' + 'Argument $int passed to MyPresenter::defaults() must be int, stdClass given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => []]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::defaults() must be integer, array given.' + 'Argument $int passed to MyPresenter::defaults() must be int, array given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), Nette\InvalidArgumentException::class, - 'Argument $bool passed to MyPresenter::defaults() must be boolean, string given.' + 'Argument $bool passed to MyPresenter::defaults() must be bool, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), Nette\InvalidArgumentException::class, - 'Argument $arr passed to MyPresenter::defaults() must be array, string given.' + 'Argument $arr passed to MyPresenter::defaults() must be array, string given.', ); }); @@ -300,25 +300,25 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, []), Nette\InvalidArgumentException::class, - 'Missing parameter $req required by MyPresenter::objects()' + 'Missing parameter $req required by MyPresenter::objects()', ); Assert::exception( fn() => Reflection::combineArgs($method, ['req' => null, 'nullable' => null, 'opt' => null]), Nette\InvalidArgumentException::class, - 'Missing parameter $req required by MyPresenter::objects()' + 'Missing parameter $req required by MyPresenter::objects()', ); Assert::exception( fn() => Reflection::combineArgs($method, ['req' => $method, 'opt' => null]), Nette\InvalidArgumentException::class, - 'Argument $req passed to MyPresenter::objects() must be stdClass, ReflectionMethod given.' + 'Argument $req passed to MyPresenter::objects() must be stdClass, ReflectionMethod given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['req' => [], 'opt' => null]), Nette\InvalidArgumentException::class, - 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.' + 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.', ); }); @@ -332,24 +332,24 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, []), Nette\InvalidArgumentException::class, - 'Missing parameter $intArray required by MyPresenter::hintsUnion()' + 'Missing parameter $intArray required by MyPresenter::hintsUnion()', ); Assert::exception( fn() => Reflection::combineArgs($method, ['intArray' => '']), Nette\InvalidArgumentException::class, - 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given.' + 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['intArray' => null]), Nette\InvalidArgumentException::class, - 'Missing parameter $intArray required by MyPresenter::hintsUnion()' + 'Missing parameter $intArray required by MyPresenter::hintsUnion()', ); Assert::exception( fn() => Reflection::combineArgs($method, ['intArray' => new stdClass]), Nette\InvalidArgumentException::class, - 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given.' + 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given.', ); }); diff --git a/tests/UI/ComponentReflection.convertType.phpt b/tests/UI/ComponentReflection.convertType.phpt index daa0f7944..b06796990 100644 --- a/tests/UI/ComponentReflection.convertType.phpt +++ b/tests/UI/ComponentReflection.convertType.phpt @@ -105,26 +105,6 @@ testIt('int', 1, 1); testIt('int', 1.0, 1); testIt('int', 1.2); -testIt('double', null); -testIt('double', []); -testIt('double', $obj); -testIt('double', ''); -testIt('double', 'a'); -testIt('double', '0', 0.0); -testIt('double', '1', 1.0); -testIt('double', '1.', 1.0); -testIt('double', '1.0', 1.0); -testIt('double', '1.00', 1.0); -testIt('double', '1..0'); -testIt('double', '1.1', 1.1); -testIt('double', '1a'); -testIt('double', true, 1.0); -testIt('double', false, 0.0); -testIt('double', 0, 0.0); -testIt('double', 1, 1.0); -testIt('double', 1.0, 1.0); -testIt('double', 1.2, 1.2); - testIt('float', null); testIt('float', []); testIt('float', $obj); diff --git a/tests/UI/Presenter.link().persistent.phpt b/tests/UI/Presenter.link().persistent.phpt index 558858f94..54f0bb2c9 100644 --- a/tests/UI/Presenter.link().persistent.phpt +++ b/tests/UI/Presenter.link().persistent.phpt @@ -115,7 +115,7 @@ Assert::same([ ], TestPresenter::getReflection()->getPersistentParams()); Assert::same([ - 'p1' => ['def' => 20, 'type' => 'integer', 'since' => 'BasePresenter'], + 'p1' => ['def' => 20, 'type' => 'int', 'since' => 'BasePresenter'], 'p3' => ['def' => null, 'type' => 'scalar', 'since' => 'SecondPresenter'], 't1' => ['def' => null, 'type' => 'scalar', 'since' => 'PersistentParam1'], 't3' => ['def' => null, 'type' => 'scalar', 'since' => 'PersistentParam3'], diff --git a/tests/UI/Presenter.link().php74.phpt b/tests/UI/Presenter.link().php74.phpt index 4e1243a87..67419df3c 100644 --- a/tests/UI/Presenter.link().php74.phpt +++ b/tests/UI/Presenter.link().php74.phpt @@ -108,7 +108,7 @@ class TestPresenter extends Application\UI\Presenter Assert::same(['pint' => 20, 'pbool' => null, 'parr' => [1], 'action' => 'params'], $this->getLastCreatedRequest()->getParameters()); Assert::same('/index.php?pint=1&pbool=0&action=params&presenter=Test', $this->link('params', ['pint' => true, 'pbool' => '0', 'parr' => []])); Assert::same('/index.php?pint=0&pbool=0&p=0&action=params&presenter=Test', $this->link('params', ['pint' => false, 'pbool' => false, 'p' => false, 'parr' => null])); - Assert::same("#error: Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given.", $this->link('this', ['p' => null, 'pbool' => 'a'])); + Assert::same("#error: Value passed to persistent parameter 'pbool' in presenter Test must be bool, string given.", $this->link('this', ['p' => null, 'pbool' => 'a'])); Assert::same("#error: Value passed to persistent parameter 'p' in presenter Test must be scalar, array given.", $this->link('this', ['p' => [1], 'pbool' => false])); Assert::same('/index.php?action=persistent&presenter=Test', $this->link('persistent')); @@ -148,10 +148,10 @@ class TestPresenter extends Application\UI\Presenter Assert::same(['mycontrol-x' => 1, 'mycontrol-y' => 2, 'mycontrol-round' => null, 'mycontrol-order' => null, 'pint' => null, 'parr' => null, 'pbool' => null, 'action' => 'default', 'do' => 'mycontrol-click'], $this->getLastCreatedRequest()->getParameters()); // Component link type checking - Assert::same("#error: Value passed to persistent parameter 'order' in component 'mycontrol' must be array, integer given.", $this['mycontrol']->link('click', ['order' => 1])); - Assert::same("#error: Value passed to persistent parameter 'round' in component 'mycontrol' must be integer, array given.", $this['mycontrol']->link('click', ['round' => []])); + Assert::same("#error: Value passed to persistent parameter 'order' in component 'mycontrol' must be array, int given.", $this['mycontrol']->link('click', ['order' => 1])); + Assert::same("#error: Value passed to persistent parameter 'round' in component 'mycontrol' must be int, array given.", $this['mycontrol']->link('click', ['round' => []])); $this['mycontrol']->order = 1; - Assert::same("#error: Value passed to persistent parameter 'order' in component 'mycontrol' must be array, integer given.", $this['mycontrol']->link('click')); + Assert::same("#error: Value passed to persistent parameter 'order' in component 'mycontrol' must be array, int given.", $this['mycontrol']->link('click')); $this['mycontrol']->order = null; // type checking @@ -209,10 +209,10 @@ class TestPresenter extends Application\UI\Presenter Assert::same('/index.php?action=defaults&presenter=Test', $this->link('defaults', ['int' => '1', 'bool' => '1', 'str' => 'a', 'arr' => [1]])); Assert::same(['int' => null, 'bool' => null, 'str' => null, 'arr' => null, 'pint' => null, 'parr' => null, 'pbool' => null, 'action' => 'defaults'], $this->getLastCreatedRequest()->getParameters()); Assert::same('/index.php?int=0&bool=0&str=&action=defaults&presenter=Test', $this->link('defaults', ['int' => 0, 'bool' => false, 'str' => '', 'arr' => []])); - Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be integer, string given.', $this->link('defaults', ['int' => ''])); - Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be integer, array given.', $this->link('defaults', ['int' => []])); - Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be integer, stdClass given.', $this->link('defaults', ['int' => new stdClass])); - Assert::same('#error: Argument $bool passed to TestPresenter::actionDefaults() must be boolean, string given.', $this->link('defaults', ['int' => '1', 'bool' => ''])); + Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be int, string given.', $this->link('defaults', ['int' => ''])); + Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be int, array given.', $this->link('defaults', ['int' => []])); + Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be int, stdClass given.', $this->link('defaults', ['int' => new stdClass])); + Assert::same('#error: Argument $bool passed to TestPresenter::actionDefaults() must be bool, string given.', $this->link('defaults', ['int' => '1', 'bool' => ''])); Assert::same('#error: Argument $arr passed to TestPresenter::actionDefaults() must be array, string given.', $this->link('defaults', ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => ''])); Assert::same('/index.php?action=objects&presenter=Test', $this->link('objects', ['req' => new stdClass, 'nullable' => new stdClass, 'opt' => new stdClass])); @@ -230,7 +230,7 @@ class TestPresenter extends Application\UI\Presenter Assert::error( fn() => $this->link('params', ['p' => null, 'pbool' => 'a']), E_USER_WARNING, - "Invalid link: Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given." + "Invalid link: Value passed to persistent parameter 'pbool' in presenter Test must be bool, string given.", ); // exception invalid link mode @@ -238,7 +238,7 @@ class TestPresenter extends Application\UI\Presenter Assert::exception( fn() => $this->link('params', ['p' => null, 'pbool' => 'a']), Nette\Application\UI\InvalidLinkException::class, - "Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given." + "Value passed to persistent parameter 'pbool' in presenter Test must be bool, string given.", ); $this->p = null; // null in persistent parameter means default diff --git a/tests/UI/Presenter.link().phpt b/tests/UI/Presenter.link().phpt index eb8926058..bf5029852 100644 --- a/tests/UI/Presenter.link().phpt +++ b/tests/UI/Presenter.link().phpt @@ -101,7 +101,7 @@ class TestPresenter extends Application\UI\Presenter Assert::same(['pint' => 20, 'pbool' => null, 'parr' => [1], 'action' => 'params'], $this->getLastCreatedRequest()->getParameters()); Assert::same('/index.php?pint=1&pbool=0&action=params&presenter=Test', $this->link('params', ['pint' => true, 'pbool' => '0', 'parr' => []])); Assert::same('/index.php?pint=0&pbool=0&p=0&action=params&presenter=Test', $this->link('params', ['pint' => false, 'pbool' => false, 'p' => false, 'parr' => null])); - Assert::same("#error: Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given.", $this->link('this', ['p' => null, 'pbool' => 'a'])); + Assert::same("#error: Value passed to persistent parameter 'pbool' in presenter Test must be bool, string given.", $this->link('this', ['p' => null, 'pbool' => 'a'])); Assert::same("#error: Value passed to persistent parameter 'p' in presenter Test must be scalar, array given.", $this->link('this', ['p' => [1], 'pbool' => false])); Assert::same('/index.php?action=persistent&presenter=Test', $this->link('persistent')); @@ -134,10 +134,10 @@ class TestPresenter extends Application\UI\Presenter Assert::same(['mycontrol-x' => 1, 'mycontrol-y' => 2, 'mycontrol-round' => null, 'mycontrol-order' => null, 'pint' => null, 'parr' => null, 'pbool' => null, 'action' => 'default', 'do' => 'mycontrol-click'], $this->getLastCreatedRequest()->getParameters()); // Component link type checking - Assert::same("#error: Value passed to persistent parameter 'order' in component 'mycontrol' must be array, integer given.", $this['mycontrol']->link('click', ['order' => 1])); - Assert::same("#error: Value passed to persistent parameter 'round' in component 'mycontrol' must be integer, array given.", $this['mycontrol']->link('click', ['round' => []])); + Assert::same("#error: Value passed to persistent parameter 'order' in component 'mycontrol' must be array, int given.", $this['mycontrol']->link('click', ['order' => 1])); + Assert::same("#error: Value passed to persistent parameter 'round' in component 'mycontrol' must be int, array given.", $this['mycontrol']->link('click', ['round' => []])); $this['mycontrol']->order = 1; - Assert::same("#error: Value passed to persistent parameter 'order' in component 'mycontrol' must be array, integer given.", $this['mycontrol']->link('click')); + Assert::same("#error: Value passed to persistent parameter 'order' in component 'mycontrol' must be array, int given.", $this['mycontrol']->link('click')); $this['mycontrol']->order = null; // type checking @@ -195,10 +195,10 @@ class TestPresenter extends Application\UI\Presenter Assert::same('/index.php?action=defaults&presenter=Test', $this->link('defaults', ['int' => '1', 'bool' => '1', 'str' => 'a', 'arr' => [1]])); Assert::same(['int' => null, 'bool' => null, 'str' => null, 'arr' => null, 'pint' => null, 'parr' => null, 'pbool' => null, 'action' => 'defaults'], $this->getLastCreatedRequest()->getParameters()); Assert::same('/index.php?int=0&bool=0&str=&action=defaults&presenter=Test', $this->link('defaults', ['int' => 0, 'bool' => false, 'str' => '', 'arr' => []])); - Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be integer, string given.', $this->link('defaults', ['int' => ''])); - Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be integer, array given.', $this->link('defaults', ['int' => []])); - Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be integer, stdClass given.', $this->link('defaults', ['int' => new stdClass])); - Assert::same('#error: Argument $bool passed to TestPresenter::actionDefaults() must be boolean, string given.', $this->link('defaults', ['int' => '1', 'bool' => ''])); + Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be int, string given.', $this->link('defaults', ['int' => ''])); + Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be int, array given.', $this->link('defaults', ['int' => []])); + Assert::same('#error: Argument $int passed to TestPresenter::actionDefaults() must be int, stdClass given.', $this->link('defaults', ['int' => new stdClass])); + Assert::same('#error: Argument $bool passed to TestPresenter::actionDefaults() must be bool, string given.', $this->link('defaults', ['int' => '1', 'bool' => ''])); Assert::same('#error: Argument $arr passed to TestPresenter::actionDefaults() must be array, string given.', $this->link('defaults', ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => ''])); Assert::same('/index.php?action=objects&presenter=Test', $this->link('objects', ['req' => new stdClass, 'nullable' => new stdClass, 'opt' => new stdClass])); @@ -216,7 +216,7 @@ class TestPresenter extends Application\UI\Presenter Assert::error( fn() => $this->link('params', ['p' => null, 'pbool' => 'a']), E_USER_WARNING, - "Invalid link: Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given." + "Invalid link: Value passed to persistent parameter 'pbool' in presenter Test must be bool, string given.", ); // exception invalid link mode @@ -224,7 +224,7 @@ class TestPresenter extends Application\UI\Presenter Assert::exception( fn() => $this->link('params', ['p' => null, 'pbool' => 'a']), Nette\Application\UI\InvalidLinkException::class, - "Value passed to persistent parameter 'pbool' in presenter Test must be boolean, string given." + "Value passed to persistent parameter 'pbool' in presenter Test must be bool, string given.", ); $this->p = null; // null in persistent parameter means default diff --git a/tests/UI/Presenter.paramChecking.phpt b/tests/UI/Presenter.paramChecking.phpt index 0eb443e86..b05fc6037 100644 --- a/tests/UI/Presenter.paramChecking.phpt +++ b/tests/UI/Presenter.paramChecking.phpt @@ -52,39 +52,39 @@ Assert::exception(function () use ($presenter) { Assert::exception(function () use ($presenter) { $request = new Application\Request('Test', Http\Request::GET, ['c' => 1]); $presenter->run($request); -}, Nette\Application\BadRequestException::class, 'Argument $c passed to ParamPresenter::actionDefault() must be array, integer given.'); +}, Nette\Application\BadRequestException::class, 'Argument $c passed to ParamPresenter::actionDefault() must be array, int given.'); Assert::exception(function () use ($presenter) { $request = new Application\Request('Test', Http\Request::GET, ['d' => 1]); $presenter->run($request); -}, Nette\Application\BadRequestException::class, 'Argument $d passed to ParamPresenter::actionDefault() must be array, integer given.'); +}, Nette\Application\BadRequestException::class, 'Argument $d passed to ParamPresenter::actionDefault() must be array, int given.'); Assert::exception(function () use ($presenter) { $request = new Application\Request('Test', Http\Request::GET, ['e' => 1.1]); $presenter->run($request); -}, Nette\Application\BadRequestException::class, 'Argument $e passed to ParamPresenter::actionDefault() must be integer, double given.'); +}, Nette\Application\BadRequestException::class, 'Argument $e passed to ParamPresenter::actionDefault() must be int, float given.'); Assert::exception(function () use ($presenter) { $request = new Application\Request('Test', Http\Request::GET, ['e' => '1 ']); $presenter->run($request); -}, Nette\Application\BadRequestException::class, 'Argument $e passed to ParamPresenter::actionDefault() must be integer, string given.'); +}, Nette\Application\BadRequestException::class, 'Argument $e passed to ParamPresenter::actionDefault() must be int, string given.'); Assert::exception(function () use ($presenter) { $request = new Application\Request('Test', Http\Request::GET, ['f' => '1 ']); $presenter->run($request); -}, Nette\Application\BadRequestException::class, 'Argument $f passed to ParamPresenter::actionDefault() must be double, string given.'); +}, Nette\Application\BadRequestException::class, 'Argument $f passed to ParamPresenter::actionDefault() must be float, string given.'); Assert::exception(function () use ($presenter) { $request = new Application\Request('Test', Http\Request::GET, ['g' => '']); $presenter->run($request); -}, Nette\Application\BadRequestException::class, 'Argument $g passed to ParamPresenter::actionDefault() must be boolean, string given.'); +}, Nette\Application\BadRequestException::class, 'Argument $g passed to ParamPresenter::actionDefault() must be bool, string given.'); Assert::exception(function () use ($presenter) { $request = new Application\Request('Test', Http\Request::GET, ['bool' => []]); $presenter->run($request); -}, Nette\Application\BadRequestException::class, "Value passed to persistent parameter 'bool' in presenter Test must be boolean, array given."); +}, Nette\Application\BadRequestException::class, "Value passed to persistent parameter 'bool' in presenter Test must be bool, array given."); From 84458622db41a1423f048d7652930ee12cd4d509 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 27 Nov 2022 22:29:14 +0100 Subject: [PATCH 16/42] uses PascalCase constants --- .phpstorm.meta.php | 72 +++++++++---------- src/Application/MicroPresenter.php | 6 +- .../Responses/RedirectResponse.php | 2 +- src/Application/Routers/Route.php | 26 +++---- src/Application/UI/Component.php | 6 +- src/Application/UI/Form.php | 2 +- src/Application/UI/Presenter.php | 18 ++--- src/Application/exceptions.php | 4 +- .../ApplicationDI/ApplicationExtension.php | 2 +- tests/Application/Presenter.twoDomains.phpt | 2 +- tests/Routers/Route.filter.global.phpt | 8 +-- tests/Routers/Route.filter.query.phpt | 4 +- tests/Routers/Route.filter.url.object.phpt | 4 +- tests/Routers/Route.filter.url.phpt | 4 +- tests/Routers/Route.filterTable.query.phpt | 2 +- tests/Routers/Route.filterTable.strict.phpt | 4 +- tests/Routers/Route.filterTable.url.phpt | 2 +- tests/Routers/Route.urlEncoding.phpt | 2 +- tests/Routers/Route.withUserClassAlt.phpt | 2 +- .../UI/Component.isLinkCurrent().asserts.php | 58 +++++++-------- tests/UI/Form.phpt | 2 +- tests/UI/Presenter.link().persistent.phpt | 2 +- tests/UI/Presenter.link().php74.phpt | 2 +- tests/UI/Presenter.link().phpt | 2 +- tests/UI/Presenter.paramChecking.phpt | 22 +++--- 25 files changed, 130 insertions(+), 130 deletions(-) diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index af319c059..3c0ac5638 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -8,44 +8,44 @@ expectedArguments(\Nette\Application\Routers\SimpleRouter::__construct(), 1, \Nette\Routing\Router::ONE_WAY); registerArgumentsSet('nette_http_codes_3xx', - \Nette\Http\IResponse::S300_MULTIPLE_CHOICES, - \Nette\Http\IResponse::S301_MOVED_PERMANENTLY, - \Nette\Http\IResponse::S302_FOUND, - \Nette\Http\IResponse::S303_SEE_OTHER, - \Nette\Http\IResponse::S303_POST_GET, - \Nette\Http\IResponse::S304_NOT_MODIFIED, - \Nette\Http\IResponse::S305_USE_PROXY, - \Nette\Http\IResponse::S307_TEMPORARY_REDIRECT, - \Nette\Http\IResponse::S308_PERMANENT_REDIRECT, + \Nette\Http\IResponse::S300_MultipleChoices, + \Nette\Http\IResponse::S301_MovedPermanently, + \Nette\Http\IResponse::S302_Found, + \Nette\Http\IResponse::S303_SeeOther, + \Nette\Http\IResponse::S303_PostGet, + \Nette\Http\IResponse::S304_NotModified, + \Nette\Http\IResponse::S305_UseProxy, + \Nette\Http\IResponse::S307_TemporaryRedirect, + \Nette\Http\IResponse::S308_PermanentRedirect, ); registerArgumentsSet('nette_http_codes_4xx', - \Nette\Http\IResponse::S400_BAD_REQUEST, - \Nette\Http\IResponse::S401_UNAUTHORIZED, - \Nette\Http\IResponse::S402_PAYMENT_REQUIRED, - \Nette\Http\IResponse::S403_FORBIDDEN, - \Nette\Http\IResponse::S404_NOT_FOUND, - \Nette\Http\IResponse::S405_METHOD_NOT_ALLOWED, - \Nette\Http\IResponse::S406_NOT_ACCEPTABLE, - \Nette\Http\IResponse::S407_PROXY_AUTHENTICATION_REQUIRED, - \Nette\Http\IResponse::S408_REQUEST_TIMEOUT, - \Nette\Http\IResponse::S409_CONFLICT, - \Nette\Http\IResponse::S410_GONE, - \Nette\Http\IResponse::S411_LENGTH_REQUIRED, - \Nette\Http\IResponse::S412_PRECONDITION_FAILED, - \Nette\Http\IResponse::S413_REQUEST_ENTITY_TOO_LARGE, - \Nette\Http\IResponse::S414_REQUEST_URI_TOO_LONG, - \Nette\Http\IResponse::S415_UNSUPPORTED_MEDIA_TYPE, - \Nette\Http\IResponse::S416_REQUESTED_RANGE_NOT_SATISFIABLE, - \Nette\Http\IResponse::S417_EXPECTATION_FAILED, - \Nette\Http\IResponse::S421_MISDIRECTED_REQUEST, - \Nette\Http\IResponse::S422_UNPROCESSABLE_ENTITY, - \Nette\Http\IResponse::S423_LOCKED, - \Nette\Http\IResponse::S424_FAILED_DEPENDENCY, - \Nette\Http\IResponse::S426_UPGRADE_REQUIRED, - \Nette\Http\IResponse::S428_PRECONDITION_REQUIRED, - \Nette\Http\IResponse::S429_TOO_MANY_REQUESTS, - \Nette\Http\IResponse::S431_REQUEST_HEADER_FIELDS_TOO_LARGE, - \Nette\Http\IResponse::S451_UNAVAILABLE_FOR_LEGAL_REASONS, + \Nette\Http\IResponse::S400_BadRequest, + \Nette\Http\IResponse::S401_Unauthorized, + \Nette\Http\IResponse::S402_PaymentRequired, + \Nette\Http\IResponse::S403_Forbidden, + \Nette\Http\IResponse::S404_NotFound, + \Nette\Http\IResponse::S405_MethodNotAllowed, + \Nette\Http\IResponse::S406_NotAcceptable, + \Nette\Http\IResponse::S407_ProxyAuthenticationRequired, + \Nette\Http\IResponse::S408_RequestTimeout, + \Nette\Http\IResponse::S409_Conflict, + \Nette\Http\IResponse::S410_Gone, + \Nette\Http\IResponse::S411_LengthRequired, + \Nette\Http\IResponse::S412_PreconditionFailed, + \Nette\Http\IResponse::S413_RequestEntityTooLarge, + \Nette\Http\IResponse::S414_RequestUriTooLong, + \Nette\Http\IResponse::S415_UnsupportedMediaType, + \Nette\Http\IResponse::S416_RequestedRangeNotSatisfiable, + \Nette\Http\IResponse::S417_ExpectationFailed, + \Nette\Http\IResponse::S421_MisdirectedRequest, + \Nette\Http\IResponse::S422_UnprocessableEntity, + \Nette\Http\IResponse::S423_Locked, + \Nette\Http\IResponse::S424_FailedDependency, + \Nette\Http\IResponse::S426_UpgradeRequired, + \Nette\Http\IResponse::S428_PreconditionRequired, + \Nette\Http\IResponse::S429_TooManyRequests, + \Nette\Http\IResponse::S431_RequestHeaderFieldsTooLarge, + \Nette\Http\IResponse::S451_UnavailableForLegalReasons, ); expectedArguments(\Nette\Application\UI\Presenter::redirectUrl(), 1, argumentsSet('nette_http_codes_3xx')); diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 24426e0f1..1a6bce66c 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -57,7 +57,7 @@ public function run(Application\Request $request): Application\Response $refUrl = $this->httpRequest->getUrl()->withoutUserInfo(); $url = $this->router->constructUrl($request->toArray(), $refUrl); if ($url !== null && !$refUrl->isEqual($url)) { - return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY); + return new Responses\RedirectResponse($url, Http\IResponse::S301_MovedPermanently); } } @@ -137,7 +137,7 @@ public function createTemplate(?string $class = null, ?callable $latteFactory = /** * Redirects to another URL. */ - public function redirectUrl(string $url, int $httpCode = Http\IResponse::S302_FOUND): Responses\RedirectResponse + public function redirectUrl(string $url, int $httpCode = Http\IResponse::S302_Found): Responses\RedirectResponse { return new Responses\RedirectResponse($url, $httpCode); } @@ -147,7 +147,7 @@ public function redirectUrl(string $url, int $httpCode = Http\IResponse::S302_FO * Throws HTTP error. * @throws Nette\Application\BadRequestException */ - public function error(string $message = '', int $httpCode = Http\IResponse::S404_NOT_FOUND): void + public function error(string $message = '', int $httpCode = Http\IResponse::S404_NotFound): void { throw new Application\BadRequestException($message, $httpCode); } diff --git a/src/Application/Responses/RedirectResponse.php b/src/Application/Responses/RedirectResponse.php index fda1a378a..7fbbe01fa 100644 --- a/src/Application/Responses/RedirectResponse.php +++ b/src/Application/Responses/RedirectResponse.php @@ -25,7 +25,7 @@ final class RedirectResponse implements Nette\Application\Response private int $httpCode; - public function __construct(string $url, int $httpCode = Http\IResponse::S302_FOUND) + public function __construct(string $url, int $httpCode = Http\IResponse::S302_Found) { $this->url = $url; $this->httpCode = $httpCode; diff --git a/src/Application/Routers/Route.php b/src/Application/Routers/Route.php index 971689c70..ba611da0e 100644 --- a/src/Application/Routers/Route.php +++ b/src/Application/Routers/Route.php @@ -24,19 +24,19 @@ class Route extends Nette\Routing\Route implements Nette\Routing\Router private const UIMeta = [ 'module' => [ - self::PATTERN => '[a-z][a-z0-9.-]*', - self::FILTER_IN => [self::class, 'path2presenter'], - self::FILTER_OUT => [self::class, 'presenter2path'], + self::Pattern => '[a-z][a-z0-9.-]*', + self::FilterIn => [self::class, 'path2presenter'], + self::FilterOut => [self::class, 'presenter2path'], ], 'presenter' => [ - self::PATTERN => '[a-z][a-z0-9.-]*', - self::FILTER_IN => [self::class, 'path2presenter'], - self::FILTER_OUT => [self::class, 'presenter2path'], + self::Pattern => '[a-z][a-z0-9.-]*', + self::FilterIn => [self::class, 'path2presenter'], + self::FilterOut => [self::class, 'presenter2path'], ], 'action' => [ - self::PATTERN => '[a-z][a-z0-9-]*', - self::FILTER_IN => [self::class, 'path2action'], - self::FILTER_OUT => [self::class, 'action2path'], + self::Pattern => '[a-z][a-z0-9-]*', + self::FilterIn => [self::class, 'path2action'], + self::FilterOut => [self::class, 'action2path'], ], ]; @@ -104,12 +104,12 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri if (isset($metadata[self::ModuleKey])) { // try split into module and [submodule:]presenter parts $presenter = $params[self::PresenterKey]; $module = $metadata[self::ModuleKey]; - $a = isset($module['fixity'], $module[self::VALUE]) - && strncmp($presenter, $module[self::VALUE] . ':', strlen($module[self::VALUE]) + 1) === 0 - ? strlen($module[self::VALUE]) + $a = isset($module['fixity'], $module[self::Value]) + && strncmp($presenter, $module[self::Value] . ':', strlen($module[self::Value]) + 1) === 0 + ? strlen($module[self::Value]) : strrpos($presenter, ':'); if ($a === false) { - $params[self::ModuleKey] = isset($module[self::VALUE]) ? '' : null; + $params[self::ModuleKey] = isset($module[self::Value]) ? '' : null; } else { $params[self::ModuleKey] = substr($presenter, 0, $a); $params[self::PresenterKey] = substr($presenter, $a + 1); diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index a02e6468f..3dd972ac1 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -206,7 +206,7 @@ final public function getParameters(): array final public function getParameterId(string $name): string { $uid = $this->getUniqueId(); - return $uid === '' ? $name : $uid . self::NAME_SEPARATOR . $name; + return $uid === '' ? $name : $uid . self::NameSeparator . $name; } @@ -323,7 +323,7 @@ public function redirectPermanent(string $destination, $args = []): void $presenter = $this->getPresenter(); $presenter->redirectUrl( $presenter->createRequest($this, $destination, $args, 'redirect'), - Nette\Http\IResponse::S301_MOVED_PERMANENTLY, + Nette\Http\IResponse::S301_MovedPermanently, ); } @@ -332,7 +332,7 @@ public function redirectPermanent(string $destination, $args = []): void * Throws HTTP error. * @throws Nette\Application\BadRequestException */ - public function error(string $message = '', int $httpCode = Nette\Http\IResponse::S404_NOT_FOUND): void + public function error(string $message = '', int $httpCode = Nette\Http\IResponse::S404_NotFound): void { throw new Nette\Application\BadRequestException($message, $httpCode); } diff --git a/src/Application/UI/Form.php b/src/Application/UI/Form.php index 0a4455b15..36a6199b3 100644 --- a/src/Application/UI/Form.php +++ b/src/Application/UI/Form.php @@ -138,7 +138,7 @@ protected function beforeRender() parent::beforeRender(); $key = ($this->isMethod('post') ? '_' : '') . Presenter::SignalKey; if (!isset($this[$key])) { - $do = $this->lookupPath(Presenter::class) . self::NAME_SEPARATOR . 'submit'; + $do = $this->lookupPath(Presenter::class) . self::NameSeparator . 'submit'; $this[$key] = (new Nette\Forms\Controls\HiddenField($do))->setOmitted(); } } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 46ab07999..0a46d2599 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -649,8 +649,8 @@ public function redirectUrl(string $url, ?int $httpCode = null): void } elseif (!$httpCode) { $httpCode = $this->httpRequest->isMethod('post') - ? Http\IResponse::S303_POST_GET - : Http\IResponse::S302_FOUND; + ? Http\IResponse::S303_PostGet + : Http\IResponse::S302_Found; } $this->sendResponse(new Responses\RedirectResponse($url, $httpCode)); @@ -707,8 +707,8 @@ public function canonicalize(?string $destination = null, ...$args): void } $code = $request->hasFlag($request::VARYING) - ? Http\IResponse::S302_FOUND - : Http\IResponse::S301_MOVED_PERMANENTLY; + ? Http\IResponse::S302_Found + : Http\IResponse::S301_MovedPermanently; $this->sendResponse(new Responses\RedirectResponse($url, $code)); } @@ -808,7 +808,7 @@ protected function createRequest( if (array_key_exists(0, $args)) { throw new InvalidLinkException("Unable to pass parameters to 'this!' signal."); } - } elseif (!str_contains($signal, self::NAME_SEPARATOR)) { + } elseif (!str_contains($signal, self::NameSeparator)) { // counterpart of signalReceived() & tryCall() $method = $component->formatSignalMethod($signal); if (!$reflection->hasCallableMethod($method)) { @@ -832,7 +832,7 @@ protected function createRequest( } if ($args && $component !== $this) { - $prefix = $component->getUniqueId() . self::NAME_SEPARATOR; + $prefix = $component->getUniqueId() . self::NameSeparator; foreach ($args as $key => $val) { unset($args[$key]); $args[$prefix . $key] = $val; @@ -1150,7 +1150,7 @@ protected function getGlobalState(?string $forClass = null): array if (!isset($this->globalState)) { $state = []; foreach ($this->globalParams as $id => $params) { - $prefix = $id . self::NAME_SEPARATOR; + $prefix = $id . self::NameSeparator; foreach ($params as $key => $val) { $state[$prefix . $key] = $val; } @@ -1178,7 +1178,7 @@ protected function getGlobalState(?string $forClass = null): array continue; } - $prefix = $component->getUniqueId() . self::NAME_SEPARATOR; + $prefix = $component->getUniqueId() . self::NameSeparator; $params = []; $component->saveState($params); foreach ($params as $key => $val) { @@ -1195,7 +1195,7 @@ protected function getGlobalState(?string $forClass = null): array $since = null; foreach ($state as $key => $foo) { if (!isset($sinces[$key])) { - $x = strpos($key, self::NAME_SEPARATOR); + $x = strpos($key, self::NameSeparator); $x = $x === false ? $key : substr($key, 0, $x); $sinces[$key] = $sinces[$x] ?? false; } diff --git a/src/Application/exceptions.php b/src/Application/exceptions.php index 3ada5038b..1a010742a 100644 --- a/src/Application/exceptions.php +++ b/src/Application/exceptions.php @@ -42,7 +42,7 @@ class InvalidPresenterException extends \Exception */ class BadRequestException extends \Exception { - protected $code = Http\IResponse::S404_NOT_FOUND; + protected $code = Http\IResponse::S404_NotFound; public function __construct(string $message = '', int $httpCode = 0, ?\Throwable $previous = null) @@ -63,5 +63,5 @@ public function getHttpCode(): int */ class ForbiddenRequestException extends BadRequestException { - protected $code = Http\IResponse::S403_FORBIDDEN; + protected $code = Http\IResponse::S403_Forbidden; } diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index 8250806ea..2c4734e45 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -125,7 +125,7 @@ public function beforeCompile() } foreach ($all as $def) { - $def->addTag(Nette\DI\Extensions\InjectExtension::TAG_INJECT) + $def->addTag(Nette\DI\Extensions\InjectExtension::TagInject) ->setAutowired(false); if (is_subclass_of($def->getType(), UI\Presenter::class) && $def instanceof Definitions\ServiceDefinition) { diff --git a/tests/Application/Presenter.twoDomains.phpt b/tests/Application/Presenter.twoDomains.phpt index 78df3898b..46943d99c 100644 --- a/tests/Application/Presenter.twoDomains.phpt +++ b/tests/Application/Presenter.twoDomains.phpt @@ -35,7 +35,7 @@ function testLink($domain) new Http\Response, ); - $request = new Application\Request('Test', Http\Request::GET, []); + $request = new Application\Request('Test', Http\Request::Get, []); $presenter->run($request); Assert::same('http://' . $domain . '/index.php?action=default&presenter=Test', $presenter->link('//this')); diff --git a/tests/Routers/Route.filter.global.phpt b/tests/Routers/Route.filter.global.phpt index 660017f95..04acda535 100644 --- a/tests/Routers/Route.filter.global.phpt +++ b/tests/Routers/Route.filter.global.phpt @@ -17,7 +17,7 @@ require __DIR__ . '/Route.php'; $route = new Route('', [ null => [ - Route::FILTER_IN => function (array $arr) { + Route::FilterIn => function (array $arr) { if (substr($arr['presenter'], 0, 3) !== 'Abc') { return null; } @@ -26,7 +26,7 @@ $route = new Route('', [ $arr['param'] .= '.in'; return $arr; }, - Route::FILTER_OUT => function (array $arr) { + Route::FilterOut => function (array $arr) { if (substr($arr['presenter'], 0, 3) !== 'Abc') { return null; } @@ -51,7 +51,7 @@ Assert::null(testRouteOut($route, ['presenter' => 'Cde'])); $route = new Route('//', [ null => [ - Route::FILTER_IN => function (array $arr) { + Route::FilterIn => function (array $arr) { if ($arr['presenter'] !== 'AbcCs') { return null; } @@ -60,7 +60,7 @@ $route = new Route('//', [ $arr['action'] = substr($arr['action'], 0, -2); return $arr; }, - Route::FILTER_OUT => function (array $arr) { + Route::FilterOut => function (array $arr) { if ($arr['presenter'] !== 'Abc') { return null; } diff --git a/tests/Routers/Route.filter.query.phpt b/tests/Routers/Route.filter.query.phpt index eb2aae981..45645f458 100644 --- a/tests/Routers/Route.filter.query.phpt +++ b/tests/Routers/Route.filter.query.phpt @@ -16,8 +16,8 @@ require __DIR__ . '/Route.php'; $route = new Route(' ? action=', [ 'presenter' => [ - Route::FILTER_IN => fn($s) => strrev($s), - Route::FILTER_OUT => fn($s) => strtoupper(strrev($s)), + Route::FilterIn => fn($s) => strrev($s), + Route::FilterOut => fn($s) => strtoupper(strrev($s)), ], ]); diff --git a/tests/Routers/Route.filter.url.object.phpt b/tests/Routers/Route.filter.url.object.phpt index 39a30a13a..1789c388e 100644 --- a/tests/Routers/Route.filter.url.object.phpt +++ b/tests/Routers/Route.filter.url.object.phpt @@ -24,8 +24,8 @@ $identityMap[2] = new RouterObject(2); $route = new Route('', [ 'presenter' => 'presenter', 'parameter' => [ - Route::FILTER_IN => fn($s) => $identityMap[$s] ?? null, - Route::FILTER_OUT => fn($obj) => $obj instanceof RouterObject ? $obj->getId() : null, + Route::FilterIn => fn($s) => $identityMap[$s] ?? null, + Route::FilterOut => fn($obj) => $obj instanceof RouterObject ? $obj->getId() : null, ], ]); diff --git a/tests/Routers/Route.filter.url.phpt b/tests/Routers/Route.filter.url.phpt index d96abff62..1d69b564c 100644 --- a/tests/Routers/Route.filter.url.phpt +++ b/tests/Routers/Route.filter.url.phpt @@ -16,8 +16,8 @@ require __DIR__ . '/Route.php'; $route = new Route('', [ 'presenter' => [ - Route::FILTER_IN => fn($s) => strrev($s), - Route::FILTER_OUT => fn($s) => strrev($s), + Route::FilterIn => fn($s) => strrev($s), + Route::FilterOut => fn($s) => strrev($s), ], ]); diff --git a/tests/Routers/Route.filterTable.query.phpt b/tests/Routers/Route.filterTable.query.phpt index eb87cdf18..50bec14d4 100644 --- a/tests/Routers/Route.filterTable.query.phpt +++ b/tests/Routers/Route.filterTable.query.phpt @@ -16,7 +16,7 @@ require __DIR__ . '/Route.php'; $route = new Route(' ? action=', [ 'presenter' => [ - Route::FILTER_TABLE => [ + Route::FilterTable => [ 'produkt' => 'Product', 'kategorie' => 'Category', 'zakaznik' => 'Customer', diff --git a/tests/Routers/Route.filterTable.strict.phpt b/tests/Routers/Route.filterTable.strict.phpt index 99e5b0261..5532a341a 100644 --- a/tests/Routers/Route.filterTable.strict.phpt +++ b/tests/Routers/Route.filterTable.strict.phpt @@ -16,13 +16,13 @@ require __DIR__ . '/Route.php'; $route = new Route('', [ 'presenter' => [ - Route::FILTER_TABLE => [ + Route::FilterTable => [ 'produkt' => 'Product', 'kategorie' => 'Category', 'zakaznik' => 'Customer', 'kosik' => 'Basket', ], - Route::FILTER_STRICT => true, + Route::FilterStrict => true, ], ]); diff --git a/tests/Routers/Route.filterTable.url.phpt b/tests/Routers/Route.filterTable.url.phpt index 71580e8b6..5cda62b43 100644 --- a/tests/Routers/Route.filterTable.url.phpt +++ b/tests/Routers/Route.filterTable.url.phpt @@ -16,7 +16,7 @@ require __DIR__ . '/Route.php'; $route = new Route('', [ 'presenter' => [ - Route::FILTER_TABLE => [ + Route::FilterTable => [ 'produkt' => 'Product', 'kategorie' => 'Category', 'zakaznik' => 'Customer', diff --git a/tests/Routers/Route.urlEncoding.phpt b/tests/Routers/Route.urlEncoding.phpt index 3078d5011..d45bfc02e 100644 --- a/tests/Routers/Route.urlEncoding.phpt +++ b/tests/Routers/Route.urlEncoding.phpt @@ -28,7 +28,7 @@ testRouteIn($route, '/a%3A%25%2Fb', [ $route = new Route('', [ 'presenter' => 'Presenter', 'param' => [ - Route::FILTER_OUT => 'rawurlencode', + Route::FilterOut => 'rawurlencode', ], ]); diff --git a/tests/Routers/Route.withUserClassAlt.phpt b/tests/Routers/Route.withUserClassAlt.phpt index c35e48ab0..db9719183 100644 --- a/tests/Routers/Route.withUserClassAlt.phpt +++ b/tests/Routers/Route.withUserClassAlt.phpt @@ -16,7 +16,7 @@ require __DIR__ . '/Route.php'; $route = new Route('/', [ 'id' => [ - Route::PATTERN => '\d{1,3}', + Route::Pattern => '\d{1,3}', ], ]); diff --git a/tests/UI/Component.isLinkCurrent().asserts.php b/tests/UI/Component.isLinkCurrent().asserts.php index 4c0a1a5ad..54be8d233 100644 --- a/tests/UI/Component.isLinkCurrent().asserts.php +++ b/tests/UI/Component.isLinkCurrent().asserts.php @@ -46,37 +46,37 @@ function callIsComponentLinkCurrent( Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true]), 'Test:default', [], )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true]), 'Test:default', ['int' => 2], )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, [Application\UI\Presenter::ActionKey => 'otherAction']), + new Application\Request('Test', Http\Request::Get, [Application\UI\Presenter::ActionKey => 'otherAction']), 'Test:default', [], )); Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, [Application\UI\Presenter::ActionKey => 'otherAction']), + new Application\Request('Test', Http\Request::Get, [Application\UI\Presenter::ActionKey => 'otherAction']), 'Test:otherAction', [], )); Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true]), 'Test:default', ['bool' => true], )); Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true]), 'Test:default', [ 'bool' => true, @@ -85,7 +85,7 @@ function callIsComponentLinkCurrent( )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true]), 'Test:default', [ 'bool' => false, @@ -94,7 +94,7 @@ function callIsComponentLinkCurrent( )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true]), 'Test:default', [ 'bool' => false, @@ -103,7 +103,7 @@ function callIsComponentLinkCurrent( )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true, Application\UI\Presenter::ActionKey => 'otherAction']), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true, Application\UI\Presenter::ActionKey => 'otherAction']), 'Test:default', [ 'bool' => true, @@ -112,7 +112,7 @@ function callIsComponentLinkCurrent( )); Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true, Application\UI\Presenter::ActionKey => 'otherAction']), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true, Application\UI\Presenter::ActionKey => 'otherAction']), 'Test:otherAction', [ 'bool' => true, @@ -121,31 +121,31 @@ function callIsComponentLinkCurrent( )); Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true]), 'Test:*', [], )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true]), 'Test:*', ['float' => 1.0], )); Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true, 'float' => 1.0]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true, 'float' => 1.0]), 'Test:*', ['float' => 1.0], )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true, 'float' => 1.0]), + new Application\Request('Test', Http\Request::Get, ['int' => 1, 'bool' => true, 'float' => 1.0]), 'Test:*', ['float' => 2.0], )); Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 1, Application\UI\Presenter::ActionKey => 'otherAction']), + new Application\Request('Test', Http\Request::Get, ['int' => 1, Application\UI\Presenter::ActionKey => 'otherAction']), 'Test:*', [ 'int' => 1, @@ -153,7 +153,7 @@ function callIsComponentLinkCurrent( )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, ['int' => 2, Application\UI\Presenter::ActionKey => 'otherAction']), + new Application\Request('Test', Http\Request::Get, ['int' => 2, Application\UI\Presenter::ActionKey => 'otherAction']), 'Test:*', [ 'int' => 1, @@ -161,7 +161,7 @@ function callIsComponentLinkCurrent( )); Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'signal', 'int' => 1, 'bool' => true, @@ -171,7 +171,7 @@ function callIsComponentLinkCurrent( )); Assert::true(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'signal', 'int' => 1, 'bool' => true, @@ -181,7 +181,7 @@ function callIsComponentLinkCurrent( )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'signal', 'int' => 1, 'bool' => true, @@ -193,7 +193,7 @@ function callIsComponentLinkCurrent( // conflicting action in destination string and args Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::ActionKey => 'default', 'int' => 1, 'bool' => true, @@ -205,7 +205,7 @@ function callIsComponentLinkCurrent( )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::ActionKey => 'default', 'int' => 1, 'bool' => true, @@ -219,7 +219,7 @@ function callIsComponentLinkCurrent( // conflicting signal in destination string and args Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'signal', 'int' => 1, 'bool' => true, @@ -231,7 +231,7 @@ function callIsComponentLinkCurrent( )); Assert::false(callIsLinkCurrent( - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'signal', 'int' => 1, 'bool' => true, @@ -250,7 +250,7 @@ function callIsComponentLinkCurrent( Assert::true(callIsComponentLinkCurrent( $testPresenter, $testControl, - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'test-click', 'int' => 1, 'bool' => true, @@ -265,7 +265,7 @@ function callIsComponentLinkCurrent( Assert::false(callIsComponentLinkCurrent( $testPresenter, $testControl, - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'test-click', 'int' => 1, 'bool' => true, @@ -280,7 +280,7 @@ function callIsComponentLinkCurrent( Assert::true(callIsComponentLinkCurrent( $testPresenter, $testControl, - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'test-click', 'int' => 1, 'bool' => true, @@ -298,7 +298,7 @@ function callIsComponentLinkCurrent( Assert::false(callIsComponentLinkCurrent( $testPresenter, $testControl, - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'test-click', 'int' => 1, 'bool' => true, @@ -317,7 +317,7 @@ function callIsComponentLinkCurrent( Assert::true(callIsComponentLinkCurrent( $testPresenter, $testControlWithAnotherTestControl, - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'test-test-click', 'int' => 1, 'bool' => true, @@ -336,7 +336,7 @@ function callIsComponentLinkCurrent( Assert::false(callIsComponentLinkCurrent( $testPresenter, $testControlWithAnotherTestControl, - new Application\Request('Test', Http\Request::GET, [ + new Application\Request('Test', Http\Request::Get, [ Application\UI\Presenter::SignalKey => 'test-test-click', 'int' => 1, 'bool' => true, diff --git a/tests/UI/Form.phpt b/tests/UI/Form.phpt index 9f4541565..66c8ef39b 100644 --- a/tests/UI/Form.phpt +++ b/tests/UI/Form.phpt @@ -21,7 +21,7 @@ class TestPresenter extends UI\Presenter test('', function () { $presenter = new TestPresenter; $form = new UI\Form($presenter, 'name'); - $form->setMethod($form::GET); // must not throw exception + $form->setMethod($form::Get); // must not throw exception }); diff --git a/tests/UI/Presenter.link().persistent.phpt b/tests/UI/Presenter.link().persistent.phpt index 54f0bb2c9..8bf8e73c0 100644 --- a/tests/UI/Presenter.link().persistent.phpt +++ b/tests/UI/Presenter.link().persistent.phpt @@ -152,5 +152,5 @@ $presenter->injectPrimary( $presenter->invalidLinkMode = TestPresenter::InvalidLinkWarning; $presenter->autoCanonicalize = false; -$request = new Application\Request('Test', Http\Request::GET, []); +$request = new Application\Request('Test', Http\Request::Get, []); $presenter->run($request); diff --git a/tests/UI/Presenter.link().php74.phpt b/tests/UI/Presenter.link().php74.phpt index 67419df3c..a48cae932 100644 --- a/tests/UI/Presenter.link().php74.phpt +++ b/tests/UI/Presenter.link().php74.phpt @@ -318,5 +318,5 @@ $presenter->injectPrimary( $presenter->invalidLinkMode = TestPresenter::InvalidLinkWarning; $presenter->autoCanonicalize = false; -$request = new Application\Request('Test', Http\Request::GET, []); +$request = new Application\Request('Test', Http\Request::Get, []); $presenter->run($request); diff --git a/tests/UI/Presenter.link().phpt b/tests/UI/Presenter.link().phpt index bf5029852..0d1993ef7 100644 --- a/tests/UI/Presenter.link().phpt +++ b/tests/UI/Presenter.link().phpt @@ -304,5 +304,5 @@ $presenter->injectPrimary( $presenter->invalidLinkMode = TestPresenter::InvalidLinkWarning; $presenter->autoCanonicalize = false; -$request = new Application\Request('Test', Http\Request::GET, []); +$request = new Application\Request('Test', Http\Request::Get, []); $presenter->run($request); diff --git a/tests/UI/Presenter.paramChecking.phpt b/tests/UI/Presenter.paramChecking.phpt index b05fc6037..db14d7baf 100644 --- a/tests/UI/Presenter.paramChecking.phpt +++ b/tests/UI/Presenter.paramChecking.phpt @@ -26,65 +26,65 @@ $presenter->injectPrimary( Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['action' => []]); + $request = new Application\Request('Test', Http\Request::Get, ['action' => []]); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Action name is not valid.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['do' => []]); + $request = new Application\Request('Test', Http\Request::Get, ['do' => []]); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Signal name is not string.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['a' => []]); + $request = new Application\Request('Test', Http\Request::Get, ['a' => []]); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Argument $a passed to ParamPresenter::actionDefault() must be scalar, array given.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['b' => []]); + $request = new Application\Request('Test', Http\Request::Get, ['b' => []]); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Argument $b passed to ParamPresenter::actionDefault() must be scalar, array given.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['c' => 1]); + $request = new Application\Request('Test', Http\Request::Get, ['c' => 1]); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Argument $c passed to ParamPresenter::actionDefault() must be array, int given.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['d' => 1]); + $request = new Application\Request('Test', Http\Request::Get, ['d' => 1]); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Argument $d passed to ParamPresenter::actionDefault() must be array, int given.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['e' => 1.1]); + $request = new Application\Request('Test', Http\Request::Get, ['e' => 1.1]); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Argument $e passed to ParamPresenter::actionDefault() must be int, float given.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['e' => '1 ']); + $request = new Application\Request('Test', Http\Request::Get, ['e' => '1 ']); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Argument $e passed to ParamPresenter::actionDefault() must be int, string given.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['f' => '1 ']); + $request = new Application\Request('Test', Http\Request::Get, ['f' => '1 ']); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Argument $f passed to ParamPresenter::actionDefault() must be float, string given.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['g' => '']); + $request = new Application\Request('Test', Http\Request::Get, ['g' => '']); $presenter->run($request); }, Nette\Application\BadRequestException::class, 'Argument $g passed to ParamPresenter::actionDefault() must be bool, string given.'); Assert::exception(function () use ($presenter) { - $request = new Application\Request('Test', Http\Request::GET, ['bool' => []]); + $request = new Application\Request('Test', Http\Request::Get, ['bool' => []]); $presenter->run($request); }, Nette\Application\BadRequestException::class, "Value passed to persistent parameter 'bool' in presenter Test must be bool, array given."); From 2e69d54a070f0dca349df806446ea688d72a040f Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 29 Aug 2023 14:00:58 +0200 Subject: [PATCH 17/42] removed Nette\SmartObject --- src/Application/Application.php | 2 -- src/Application/ErrorPresenter.php | 3 --- src/Application/LinkGenerator.php | 3 --- src/Application/MicroPresenter.php | 2 -- src/Application/PresenterFactory.php | 2 -- src/Application/Responses/CallbackResponse.php | 2 -- src/Application/Responses/FileResponse.php | 2 -- src/Application/Responses/ForwardResponse.php | 2 -- src/Application/Responses/JsonResponse.php | 2 -- src/Application/Responses/RedirectResponse.php | 2 -- src/Application/Responses/TextResponse.php | 2 -- src/Application/Responses/VoidResponse.php | 2 -- src/Application/Routers/CliRouter.php | 2 -- src/Application/UI/ComponentReflection.php | 2 -- src/Application/UI/Link.php | 4 ---- src/Application/UI/MethodReflection.php | 4 ---- src/Bridges/ApplicationDI/ApplicationExtension.php | 4 ++-- src/Bridges/ApplicationLatte/Nodes/TemplatePrintNode.php | 4 ---- src/Bridges/ApplicationLatte/SnippetDriver.php | 2 -- src/Bridges/ApplicationLatte/TemplateFactory.php | 2 -- src/Bridges/ApplicationTracy/RoutingPanel.php | 2 -- 21 files changed, 2 insertions(+), 50 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index 4d0ac0cd9..2fbde802a 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -19,8 +19,6 @@ */ class Application { - use Nette\SmartObject; - public int $maxLoop = 20; /** enable fault barrier? */ diff --git a/src/Application/ErrorPresenter.php b/src/Application/ErrorPresenter.php index 77f79e4a7..1546af65a 100644 --- a/src/Application/ErrorPresenter.php +++ b/src/Application/ErrorPresenter.php @@ -9,7 +9,6 @@ namespace NetteModule; -use Nette; use Nette\Application; use Nette\Http; use Tracy\ILogger; @@ -20,8 +19,6 @@ */ final class ErrorPresenter implements Application\IPresenter { - use Nette\SmartObject; - public function __construct( private ?ILogger $logger = null, ) { diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index dcf2b9824..a890bf792 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -9,7 +9,6 @@ namespace Nette\Application; -use Nette; use Nette\Http\UrlScript; use Nette\Routing\Router; @@ -19,8 +18,6 @@ */ final class LinkGenerator { - use Nette\SmartObject; - public function __construct( private Router $router, private UrlScript $refUrl, diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 1a6bce66c..64536e743 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -22,8 +22,6 @@ */ final class MicroPresenter implements Application\IPresenter { - use Nette\SmartObject; - private ?Application\Request $request; diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index 674938e2a..fe79020a2 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -17,8 +17,6 @@ */ class PresenterFactory implements IPresenterFactory { - use Nette\SmartObject; - /** @var array[] of module => splited mask */ private array $mapping = [ '*' => ['', '*Module\\', '*Presenter'], diff --git a/src/Application/Responses/CallbackResponse.php b/src/Application/Responses/CallbackResponse.php index 84bc33e88..91a2cc74c 100644 --- a/src/Application/Responses/CallbackResponse.php +++ b/src/Application/Responses/CallbackResponse.php @@ -17,8 +17,6 @@ */ final class CallbackResponse implements Nette\Application\Response { - use Nette\SmartObject; - /** @var callable */ private $callback; diff --git a/src/Application/Responses/FileResponse.php b/src/Application/Responses/FileResponse.php index 2667f7858..e4da97670 100644 --- a/src/Application/Responses/FileResponse.php +++ b/src/Application/Responses/FileResponse.php @@ -17,8 +17,6 @@ */ final class FileResponse implements Nette\Application\Response { - use Nette\SmartObject; - public bool $resuming = true; private string $file; diff --git a/src/Application/Responses/ForwardResponse.php b/src/Application/Responses/ForwardResponse.php index f2ee36e50..9e68c16ca 100644 --- a/src/Application/Responses/ForwardResponse.php +++ b/src/Application/Responses/ForwardResponse.php @@ -17,8 +17,6 @@ */ final class ForwardResponse implements Nette\Application\Response { - use Nette\SmartObject; - private Nette\Application\Request $request; diff --git a/src/Application/Responses/JsonResponse.php b/src/Application/Responses/JsonResponse.php index 0ac3d2512..2f32145c4 100644 --- a/src/Application/Responses/JsonResponse.php +++ b/src/Application/Responses/JsonResponse.php @@ -17,8 +17,6 @@ */ final class JsonResponse implements Nette\Application\Response { - use Nette\SmartObject; - private mixed $payload; private string $contentType; diff --git a/src/Application/Responses/RedirectResponse.php b/src/Application/Responses/RedirectResponse.php index 7fbbe01fa..42f2d19ae 100644 --- a/src/Application/Responses/RedirectResponse.php +++ b/src/Application/Responses/RedirectResponse.php @@ -18,8 +18,6 @@ */ final class RedirectResponse implements Nette\Application\Response { - use Nette\SmartObject; - private string $url; private int $httpCode; diff --git a/src/Application/Responses/TextResponse.php b/src/Application/Responses/TextResponse.php index 439a2b32d..e21fb5168 100644 --- a/src/Application/Responses/TextResponse.php +++ b/src/Application/Responses/TextResponse.php @@ -17,8 +17,6 @@ */ final class TextResponse implements Nette\Application\Response { - use Nette\SmartObject; - private mixed $source; diff --git a/src/Application/Responses/VoidResponse.php b/src/Application/Responses/VoidResponse.php index 05f0ab228..43a6de909 100644 --- a/src/Application/Responses/VoidResponse.php +++ b/src/Application/Responses/VoidResponse.php @@ -17,8 +17,6 @@ */ final class VoidResponse implements Nette\Application\Response { - use Nette\SmartObject; - public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse): void { } diff --git a/src/Application/Routers/CliRouter.php b/src/Application/Routers/CliRouter.php index 225b6624c..ea28f2188 100644 --- a/src/Application/Routers/CliRouter.php +++ b/src/Application/Routers/CliRouter.php @@ -17,8 +17,6 @@ */ final class CliRouter implements Nette\Routing\Router { - use Nette\SmartObject; - private const PresenterKey = 'action'; private array $defaults; diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index bb2fc67b5..c1aadc34c 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -20,8 +20,6 @@ */ final class ComponentReflection extends \ReflectionClass { - use Nette\SmartObject; - /** getPersistentParams cache */ private static array $ppCache = []; diff --git a/src/Application/UI/Link.php b/src/Application/UI/Link.php index 687a331b2..76aeffc15 100644 --- a/src/Application/UI/Link.php +++ b/src/Application/UI/Link.php @@ -9,8 +9,6 @@ namespace Nette\Application\UI; -use Nette; - /** * Lazy encapsulation of Component::link(). @@ -18,8 +16,6 @@ */ final class Link { - use Nette\SmartObject; - private Component $component; private string $destination; diff --git a/src/Application/UI/MethodReflection.php b/src/Application/UI/MethodReflection.php index 6e3c8cba0..f576deeaf 100644 --- a/src/Application/UI/MethodReflection.php +++ b/src/Application/UI/MethodReflection.php @@ -9,16 +9,12 @@ namespace Nette\Application\UI; -use Nette; - /** * @internal */ final class MethodReflection extends \ReflectionMethod { - use Nette\SmartObject; - /** * Has method specified annotation? */ diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index 2c4734e45..c85b04f78 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -206,8 +206,8 @@ public static function initializeBlueScreenPanel( ]; }); if ( - version_compare(Tracy\Debugger::VERSION, '2.9.0', '>=') - && version_compare(Tracy\Debugger::VERSION, '3.0', '<') + version_compare(Tracy\Debugger::Version, '2.9.0', '>=') + && version_compare(Tracy\Debugger::Version, '3.0', '<') ) { $blueScreen->addFileGenerator([self::class, 'generateNewPresenterFileContents']); } diff --git a/src/Bridges/ApplicationLatte/Nodes/TemplatePrintNode.php b/src/Bridges/ApplicationLatte/Nodes/TemplatePrintNode.php index 5ec3a4e5f..a3421d976 100644 --- a/src/Bridges/ApplicationLatte/Nodes/TemplatePrintNode.php +++ b/src/Bridges/ApplicationLatte/Nodes/TemplatePrintNode.php @@ -12,7 +12,6 @@ use Latte; use Latte\Compiler\PhpHelpers; use Latte\Compiler\PrintContext; -use Nette; use Nette\Application\UI\Presenter; use Nette\Bridges\ApplicationLatte\Template; use Nette\PhpGenerator as Php; @@ -55,9 +54,6 @@ public static function printClass(Latte\Runtime\Template $template, ?string $par $namespace = new Php\PhpNamespace(Php\Helpers::extractNamespace($name)); $class = $namespace->addClass(Php\Helpers::extractShortName($name)); $class->setExtends($parent ?: Template::class); - if (!$parent) { - $class->addTrait(Nette\SmartObject::class); - } $blueprint->addProperties($class, $params); $blueprint->addFunctions($class, $funcs); diff --git a/src/Bridges/ApplicationLatte/SnippetDriver.php b/src/Bridges/ApplicationLatte/SnippetDriver.php index 7999db6fd..776c88291 100644 --- a/src/Bridges/ApplicationLatte/SnippetDriver.php +++ b/src/Bridges/ApplicationLatte/SnippetDriver.php @@ -20,8 +20,6 @@ */ final class SnippetDriver { - use Nette\SmartObject; - public const TypeStatic = 'static', TypeDynamic = 'dynamic', diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 252eadc7b..d325603ab 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -19,8 +19,6 @@ */ class TemplateFactory implements UI\TemplateFactory { - use Nette\SmartObject; - /** @var array Occurs when a new template is created */ public array $onCreate = []; private string $templateClass; diff --git a/src/Bridges/ApplicationTracy/RoutingPanel.php b/src/Bridges/ApplicationTracy/RoutingPanel.php index c04a3f50c..01384cdf4 100644 --- a/src/Bridges/ApplicationTracy/RoutingPanel.php +++ b/src/Bridges/ApplicationTracy/RoutingPanel.php @@ -20,8 +20,6 @@ */ final class RoutingPanel implements Tracy\IBarPanel { - use Nette\SmartObject; - private Routing\Router $router; private Nette\Http\IRequest $httpRequest; private Nette\Application\IPresenterFactory $presenterFactory; From f588a480738e0773c851387fdfd1ad41908622cd Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 20:35:50 +0100 Subject: [PATCH 18/42] Control, Presenter::createTemplate has argument --- ncs.xml | 9 --------- src/Application/UI/Control.php | 9 ++------- src/Application/UI/Presenter.php | 6 ++---- 3 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 ncs.xml diff --git a/ncs.xml b/ncs.xml deleted file mode 100644 index 1ffbc8322..000000000 --- a/ncs.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - ./src/Application/UI/Control.php - ./src/Application/UI/Presenter.php - - diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index d03914bf1..91d0ba6b2 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -48,14 +48,9 @@ final public function getTemplate(): Template } - /** - * @param string $class - */ - protected function createTemplate(/*string $class = null*/): Template + protected function createTemplate(?string $class = null): Template { - $class = func_num_args() // back compatibility - ? func_get_arg(0) - : $this->formatTemplateClass(); + $class ??= $this->formatTemplateClass(); $templateFactory = $this->templateFactory ?? $this->getPresenter()->getTemplateFactory(); return $templateFactory->createTemplate($this, $class); } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 0a46d2599..8f6cd94ea 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -529,11 +529,9 @@ public static function formatRenderMethod(string $view): string } - protected function createTemplate(/*string $class = null*/): Template + protected function createTemplate(?string $class = null): Template { - $class = func_num_args() // back compatibility - ? func_get_arg(0) - : $this->formatTemplateClass(); + $class ??= $this->formatTemplateClass(); return $this->getTemplateFactory()->createTemplate($this, $class); } From 9f5cb405aaf5c343347ccee4fe3b268c670f977a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 24 Oct 2022 19:12:55 +0200 Subject: [PATCH 19/42] Revert "UI\PresenterComponent: removed references created by loadState() for persistent parameters. [Closes nette/nette#703]" (possible BC break) This reverts commit cda17f460d020b0f042364d4e140742022a7e94d. See https://forum.nette.org/cs/35528-stejne-pojmenovany-parametr-akce-presenteru-a-persistentni-odlisne-chovani-v-nette-2-0-oproti-aktualnimu#p221742 BC break: Property must be nullable, ie: #[Persistent] public ?int $foo --- src/Application/UI/Component.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 3dd972ac1..ebab30c6f 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -160,9 +160,9 @@ public function loadState(array $params): void )); } - $this->$name = $params[$name]; + $this->$name = &$params[$name]; } else { - $params[$name] = $this->$name ?? null; + $params[$name] = &$this->$name; } } From 2332cea32a1180a5529d6417b0b682822e826444 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 24 Oct 2022 19:16:48 +0200 Subject: [PATCH 20/42] UI\Component: removed references returned by getParameters() [Closes nette/nette#703][Closes #69] --- src/Application/UI/Component.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index ebab30c6f..5ee05b98b 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -196,7 +196,7 @@ final public function getParameter(string $name): mixed */ final public function getParameters(): array { - return $this->params; + return array_map(fn($item) => $item, $this->params); } From b9de486d45b9430e724c4b80aaec44c82c970450 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 21:06:01 +0100 Subject: [PATCH 21/42] Form: $crossOrigin is defined in descendant --- src/Application/UI/Form.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/Application/UI/Form.php b/src/Application/UI/Form.php index 36a6199b3..7f699800d 100644 --- a/src/Application/UI/Form.php +++ b/src/Application/UI/Form.php @@ -20,9 +20,6 @@ class Form extends Nette\Forms\Form implements SignalReceiver /** @var array Occurs when form is attached to presenter */ public array $onAnchor = []; - /** @var bool */ - protected $crossOrigin = false; - /** * Application form constructor. @@ -96,19 +93,10 @@ public function isAnchored(): bool } - /** - * Disables CSRF protection using a SameSite cookie. - */ - public function allowCrossOrigin(): void - { - $this->crossOrigin = true; - } - - /** @deprecated use allowCrossOrigin() */ public function disableSameSiteProtection(): void { - $this->crossOrigin = true; + $this->allowCrossOrigin(); } From d6b41c3fbea666ac60fb95f2b26c3d4fe38bb5ca Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 11 Mar 2021 21:44:34 +0100 Subject: [PATCH 22/42] removed community health files --- .github/ISSUE_TEMPLATE/Bug_report.md | 19 ------------- .github/ISSUE_TEMPLATE/Feature_request.md | 9 ------ .github/ISSUE_TEMPLATE/Support_question.md | 12 -------- .github/ISSUE_TEMPLATE/Support_us.md | 21 -------------- .github/funding.yml | 2 -- .github/pull_request_template.md | 11 -------- contributing.md | 33 ---------------------- 7 files changed, 107 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/Bug_report.md delete mode 100644 .github/ISSUE_TEMPLATE/Feature_request.md delete mode 100644 .github/ISSUE_TEMPLATE/Support_question.md delete mode 100644 .github/ISSUE_TEMPLATE/Support_us.md delete mode 100644 .github/funding.yml delete mode 100644 .github/pull_request_template.md delete mode 100644 contributing.md diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md deleted file mode 100644 index a4cd12634..000000000 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -name: "🐛 Bug Report" -about: "If something isn't working as expected 🤔" - ---- - -Version: ?.?.? - -### Bug Description -... A clear and concise description of what the bug is. A good bug report shouldn't leave others needing to chase you up for more information. - -### Steps To Reproduce -... If possible a minimal demo of the problem ... - -### Expected Behavior -... A clear and concise description of what you expected to happen. - -### Possible Solution -... Only if you have suggestions on a fix for the bug diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md deleted file mode 100644 index d2e219489..000000000 --- a/.github/ISSUE_TEMPLATE/Feature_request.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -name: "🚀 Feature Request" -about: "I have a suggestion (and may want to implement it) 🙂" - ---- - -- Is your feature request related to a problem? Please describe. -- Explain your intentions. -- It's up to you to make a strong case to convince the project's developers of the merits of this feature. diff --git a/.github/ISSUE_TEMPLATE/Support_question.md b/.github/ISSUE_TEMPLATE/Support_question.md deleted file mode 100644 index 75c48b6ed..000000000 --- a/.github/ISSUE_TEMPLATE/Support_question.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: "🤗 Support Question" -about: "If you have a question 💬, please check out our forum!" - ---- - ---------------^ Click "Preview" for a nicer view! -We primarily use GitHub as an issue tracker; for usage and support questions, please check out these resources below. Thanks! 😁. - -* Nette Forum: https://forum.nette.org -* Nette Gitter: https://gitter.im/nette/nette -* Slack (czech): https://pehapkari.slack.com/messages/C2R30BLKA diff --git a/.github/ISSUE_TEMPLATE/Support_us.md b/.github/ISSUE_TEMPLATE/Support_us.md deleted file mode 100644 index 92d8a4c3a..000000000 --- a/.github/ISSUE_TEMPLATE/Support_us.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -name: "❤️ Support us" -about: "If you would like to support our efforts in maintaining this project 🙌" - ---- - ---------------^ Click "Preview" for a nicer view! - -> https://nette.org/donate - -Help support Nette! - -We develop Nette Framework for more than 14 years. In order to make your life more comfortable. Nette cares about the safety of your sites. Nette saves you time. And gives job opportunities. - -Nette earns you money. And is absolutely free. - -To ensure future development and improving the documentation, we need your donation. - -Whether you are chief of IT company which benefits from Nette, or developer who goes for advice on our forum, if you like Nette, [please make a donation now](https://nette.org/donate). - -Thank you! diff --git a/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index 25adc9520..000000000 --- a/.github/funding.yml +++ /dev/null @@ -1,2 +0,0 @@ -github: dg -custom: "https://nette.org/donate" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index f8aa3f408..000000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,11 +0,0 @@ -- bug fix / new feature? -- BC break? yes/no -- doc PR: nette/docs#??? - - diff --git a/contributing.md b/contributing.md deleted file mode 100644 index 184152c02..000000000 --- a/contributing.md +++ /dev/null @@ -1,33 +0,0 @@ -How to contribute & use the issue tracker -========================================= - -Nette welcomes your contributions. There are several ways to help out: - -* Create an issue on GitHub, if you have found a bug -* Write test cases for open bug issues -* Write fixes for open bug/feature issues, preferably with test cases included -* Contribute to the [documentation](https://nette.org/en/writing) - -Issues ------- - -Please **do not use the issue tracker to ask questions**. We will be happy to help you -on [Nette forum](https://forum.nette.org) or chat with us on [Gitter](https://gitter.im/nette/nette). - -A good bug report shouldn't leave others needing to chase you up for more -information. Please try to be as detailed as possible in your report. - -**Feature requests** are welcome. But take a moment to find out whether your idea -fits with the scope and aims of the project. It's up to *you* to make a strong -case to convince the project's developers of the merits of this feature. - -Contributing ------------- - -If you'd like to contribute, please take a moment to read [the contributing guide](https://nette.org/en/contributing). - -The best way to propose a feature is to discuss your ideas on [Nette forum](https://forum.nette.org) before implementing them. - -Please do not fix whitespace, format code, or make a purely cosmetic patch. - -Thanks! :heart: From ab37a47ae633e1432300e2371bfc79a909b41db6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 14 Aug 2023 21:26:31 +0200 Subject: [PATCH 23/42] removed support for Latte 2 --- composer.json | 3 +- src/Bridges/ApplicationDI/LatteExtension.php | 46 +---- .../ApplicationLatte/SnippetBridge.php | 96 --------- src/Bridges/ApplicationLatte/Template.php | 11 +- .../ApplicationLatte/TemplateFactory.php | 65 +----- src/Bridges/ApplicationLatte/UIMacros.php | 188 ------------------ src/Bridges/ApplicationLatte/UIRuntime.php | 84 -------- tests/Bridges.DI/LatteExtension.2.phpt | 122 ------------ tests/Bridges.DI/LatteExtension.basic.phpt | 4 - .../Template.getParentName().phpt | 58 ------ .../TemplateFactory.customTemplate.phpt | 74 ------- .../TemplateFactory.filters.phpt | 47 ----- .../TemplateFactory.nonce.control.phpt | 39 ---- .../TemplateFactory.nonce.presenter.phpt | 42 ---- .../TemplateFactory.onCompile.phpt | 80 -------- .../TemplateFactory.onCreate.phpt | 36 ---- tests/Bridges.Latte2/UIMacros.control.2.phpt | 86 -------- tests/Bridges.Latte2/UIMacros.control.3.phpt | 51 ----- tests/Bridges.Latte2/UIMacros.control.phpt | 88 -------- .../UIMacros.isLinkCurrent.phpt | 54 ----- tests/Bridges.Latte2/UIMacros.link.2.phpt | 122 ------------ tests/Bridges.Latte2/UIMacros.link.phpt | 68 ------- .../UIMacros.renderSnippets.phpt | 97 --------- .../UIMacros.renderSnippets2.phpt | 84 -------- .../UIMacros.renderSnippets3.phpt | 73 ------- .../UIMacros.renderSnippets4.phpt | 54 ----- .../UIMacros.renderSnippets5.phpt | 59 ------ .../UIMacros.renderSnippets6.phpt | 45 ----- .../expected/UIMacros.isLinkCurrent.php | 22 -- .../expected/UIMacros.renderSnippets.html | 20 -- tests/Bridges.Latte2/templates/include3.latte | 1 - .../templates/snippet-include.latte | 25 --- .../templates/snippet-included.latte | 1 - .../Template.getParentName().phpt | 4 - .../TemplateFactory.customTemplate.phpt | 4 - .../TemplateFactory.filters.phpt | 4 - .../TemplateFactory.nonce.control.phpt | 4 - .../TemplateFactory.nonce.presenter.phpt | 4 - .../TemplateFactory.onCreate.phpt | 4 - tests/Bridges.Latte3/isLinkCurrent().phpt | 4 - tests/Bridges.Latte3/n-snippet.2.phpt | 4 - tests/Bridges.Latte3/n-snippet.block.phpt | 4 - tests/Bridges.Latte3/n-snippet.dynamic.phpt | 4 - tests/Bridges.Latte3/n-snippet.phpt | 3 - tests/Bridges.Latte3/renderSnippets.phpt | 4 - tests/Bridges.Latte3/renderSnippets2.phpt | 4 - tests/Bridges.Latte3/renderSnippets3.phpt | 4 - tests/Bridges.Latte3/renderSnippets4.phpt | 4 - tests/Bridges.Latte3/renderSnippets5.phpt | 4 - tests/Bridges.Latte3/renderSnippets6.phpt | 4 - tests/Bridges.Latte3/renderSnippets7.phpt | 4 - tests/Bridges.Latte3/{control}.2.phpt | 4 - tests/Bridges.Latte3/{control}.3.phpt | 3 - tests/Bridges.Latte3/{control}.phpt | 4 - tests/Bridges.Latte3/{ifCurrent}.phpt | 4 - tests/Bridges.Latte3/{link}.2.phpt | 4 - tests/Bridges.Latte3/{link}.phpt | 4 - tests/Bridges.Latte3/{snippet}.dynamic.phpt | 4 - tests/Bridges.Latte3/{snippet}.phpt | 4 - 59 files changed, 13 insertions(+), 2034 deletions(-) delete mode 100644 src/Bridges/ApplicationLatte/SnippetBridge.php delete mode 100644 src/Bridges/ApplicationLatte/UIMacros.php delete mode 100644 src/Bridges/ApplicationLatte/UIRuntime.php delete mode 100644 tests/Bridges.DI/LatteExtension.2.phpt delete mode 100644 tests/Bridges.Latte2/Template.getParentName().phpt delete mode 100644 tests/Bridges.Latte2/TemplateFactory.customTemplate.phpt delete mode 100644 tests/Bridges.Latte2/TemplateFactory.filters.phpt delete mode 100644 tests/Bridges.Latte2/TemplateFactory.nonce.control.phpt delete mode 100644 tests/Bridges.Latte2/TemplateFactory.nonce.presenter.phpt delete mode 100644 tests/Bridges.Latte2/TemplateFactory.onCompile.phpt delete mode 100644 tests/Bridges.Latte2/TemplateFactory.onCreate.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.control.2.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.control.3.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.control.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.isLinkCurrent.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.link.2.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.link.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.renderSnippets.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.renderSnippets2.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.renderSnippets3.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.renderSnippets4.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.renderSnippets5.phpt delete mode 100644 tests/Bridges.Latte2/UIMacros.renderSnippets6.phpt delete mode 100644 tests/Bridges.Latte2/expected/UIMacros.isLinkCurrent.php delete mode 100644 tests/Bridges.Latte2/expected/UIMacros.renderSnippets.html delete mode 100644 tests/Bridges.Latte2/templates/include3.latte delete mode 100644 tests/Bridges.Latte2/templates/snippet-include.latte delete mode 100644 tests/Bridges.Latte2/templates/snippet-included.latte diff --git a/composer.json b/composer.json index 40d55e089..f51e89757 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "nette/forms": "^4.0", "nette/robot-loader": "^3.2 || ^4.0", "nette/security": "^4.0", - "latte/latte": "^2.10.2 || ^3.0.3", + "latte/latte": "^3.0.8", "tracy/tracy": "^2.8", "mockery/mockery": "^1.4", "phpstan/phpstan-nette": "^1.0", @@ -42,7 +42,6 @@ "nette/di": "<3.0.7", "nette/forms": "<3.0", "nette/schema": "<1.2", - "latte/latte": "<2.7.1 || >=3.0.0 <3.0.8 || >=3.1", "tracy/tracy": "<2.5" }, "autoload": { diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 2036fb7df..405acd910 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -37,7 +37,6 @@ public function getConfigSchema(): Nette\Schema\Schema { return Expect::structure([ 'debugger' => Expect::anyOf(true, false, 'all'), - 'macros' => Expect::arrayOf('string'), 'extensions' => Expect::arrayOf('string|Nette\DI\Definitions\Statement'), 'templateClass' => Expect::string(), 'strictTypes' => Expect::bool(false), @@ -62,19 +61,12 @@ public function loadConfiguration() ->setFactory(Latte\Engine::class) ->addSetup('setTempDirectory', [$this->tempDir]) ->addSetup('setAutoRefresh', [$this->debugMode]) - ->addSetup('setStrictTypes', [$config->strictTypes]); - - if (version_compare(Latte\Engine::VERSION, '3', '<')) { - foreach ($config->macros as $macro) { - $this->addMacro($macro); - } - } else { - $latteFactory->addSetup('setStrictParsing', [$config->strictParsing]) + ->addSetup('setStrictTypes', [$config->strictTypes]) + ->addSetup('setStrictParsing', [$config->strictParsing]) ->addSetup('enablePhpLinter', [$config->phpLinter]); - foreach ($config->extensions as $extension) { - $this->addExtension($extension); - } + foreach ($config->extensions as $extension) { + $this->addExtension($extension); } $builder->addDefinition($this->prefix('templateFactory')) @@ -116,40 +108,12 @@ public static function initLattePanel( $control = $template->getLatte()->getProviders()['uiControl'] ?? null; if ($all || $control instanceof Nette\Application\UI\Presenter) { $name = $all && $control ? (new \ReflectionObject($control))->getShortName() : ''; - if (version_compare(Latte\Engine::VERSION, '3', '<')) { - $bar->addPanel(new Latte\Bridges\Tracy\LattePanel($template->getLatte(), $name)); - } else { - $template->getLatte()->addExtension(new Latte\Bridges\Tracy\TracyExtension($name)); - } + $template->getLatte()->addExtension(new Latte\Bridges\Tracy\TracyExtension($name)); } }; } - public function addMacro(string $macro): void - { - $builder = $this->getContainerBuilder(); - $definition = $builder->getDefinition($this->prefix('latteFactory'))->getResultDefinition(); - - if (($macro[0] ?? null) === '@') { - if (str_contains($macro, '::')) { - [$macro, $method] = explode('::', $macro); - } else { - $method = 'install'; - } - - $definition->addSetup('?->onCompile[] = function ($engine) { ?->' . $method . '($engine->getCompiler()); }', ['@self', $macro]); - - } else { - if (!str_contains($macro, '::') && class_exists($macro)) { - $macro .= '::install'; - } - - $definition->addSetup('?->onCompile[] = function ($engine) { ' . $macro . '($engine->getCompiler()); }', ['@self']); - } - } - - /** @param Nette\DI\Definitions\Statement|string $extension */ public function addExtension($extension): void { diff --git a/src/Bridges/ApplicationLatte/SnippetBridge.php b/src/Bridges/ApplicationLatte/SnippetBridge.php deleted file mode 100644 index 66109abba..000000000 --- a/src/Bridges/ApplicationLatte/SnippetBridge.php +++ /dev/null @@ -1,96 +0,0 @@ -control = $control; - } - - - public function isSnippetMode(): bool - { - return (bool) $this->control->snippetMode; - } - - - public function setSnippetMode($snippetMode) - { - $this->control->snippetMode = $snippetMode; - } - - - public function needsRedraw($name): bool - { - return $this->control->isControlInvalid($name); - } - - - public function markRedrawn($name): void - { - if ($name !== '') { - $this->control->redrawControl($name, false); - } - } - - - public function getHtmlId($name): string - { - return $this->control->getSnippetId($name); - } - - - public function addSnippet($name, $content): void - { - if (!isset($this->payload)) { - $this->payload = $this->control->getPresenter()->getPayload(); - } - - $this->payload->snippets[$this->control->getSnippetId($name)] = $content; - } - - - public function renderChildren(): void - { - $queue = [$this->control]; - do { - foreach (array_shift($queue)->getComponents() as $child) { - if ($child instanceof Renderable) { - if ($child->isControlInvalid()) { - $child->snippetMode = true; - $child->render(); - $child->snippetMode = false; - } - } elseif ($child instanceof Nette\ComponentModel\IContainer) { - $queue[] = $child; - } - } - } while ($queue); - } -} diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index 28cfdacb6..114dff8c1 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -92,16 +92,7 @@ public function addFunction(string $name, callable $callback): static */ public function setTranslator(?Nette\Localization\Translator $translator, ?string $language = null): static { - if (version_compare(Latte\Engine::VERSION, '3', '<')) { - $this->latte->addFilter( - 'translate', - fn(Latte\Runtime\FilterInfo $fi, ...$args): string => $translator === null - ? $args[0] - : $translator->translate(...$args), - ); - } else { - $this->latte->addExtension(new Latte\Essential\TranslatorExtension($translator, $language)); - } + $this->latte->addExtension(new Latte\Essential\TranslatorExtension($translator, $language)); return $this; } diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index d325603ab..becd5dc36 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -50,19 +50,14 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul $template = new $class($latte); $presenter = $control ? $control->getPresenterIfExists() : null; - if (version_compare(Latte\Engine::VERSION, '3', '<')) { - $this->setupLatte2($latte, $control, $presenter, $template); + $latte->addExtension(new UIExtension($control)); - } else { - $latte->addExtension(new UIExtension($control)); - - if ($this->cacheStorage && class_exists(Nette\Bridges\CacheLatte\CacheExtension::class)) { - $latte->addExtension(new Nette\Bridges\CacheLatte\CacheExtension($this->cacheStorage)); - } + if ($this->cacheStorage && class_exists(Nette\Bridges\CacheLatte\CacheExtension::class)) { + $latte->addExtension(new Nette\Bridges\CacheLatte\CacheExtension($this->cacheStorage)); + } - if (class_exists(Nette\Bridges\FormsLatte\FormsExtension::class)) { - $latte->addExtension(new Nette\Bridges\FormsLatte\FormsExtension); - } + if (class_exists(Nette\Bridges\FormsLatte\FormsExtension::class)) { + $latte->addExtension(new Nette\Bridges\FormsLatte\FormsExtension); } $latte->addFilter('modifyDate', fn($time, $delta, $unit = null) => $time @@ -102,52 +97,4 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul return $template; } - - - private function setupLatte2( - Latte\Engine $latte, - ?UI\Control $control, - ?UI\Presenter $presenter, - Template $template, - ): void - { - if ($latte->onCompile instanceof \Traversable) { - $latte->onCompile = iterator_to_array($latte->onCompile); - } - - array_unshift($latte->onCompile, function (Latte\Engine $latte) use ($control, $template): void { - if ($this->cacheStorage) { - $latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro); - } - - UIMacros::install($latte->getCompiler()); - if (class_exists(Nette\Bridges\FormsLatte\FormMacros::class)) { - Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler()); - } - - if ($control) { - $control->templatePrepareFilters($template); - } - }); - - $latte->addProvider('cacheStorage', $this->cacheStorage); - - if ($control) { - $latte->addProvider('uiControl', $control); - $latte->addProvider('uiPresenter', $presenter); - $latte->addProvider('snippetBridge', new SnippetBridge($control)); - if ($presenter) { - $header = $presenter->getHttpResponse()->getHeader('Content-Security-Policy') - ?: $presenter->getHttpResponse()->getHeader('Content-Security-Policy-Report-Only'); - } - - $nonce = $presenter && preg_match('#\s\'nonce-([\w+/]+=*)\'#', (string) $header, $m) ? $m[1] : null; - $latte->addProvider('uiNonce', $nonce); - } - - if ($presenter) { - $latte->addFunction('isLinkCurrent', [$presenter, 'isLinkCurrent']); - $latte->addFunction('isModuleCurrent', [$presenter, 'isModuleCurrent']); - } - } } diff --git a/src/Bridges/ApplicationLatte/UIMacros.php b/src/Bridges/ApplicationLatte/UIMacros.php deleted file mode 100644 index 0ff1fb87b..000000000 --- a/src/Bridges/ApplicationLatte/UIMacros.php +++ /dev/null @@ -1,188 +0,0 @@ -addMacro('control', [$me, 'macroControl']); - - $me->addMacro('href', null, null, fn(MacroNode $node, PhpWriter $writer): string => ' ?> href="macroLink($node, $writer) . ' ?>"addMacro('plink', [$me, 'macroLink']); - $me->addMacro('link', [$me, 'macroLink']); - $me->addMacro('ifCurrent', [$me, 'macroIfCurrent'], '}'); // deprecated; use n:class="$presenter->linkCurrent ? ..." - $me->addMacro('extends', [$me, 'macroExtends']); - $me->addMacro('layout', [$me, 'macroExtends']); - $me->addMacro('nonce', null, null, 'echo $this->global->uiNonce ? " nonce=\"{$this->global->uiNonce}\"" : "";'); - $me->addMacro('templatePrint', [$me, 'macroTemplatePrint'], null, null, self::ALLOWED_IN_HEAD); - } - - - /** - * Initializes before template parsing. - */ - public function initialize(): void - { - $this->extends = false; - } - - - /** - * Finishes template parsing. - * @return array(prolog, epilog) - */ - public function finalize() - { - if ($this->printTemplate) { - return ["Nette\\Bridges\\ApplicationLatte\\UIRuntime::printClass(\$this, $this->printTemplate); exit;"]; - } - - return [$this->extends . 'Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->parentName, $this->blocks);']; - } - - - /********************* macros ****************d*g**/ - - - /** - * {control name[:method] [params]} - */ - public function macroControl(MacroNode $node, PhpWriter $writer) - { - if ($node->context !== [Latte\Compiler::CONTENT_HTML, Latte\Compiler::CONTEXT_HTML_TEXT]) { - $escapeMod = Latte\Helpers::removeFilter($node->modifiers, 'noescape') ? '' : '|escape'; - } - - if ($node->modifiers) { - trigger_error('Modifiers are deprecated in ' . $node->getNotation(), E_USER_DEPRECATED); - } - - $node->modifiers .= $escapeMod ?? ''; - - $words = $node->tokenizer->fetchWords(); - if (!$words) { - throw new CompileException('Missing control name in {control}'); - } - - $name = $writer->formatWord($words[0]); - $method = ucfirst($words[1] ?? ''); - $method = Strings::match($method, '#^\w*$#D') - ? "render$method" - : "{\"render$method\"}"; - - $tokens = $node->tokenizer; - $pos = $tokens->position; - $wrap = false; - while ($tokens->nextToken()) { - if ($tokens->isCurrent('=>', '(expand)') && !$tokens->depth) { - $wrap = true; - break; - } - } - - $tokens->position = $pos; - $param = $wrap ? $writer->formatArray() : $writer->formatArgs(); - - return "/* line $node->startLine */ " - . ($name[0] === '$' ? "if (is_object($name)) \$_tmp = $name; else " : '') - . '$_tmp = $this->global->uiControl->getComponent(' . $name . '); ' - . 'if ($_tmp instanceof Nette\Application\UI\Renderable) $_tmp->redrawControl(null, false); ' - . ($node->modifiers === '' - ? "\$_tmp->$method($param);" - : $writer->write( - "ob_start(fn() => null); \$_tmp->$method($param); \$ʟ_fi = new LR\\FilterInfo(%var); echo %modifyContent(ob_get_clean());", - Latte\Engine::CONTENT_HTML, - ) - ); - } - - - /** - * {link destination [,] [params]} - * {plink destination [,] [params]} - * n:href="destination [,] [params]" - */ - public function macroLink(MacroNode $node, PhpWriter $writer) - { - $node->modifiers = preg_replace('#\|safeurl\s*(?=\||$)#Di', '', $node->modifiers); - return $writer->using($node, $this->getCompiler()) - ->write( - 'echo %escape(%modify(' - . ($node->name === 'plink' ? '$this->global->uiPresenter' : '$this->global->uiControl') - . '->link(%node.word, %node.array?)))' - . ($node->startLine ? " /* line $node->startLine */;" : ';'), - ); - } - - - /** - * {ifCurrent destination [,] [params]} - */ - public function macroIfCurrent(MacroNode $node, PhpWriter $writer) - { - if ($node->modifiers) { - throw new CompileException('Modifiers are not allowed in ' . $node->getNotation()); - } - - return $writer->write( - $node->args - ? 'if ($this->global->uiPresenter->isLinkCurrent(%node.word, %node.array?)) {' - : 'if ($this->global->uiPresenter->getLastCreatedRequestFlag("current")) {', - ); - } - - - /** - * {extends auto} - */ - public function macroExtends(MacroNode $node, PhpWriter $writer) - { - if ($node->modifiers || $node->parentNode || $node->args !== 'auto') { - return $this->extends = false; - } - - $this->extends = $writer->write('$this->parentName = $this->global->uiPresenter->findLayoutTemplateFile();'); - } - - - /** - * {templatePrint [parentClass | default]} - */ - public function macroTemplatePrint(MacroNode $node): void - { - if ($node->modifiers) { - throw new CompileException('Modifiers are not allowed in ' . $node->getNotation()); - } - - $this->printTemplate = var_export($node->tokenizer->fetchWord() ?: null, true); - } -} diff --git a/src/Bridges/ApplicationLatte/UIRuntime.php b/src/Bridges/ApplicationLatte/UIRuntime.php deleted file mode 100644 index ace3af72d..000000000 --- a/src/Bridges/ApplicationLatte/UIRuntime.php +++ /dev/null @@ -1,84 +0,0 @@ -global; - $blocks = array_filter(array_keys($blocks), fn(string $s): bool => $s[0] !== '_'); - if ( - $parentName === null - && $blocks - && !$template->getReferringTemplate() - && ($providers->uiControl ?? null) instanceof Nette\Application\UI\Presenter - ) { - $parentName = $providers->uiControl->findLayoutTemplateFile(); - } - } - - - public static function printClass(Latte\Runtime\Template $template, ?string $parent = null): void - { - $blueprint = new Latte\Runtime\Blueprint; - $name = 'Template'; - $params = $template->getParameters(); - $control = $params['control'] ?? $params['presenter'] ?? null; - if ($control) { - $name = preg_replace('#(Control|Presenter)$#', '', $control::class) . 'Template'; - unset($params[$control instanceof Presenter ? 'control' : 'presenter']); - } - - if ($parent) { - if (!class_exists($parent)) { - $blueprint->printHeader("{templatePrint}: Class '$parent' doesn't exist."); - return; - } - - $params = array_diff_key($params, get_class_vars($parent)); - } - - $funcs = array_diff_key((array) $template->global->fn, (new Latte\Runtime\Defaults)->getFunctions()); - unset($funcs['isLinkCurrent'], $funcs['isModuleCurrent']); - - $namespace = new Php\PhpNamespace(Php\Helpers::extractNamespace($name)); - $class = $namespace->addClass(Php\Helpers::extractShortName($name)); - $class->setExtends($parent ?: Template::class); - if (!$parent) { - $class->addTrait(Nette\SmartObject::class); - } - - $blueprint->addProperties($class, $params, true); - $blueprint->addFunctions($class, $funcs); - - $end = $blueprint->printCanvas(); - $blueprint->printHeader('Native types'); - $blueprint->printCode((string) $namespace); - - $blueprint->addProperties($class, $params, false); - - $blueprint->printHeader('phpDoc types'); - $blueprint->printCode((string) $namespace); - echo $end; - } -} diff --git a/tests/Bridges.DI/LatteExtension.2.phpt b/tests/Bridges.DI/LatteExtension.2.phpt deleted file mode 100644 index 8144950b6..000000000 --- a/tests/Bridges.DI/LatteExtension.2.phpt +++ /dev/null @@ -1,122 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -class LoremIpsumMacros extends Latte\Macros\MacroSet -{ - public static function install(Latte\Compiler $compiler) - { - $me = new static($compiler); - $me->addMacro('lorem', 'lorem'); - Notes::add($me::class); - } -} - - -class IpsumLoremMacros extends Latte\Macros\MacroSet -{ - public static function install(Latte\Compiler $compiler) - { - $me = new static($compiler); - $me->addMacro('ipsum', 'ipsum'); - Notes::add($me::class); - } -} - - -class FooMacros extends Latte\Macros\MacroSet -{ - public static function install(Latte\Compiler $compiler) - { - $me = new static($compiler); - $me->addMacro('foo', 'foo'); - Notes::add($me::class); - } -} - - -class NonStaticMacrosFactory -{ - private string $parameter; - - - public function __construct($parameter) - { - $this->parameter = $parameter; - } - - - public function install(Latte\Compiler $compiler) - { - $macros = new Latte\Macros\MacroSet($compiler); - $macros->addMacro('foo', 'foo ' . $this->parameter); - Notes::add(static::class . '::install'); - } - - - public function create(Latte\Compiler $compiler) - { - $macros = new Latte\Macros\MacroSet($compiler); - $macros->addMacro('foo2', 'foo ' . $this->parameter); - Notes::add(static::class . '::create'); - } -} - - -class AnotherExtension extends Nette\DI\CompilerExtension -{ - public function beforeCompile() - { - foreach ($this->compiler->getExtensions(Nette\Bridges\ApplicationDI\LatteExtension::class) as $extension) { - $extension->addMacro('FooMacros::install'); - } - } -} - - -$loader = new DI\Config\Loader; -$config = $loader->load(Tester\FileMock::create(' -latte: - macros: - - LoremIpsumMacros - - IpsumLoremMacros::install - - @macroFactory - - @macroFactory::create - -services: - macroFactory: NonStaticMacrosFactory(foo) -', 'neon')); - -$compiler = new DI\Compiler; -$compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension('', false)); -$compiler->addExtension('another', new AnotherExtension); -$code = $compiler->addConfig($config)->compile(); -eval($code); - -$container = new Container; - - -Assert::type(Nette\Bridges\ApplicationLatte\LatteFactory::class, $container->getService('nette.latteFactory')); -$container->getService('nette.latteFactory')->create()->setLoader(new Latte\Loaders\StringLoader)->compile(''); - -Assert::same([ - 'LoremIpsumMacros', - 'IpsumLoremMacros', - 'NonStaticMacrosFactory::install', - 'NonStaticMacrosFactory::create', - 'FooMacros', -], Notes::fetch()); diff --git a/tests/Bridges.DI/LatteExtension.basic.phpt b/tests/Bridges.DI/LatteExtension.basic.phpt index 1ee2f1416..74928c51b 100644 --- a/tests/Bridges.DI/LatteExtension.basic.phpt +++ b/tests/Bridges.DI/LatteExtension.basic.phpt @@ -11,10 +11,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class MyExtension extends Latte\Extension { diff --git a/tests/Bridges.Latte2/Template.getParentName().phpt b/tests/Bridges.Latte2/Template.getParentName().phpt deleted file mode 100644 index 1253c4a4e..000000000 --- a/tests/Bridges.Latte2/Template.getParentName().phpt +++ /dev/null @@ -1,58 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -$presenter = Mockery::mock(Nette\Application\UI\Presenter::class) - ->shouldReceive('findLayoutTemplateFile')->andReturn('layout.latte') - ->mock(); - -$latte = new Latte\Engine; -$latte->setLoader(new Latte\Loaders\StringLoader); -$latte->addProvider('uiControl', $presenter); -UIMacros::install($latte->getCompiler()); - -$template = $latte->createTemplate(''); -$template->prepare(); -Assert::null($template->getParentName()); - -$template = $latte->createTemplate('{block}...{/block}'); -$template->prepare(); -Assert::null($template->getParentName()); - -$template = $latte->createTemplate('{block name}...{/block}'); -$template->prepare(); -Assert::same('layout.latte', $template->getParentName()); - -$template = $latte->createTemplate('{extends "file.latte"} {block name}...{/block}'); -$template->prepare(); -Assert::same('file.latte', $template->getParentName()); - -$template = $latte->createTemplate('{extends "file.latte"}'); -$template->prepare(); -Assert::same('file.latte', $template->getParentName()); - -$template = $latte->createTemplate( - '{extends $file} {block name}...{/block}', - ['file' => 'file.latte'], -); -$template->prepare(); -Assert::same('file.latte', $template->getParentName()); - -$template = $latte->createTemplate('{extends none}'); -$template->prepare(); -Assert::null($template->getParentName()); - -$latte->addProvider('uiPresenter', $presenter); -$template = $latte->createTemplate('{extends auto}'); -$template->prepare(); -Assert::same('layout.latte', $template->getParentName()); diff --git a/tests/Bridges.Latte2/TemplateFactory.customTemplate.phpt b/tests/Bridges.Latte2/TemplateFactory.customTemplate.phpt deleted file mode 100644 index aeb8eeb1b..000000000 --- a/tests/Bridges.Latte2/TemplateFactory.customTemplate.phpt +++ /dev/null @@ -1,74 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - -Tester\Environment::bypassFinals(); - - -class TemplateMock extends Template -{ - private $file = 'ko'; - - - public function render(?string $file = null, array $params = []): void - { - echo strrev($this->file); - } - - - public function setFile(string $file) - { - $this->file = $file; - } - - - public function getFile(): string - { - return $this->file; - } -} - - -test('', function () { - $latteFactory = Mockery::mock(LatteFactory::class); - $latteFactory->shouldReceive('create')->andReturn(new Latte\Engine); - $factory = new TemplateFactory($latteFactory); - Assert::type(Template::class, $factory->createTemplate()); -}); - -Assert::exception(function () { - $factory = new TemplateFactory(Mockery::mock(LatteFactory::class), null, null, null, stdClass::class); -}, Nette\InvalidArgumentException::class, 'Class stdClass does not implement Nette\Bridges\ApplicationLatte\Template or it does not exist.'); - - -test('', function () { - $latteFactory = Mockery::mock(LatteFactory::class); - $latteFactory->shouldReceive('create')->andReturn(new Latte\Engine); - $factory = new TemplateFactory($latteFactory, null, null, null, TemplateMock::class); - $template = $factory->createTemplate(); - Assert::type(TemplateMock::class, $template); - Assert::type(UI\Template::class, $template); - ob_start(); - $template->render(); - Assert::same('ok', ob_get_clean()); - $template->setFile('bla'); - ob_start(); - $template->render(); - Assert::same('alb', ob_get_clean()); -}); diff --git a/tests/Bridges.Latte2/TemplateFactory.filters.phpt b/tests/Bridges.Latte2/TemplateFactory.filters.phpt deleted file mode 100644 index 57e879543..000000000 --- a/tests/Bridges.Latte2/TemplateFactory.filters.phpt +++ /dev/null @@ -1,47 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -class LatteFactory implements Nette\Bridges\ApplicationLatte\LatteFactory -{ - private $engine; - - - public function __construct(Latte\Engine $engine) - { - $this->engine = $engine; - } - - - public function create(): Latte\Engine - { - return $this->engine; - } -} - -$factory = new TemplateFactory(new LatteFactory(new Latte\Engine)); -$latte = $factory->createTemplate()->getLatte(); - - -setlocale(LC_TIME, 'C'); -date_default_timezone_set('Europe/Prague'); - -Assert::null($latte->invokeFilter('modifyDate', [null, null])); -Assert::same('1978-01-24 11:40:00', (string) $latte->invokeFilter('modifyDate', [254_400_000, '+1 day'])); -Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', ['1978-05-05', '+1 day'])); -Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', [new DateTime('1978-05-05'), '1day'])); -Assert::same('1978-01-22 11:40:00', (string) $latte->invokeFilter('modifyDate', [254_400_000, -1, 'day'])); diff --git a/tests/Bridges.Latte2/TemplateFactory.nonce.control.phpt b/tests/Bridges.Latte2/TemplateFactory.nonce.control.phpt deleted file mode 100644 index 850629b36..000000000 --- a/tests/Bridges.Latte2/TemplateFactory.nonce.control.phpt +++ /dev/null @@ -1,39 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - -$latte = new Latte\Engine; - -$latteFactory = Mockery::mock(ApplicationLatte\LatteFactory::class); -$latteFactory->shouldReceive('create')->andReturn($latte); - -$response = Mockery::mock(Nette\Http\IResponse::class); -$response->shouldReceive('getHeader')->with('Content-Security-Policy')->andReturn("hello 'nonce-abcd123==' world"); - -$control = Mockery::mock(UI\Control::class); -$control->shouldReceive('getPresenter')->andReturn(null); -$control->shouldIgnoreMissing(); - -$factory = new ApplicationLatte\TemplateFactory($latteFactory); -$factory->createTemplate($control); - -$latte->setLoader(new Latte\Loaders\StringLoader); - -Assert::match( - '', - $latte->renderToString(''), -); diff --git a/tests/Bridges.Latte2/TemplateFactory.nonce.presenter.phpt b/tests/Bridges.Latte2/TemplateFactory.nonce.presenter.phpt deleted file mode 100644 index 1ef2df0e8..000000000 --- a/tests/Bridges.Latte2/TemplateFactory.nonce.presenter.phpt +++ /dev/null @@ -1,42 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - -Tester\Environment::bypassFinals(); - -$latte = new Latte\Engine; - -$latteFactory = Mockery::mock(ApplicationLatte\LatteFactory::class); -$latteFactory->shouldReceive('create')->andReturn($latte); - -$response = Mockery::mock(Nette\Http\IResponse::class); -$response->shouldReceive('getHeader')->with('Content-Security-Policy')->andReturn("hello 'nonce-abcd123==' world"); - -$presenter = Mockery::mock(UI\Presenter::class); -$presenter->shouldReceive('getPresenterIfExists')->andReturn($presenter); -$presenter->shouldReceive('getHttpResponse')->andReturn($response); -$presenter->shouldIgnoreMissing(); - -$factory = new ApplicationLatte\TemplateFactory($latteFactory); -$factory->createTemplate($presenter); - -$latte->setLoader(new Latte\Loaders\StringLoader); - -Assert::match( - '', - $latte->renderToString(''), -); diff --git a/tests/Bridges.Latte2/TemplateFactory.onCompile.phpt b/tests/Bridges.Latte2/TemplateFactory.onCompile.phpt deleted file mode 100644 index b60ebd8e1..000000000 --- a/tests/Bridges.Latte2/TemplateFactory.onCompile.phpt +++ /dev/null @@ -1,80 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -test('', function () { - $engine = new Latte\Engine; - $latteFactory = Mockery::mock(LatteFactory::class); - $latteFactory->shouldReceive('create')->andReturn($engine); - $factory = new TemplateFactory($latteFactory, new Http\Request(new Http\UrlScript('http://nette.org'))); - $engine->onCompile[] = $callback = function () {}; - - $factory->createTemplate(); - - Assert::type('array', $engine->onCompile); - Assert::type(Closure::class, $engine->onCompile[0]); // prepended by TemplateFactory - Assert::same($callback, $engine->onCompile[1]); // our callback -}); - - -test('', function () { - $engine = new Latte\Engine; - $latteFactory = Mockery::mock(LatteFactory::class); - $latteFactory->shouldReceive('create')->andReturn($engine); - $factory = new TemplateFactory($latteFactory, new Http\Request(new Http\UrlScript('http://nette.org'))); - $engine->onCompile = new ArrayIterator([$callback = function () {}]); - - $factory->createTemplate(); - - Assert::type('array', $engine->onCompile); - Assert::type(Closure::class, $engine->onCompile[0]); // prepended by TemplateFactory - Assert::same($callback, $engine->onCompile[1]); // our callback -}); - - -test('', function () { - class Event implements IteratorAggregate - { - public $events; - - - public function __construct($events) - { - $this->events = $events; - } - - - public function getIterator(): ArrayIterator - { - return new ArrayIterator($this->events); - } - } - - $engine = new Latte\Engine; - $latteFactory = Mockery::mock(LatteFactory::class); - $latteFactory->shouldReceive('create')->andReturn($engine); - $factory = new TemplateFactory($latteFactory, new Http\Request(new Http\UrlScript('http://nette.org'))); - $engine->onCompile = new Event([$callback = function () {}]); - - $factory->createTemplate(); - - Assert::type('array', $engine->onCompile); - Assert::type(Closure::class, $engine->onCompile[0]); // prepended by TemplateFactory - Assert::same($callback, $engine->onCompile[1]); // our callback -}); diff --git a/tests/Bridges.Latte2/TemplateFactory.onCreate.phpt b/tests/Bridges.Latte2/TemplateFactory.onCreate.phpt deleted file mode 100644 index 8f86ef42d..000000000 --- a/tests/Bridges.Latte2/TemplateFactory.onCreate.phpt +++ /dev/null @@ -1,36 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -test('', function () { - $engine = new Latte\Engine; - $latteFactory = Mockery::mock(LatteFactory::class); - $latteFactory->shouldReceive('create')->andReturn($engine); - $factory = new TemplateFactory($latteFactory, new Http\Request(new Http\UrlScript('http://nette.org'))); - $factory->onCreate[] = $callback = function (Template $template) { - $template->add('foo', 'bar'); - }; - - $template = $factory->createTemplate(); - - Assert::type('array', $factory->onCreate); - Assert::same($callback, $factory->onCreate[0]); // our callback - Assert::equal('bar', $template->foo); -}); diff --git a/tests/Bridges.Latte2/UIMacros.control.2.phpt b/tests/Bridges.Latte2/UIMacros.control.2.phpt deleted file mode 100644 index 9449e00e3..000000000 --- a/tests/Bridges.Latte2/UIMacros.control.2.phpt +++ /dev/null @@ -1,86 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -class MockComponent -{ - public function getComponent($name) - { - Notes::add(__METHOD__); - Notes::add(func_get_args()); - return new MockControl; - } -} - - -class MockControl -{ - public function __call($name, $args) - { - Notes::add(__METHOD__); - Notes::add(func_get_args()); - } -} - - -$latte = new Latte\Engine; -$latte->setLoader(new Latte\Loaders\StringLoader); -UIMacros::install($latte->getCompiler()); - -$latte->addProvider('uiControl', new MockComponent); -$params['form'] = new MockControl; -$params['name'] = 'form'; - -$latte->renderToString(' -{control \'name\'} - -{control form} - -{control form:test} - -{control $form:test} - -{control $name:test} - -{control $name:$name} - -{control form var1} - -{control form var1, 1, 2} - -{control form var1 => 5, 1, 2} -', $params); - -Assert::same([ - 'MockComponent::getComponent', ['name'], - 'MockControl::__call', ['render', []], - 'MockComponent::getComponent', ['form'], - 'MockControl::__call', ['render', []], - 'MockComponent::getComponent', ['form'], - 'MockControl::__call', ['renderTest', []], - 'MockControl::__call', ['renderTest', []], - 'MockComponent::getComponent', ['form'], - 'MockControl::__call', ['renderTest', []], - 'MockComponent::getComponent', ['form'], - 'MockControl::__call', ['renderform', []], - 'MockComponent::getComponent', ['form'], - 'MockControl::__call', ['render', ['var1']], - 'MockComponent::getComponent', ['form'], - 'MockControl::__call', ['render', ['var1', 1, 2]], - 'MockComponent::getComponent', ['form'], - 'MockControl::__call', ['render', [['var1' => 5, 0 => 1, 1 => 2]]], -], Notes::fetch()); diff --git a/tests/Bridges.Latte2/UIMacros.control.3.phpt b/tests/Bridges.Latte2/UIMacros.control.3.phpt deleted file mode 100644 index f5d6e23d2..000000000 --- a/tests/Bridges.Latte2/UIMacros.control.3.phpt +++ /dev/null @@ -1,51 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -$latte = new Latte\Engine; -$latte->setLoader(new Latte\Loaders\StringLoader); -UIMacros::install($latte->getCompiler()); -$latte->addProvider('uiControl', new class { - public function render() - { - echo '<>&'; - } - - - public function __call($name, $args) - { - return new self; - } -}); - -Assert::exception(function () use ($latte) { - $latte->renderToString('
&', - $latte->renderToString('
', - $latte->renderToString('
'), -); - -Assert::exception(function () use ($latte) { - $latte->renderToString(''); -}, Latte\RuntimeException::class, 'Filters: unable to convert content type HTML to HTMLCSS'); diff --git a/tests/Bridges.Latte2/UIMacros.control.phpt b/tests/Bridges.Latte2/UIMacros.control.phpt deleted file mode 100644 index 01c403e38..000000000 --- a/tests/Bridges.Latte2/UIMacros.control.phpt +++ /dev/null @@ -1,88 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -$latte = new Latte\Engine; -$latte->setLoader(new Latte\Loaders\StringLoader); -UIMacros::install($latte->getCompiler()); - -// {control ...} -Assert::match( - '%A% $this->global->uiControl->getComponent("form");%A%->render();%A%', - $latte->compile('{control form}'), -); - -@Assert::match( - <<<'XX' - %A% - /* line 1 */ $_tmp = $this->global->uiControl->getComponent("form"); - if ($_tmp instanceof Nette\Application\UI\Renderable) $_tmp->redrawControl(null, false); - ob_start(function () {}); - $_tmp->render(); - $ʟ_fi = new LR\FilterInfo('html'); - echo $this->filters->filterContent('filter', $ʟ_fi, ob_get_clean()); - %A% - XX, - $latte->compile('{control form|filter}'), -); // @deprecated - -Assert::match( - <<<'XX' - %A% - /* line 1 */ if (is_object($form)) $_tmp = $form; - else $_tmp = $this->global->uiControl->getComponent($form); - if ($_tmp instanceof Nette\Application\UI\Renderable) $_tmp->redrawControl(null, false); - $_tmp->render(); - %A% - XX, - $latte->compile('{control $form}'), -); - -Assert::match( - '%A% $this->global->uiControl->getComponent("form");%A%->renderType();%A%', - $latte->compile('{control form:type}'), -); - -Assert::match( - '%A% $this->global->uiControl->getComponent("form");%A%->{"render$type"}();%A%', - $latte->compile('{control form:$type}'), -); - -Assert::match( - '%A% $this->global->uiControl->getComponent("form");%A%->renderType(\'param\');%A%', - $latte->compile('{control form:type param}'), -); - -Assert::match( - '%A% $this->global->uiControl->getComponent("form");%A%->render(array_merge([], $params, []));%A%', - $latte->compile('{control form (expand) $params}'), -); - -Assert::match( - '%A% $this->global->uiControl->getComponent("form");%A%->renderType([\'param\' => 123]);%A%', - $latte->compile('{control form:type param => 123}'), -); - -Assert::match( - '%A% $this->global->uiControl->getComponent("form");%A%->renderType([\'param\' => 123]);%A%', - $latte->compile('{control form:type, param => 123}'), -); - -Assert::match( - '%A% $this->global->uiControl->getComponent("form");%A%->renderType(param: 123);%A%', - $latte->compile('{control form:type, param: 123}'), -); diff --git a/tests/Bridges.Latte2/UIMacros.isLinkCurrent.phpt b/tests/Bridges.Latte2/UIMacros.isLinkCurrent.phpt deleted file mode 100644 index 579a8fd4b..000000000 --- a/tests/Bridges.Latte2/UIMacros.isLinkCurrent.phpt +++ /dev/null @@ -1,54 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - -Tester\Environment::bypassFinals(); - -$latte = new Latte\Engine; - -$latteFactory = Mockery::mock(Nette\Bridges\ApplicationLatte\LatteFactory::class); -$latteFactory->shouldReceive('create')->andReturn($latte); - -$presenter = Mockery::mock(Nette\Application\UI\Presenter::class); -$presenter->shouldReceive('getPresenterIfExists')->andReturn($presenter); -$presenter->shouldReceive('getHttpResponse')->andReturn((Mockery::mock(Nette\Http\IResponse::class))->shouldIgnoreMissing()); -$presenter->shouldIgnoreMissing(); - -$factory = new Nette\Bridges\ApplicationLatte\TemplateFactory($latteFactory); -$factory->createTemplate($presenter); - -$latte->setLoader(new Latte\Loaders\StringLoader); - -Assert::matchFile( - __DIR__ . '/expected/UIMacros.isLinkCurrent.php', - $latte->compile( - <<<'XX' - n:href before n:class - - n:href after n:class - - href before n:class - - href after n:class - - {ifCurrent}empty{/ifCurrent} - - {ifCurrent default}default{/ifCurrent} - - custom function - - XX, - ), -); diff --git a/tests/Bridges.Latte2/UIMacros.link.2.phpt b/tests/Bridges.Latte2/UIMacros.link.2.phpt deleted file mode 100644 index 83a441c31..000000000 --- a/tests/Bridges.Latte2/UIMacros.link.2.phpt +++ /dev/null @@ -1,122 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -class MockControl -{ - public function link($destination, $args = []) - { - if (!is_array($args)) { - $args = array_slice(func_get_args(), 1); - } - - array_unshift($args, $destination); - return 'link:' . strtr(json_encode($args), '"', "'"); - } -} - - -class MockPresenter extends MockControl -{ - public function link($destination, $args = []) - { - if (!is_array($args)) { - $args = array_slice(func_get_args(), 1); - } - - array_unshift($args, $destination); - return 'plink:' . strtr(json_encode($args), '"', "'"); - } - - - public function isAjax() - { - return false; - } -} - - -$latte = new Latte\Engine; -$latte->setLoader(new Latte\Loaders\StringLoader); -UIMacros::install($latte->getCompiler()); - -$latte->addProvider('uiControl', new MockControl); -$latte->addProvider('uiPresenter', new MockPresenter); -$params['action'] = 'login'; -$params['arr'] = ['link' => 'login', 'param' => 123]; - -Assert::match(<<<'EOD' - plink:['Homepage:'] - - plink:['Homepage:'] - - plink:['Homepage:action'] - - plink:['Homepage:action'] - - plink:['Homepage:action',10,20,'{one}&two'] - - plink:['Homepage:action#hash',10,20,'{one}&two'] - - plink:['#hash'] - - plink:[':',10] - - plink:{'0':'default','1':10,'a':20,'b':30} - - link:['login'] - - - - - - - - - - - EOD, strtr($latte->renderToString(<<<'EOD' - {plink Homepage:} - - {plink Homepage: } - - {plink Homepage:action } - - {plink 'Homepage:action' } - - {plink Homepage:action 10, 20, '{one}&two'} - - {plink Homepage:action#hash 10, 20, '{one}&two'} - - {plink #hash} - - {plink : 10 } - - {plink default 10, 'a' => 20, 'b' => 30} - - {link $action} - - - - - - - - - - - EOD, $params), [''' => "'", ''' => "'", '{' => '{'])); diff --git a/tests/Bridges.Latte2/UIMacros.link.phpt b/tests/Bridges.Latte2/UIMacros.link.phpt deleted file mode 100644 index 52fda3fb0..000000000 --- a/tests/Bridges.Latte2/UIMacros.link.phpt +++ /dev/null @@ -1,68 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -$latte = new Latte\Engine; -$latte->setLoader(new Latte\Loaders\StringLoader); -UIMacros::install($latte->getCompiler()); - -// {link ...} -Assert::contains( - '$this->global->uiControl->link("p")', - $latte->compile('{link p}'), -); -Assert::contains( - '($this->filters->filter)($this->global->uiControl->link("p"))', - $latte->compile('{link p|filter}'), -); -Assert::contains( - '$this->global->uiControl->link("p:a")', - $latte->compile('{link p:a}'), -); -Assert::contains( - '$this->global->uiControl->link($dest)', - $latte->compile('{link $dest}'), -); -Assert::contains( - '$this->global->uiControl->link($p:$a)', - $latte->compile('{link $p:$a}'), -); -Assert::contains( - '$this->global->uiControl->link("$p:$a")', - $latte->compile('{link "$p:$a"}'), -); -Assert::contains( - '$this->global->uiControl->link("p:a")', - $latte->compile('{link "p:a"}'), -); -Assert::contains( - '$this->global->uiControl->link(\'p:a\')', - $latte->compile('{link \'p:a\'}'), -); - -Assert::contains( - '$this->global->uiControl->link("p", [\'param\'])', - $latte->compile('{link p param}'), -); -Assert::contains( - '$this->global->uiControl->link("p", [\'param\' => 123])', - $latte->compile('{link p param => 123}'), -); -Assert::contains( - '$this->global->uiControl->link("p", [\'param\' => 123])', - $latte->compile('{link p, param => 123}'), -); diff --git a/tests/Bridges.Latte2/UIMacros.renderSnippets.phpt b/tests/Bridges.Latte2/UIMacros.renderSnippets.phpt deleted file mode 100644 index 71c354140..000000000 --- a/tests/Bridges.Latte2/UIMacros.renderSnippets.phpt +++ /dev/null @@ -1,97 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -class InnerControl extends Nette\Application\UI\Control -{ - public function render() - { - $latte = new Latte\Engine; - UIMacros::install($latte->getCompiler()); - $latte->addProvider('uiPresenter', $this->getPresenter()); - $latte->addProvider('uiControl', $this); - $latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($this)); - $params['say'] = 'Hello'; - $latte->render(__DIR__ . '/templates/snippet-included.latte', $params); - } -} - -class TestPresenter extends Nette\Application\UI\Presenter -{ - public function createComponentMulti() - { - return new Nette\Application\UI\Multiplier(function () { - $control = new InnerControl; - $control->redrawControl(); - return $control; - }); - } - - - public function render() - { - $latte = new Latte\Engine; - UIMacros::install($latte->getCompiler()); - $latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($this)); - $latte->render(__DIR__ . '/templates/snippet-include.latte'); - } -} - - -$presenter = new TestPresenter; -$presenter->snippetMode = true; -$presenter->redrawControl(); -$presenter['multi-1']->redrawControl(); -$presenter->render(); -Assert::same([ - 'snippets' => [ - 'snippet--hello' => 'Hello', - 'snippet--include' => "

Included file #3 (A, B)

\n", - 'snippet--array-1' => 'Value 1', - 'snippet--array-2' => 'Value 2', - 'snippet--array-3' => 'Value 3', - 'snippet--array2-1' => 'Value 1', - 'snippet--array2-2' => 'Value 2', - 'snippet--array2-3' => 'Value 3', - 'snippet--includeSay' => 'Hello include snippet', - 'snippet--nested1' => "\t
Foo
\n", - 'snippet-multi-1-includeSay' => 'Hello', - ], -], (array) $presenter->payload); - - - -$presenter = new TestPresenter; -$presenter->snippetMode = true; -$presenter->redrawControl('hello'); -$presenter->redrawControl('array'); -$presenter->render(); - -Assert::same([ - 'snippets' => [ - 'snippet--hello' => 'Hello', - 'snippet--array-1' => 'Value 1', - 'snippet--array-2' => 'Value 2', - 'snippet--array-3' => 'Value 3', - ], -], (array) $presenter->payload); - -$presenter = new TestPresenter; -ob_start(); -$presenter->render(); -$content = ob_get_clean(); -Assert::matchFile(__DIR__ . '/expected/UIMacros.renderSnippets.html', $content); diff --git a/tests/Bridges.Latte2/UIMacros.renderSnippets2.phpt b/tests/Bridges.Latte2/UIMacros.renderSnippets2.phpt deleted file mode 100644 index 58a72d170..000000000 --- a/tests/Bridges.Latte2/UIMacros.renderSnippets2.phpt +++ /dev/null @@ -1,84 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -class InnerControl extends Nette\Application\UI\Control -{ - public function render() - { - $this->renderA(); - $this->renderB(); - } - - - public function renderA() - { - $latte = new Latte\Engine; - $latte->setLoader(new Latte\Loaders\StringLoader); - UIMacros::install($latte->getCompiler()); - $latte->addProvider('uiPresenter', $this->getPresenter()); - $latte->addProvider('uiControl', $this); - $latte->addProvider('snippetBridge', new SnippetBridge($this)); - $params['say'] = 'Hello'; - $latte->render('{snippet testA}{$say}{/snippet}', $params); - } - - - public function renderB() - { - $latte = new Latte\Engine; - $latte->setLoader(new Latte\Loaders\StringLoader); - UIMacros::install($latte->getCompiler()); - $latte->addProvider('uiPresenter', $this->getPresenter()); - $latte->addProvider('uiControl', $this); - $latte->addProvider('snippetBridge', new SnippetBridge($this)); - $params['say'] = 'world'; - $latte->render('{snippet testB}{$say}{/snippet}', $params); - } -} - -class TestPresenter extends Nette\Application\UI\Presenter -{ - public function createComponentMulti() - { - return new Nette\Application\UI\Multiplier(fn() => new InnerControl); - } - - - public function render() - { - $latte = new Latte\Engine; - $latte->setLoader(new Latte\Loaders\StringLoader); - UIMacros::install($latte->getCompiler()); - $latte->addProvider('uiControl', $this); - $latte->addProvider('snippetBridge', new SnippetBridge($this)); - $latte->render(''); - } -} - - -$presenter = new TestPresenter; -$presenter->snippetMode = true; -$presenter['multi-1']->redrawControl(); -$presenter->render(); -Assert::same([ - 'snippets' => [ - 'snippet-multi-1-testA' => 'Hello', - 'snippet-multi-1-testB' => 'world', - ], -], (array) $presenter->payload); diff --git a/tests/Bridges.Latte2/UIMacros.renderSnippets3.phpt b/tests/Bridges.Latte2/UIMacros.renderSnippets3.phpt deleted file mode 100644 index 3dc72672b..000000000 --- a/tests/Bridges.Latte2/UIMacros.renderSnippets3.phpt +++ /dev/null @@ -1,73 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -class TestControl extends Nette\Application\UI\Control -{ - public function render() - { - $latte = new Latte\Engine; - $latte->setLoader(new Latte\Loaders\StringLoader); - UIMacros::install($latte->getCompiler()); - $latte->addProvider('uiPresenter', $this->getPresenter()); - $latte->addProvider('uiControl', $this); - $latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($this)); - $latte->render('{snippet foo}hello{/snippet}'); - } -} - -class TestPresenter extends Nette\Application\UI\Presenter -{ - public function createComponentTest() - { - return new TestControl; - } - - - public function render() - { - $latte = new Latte\Engine; - $latte->setLoader(new Latte\Loaders\StringLoader); - UIMacros::install($latte->getCompiler()); - $latte->addProvider('uiControl', $this); - $latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($this)); - $latte->render('{snippet foo}{control test}{/snippet}'); - } -} - - -$presenter = new TestPresenter; -$presenter->snippetMode = true; -$presenter->redrawControl('foo'); -$presenter['test']->redrawControl('foo'); -$presenter->render(); -Assert::same([ - 'snippets' => [ - 'snippet--foo' => '
hello
', - ], -], (array) $presenter->payload); - - -$presenter = new TestPresenter; -$presenter->snippetMode = true; -$presenter['test']->redrawControl('foo'); -$presenter->render(); -Assert::same([ - 'snippets' => [ - 'snippet-test-foo' => 'hello', - ], -], (array) $presenter->payload); diff --git a/tests/Bridges.Latte2/UIMacros.renderSnippets4.phpt b/tests/Bridges.Latte2/UIMacros.renderSnippets4.phpt deleted file mode 100644 index 917404369..000000000 --- a/tests/Bridges.Latte2/UIMacros.renderSnippets4.phpt +++ /dev/null @@ -1,54 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - - -class TestPresenter extends Nette\Application\UI\Presenter -{ - public function render() - { - $latte = new Latte\Engine; - $latte->setLoader(new Latte\Loaders\StringLoader); - UIMacros::install($latte->getCompiler()); - $latte->addProvider('uiControl', $this); - $latte->addProvider('snippetBridge', new SnippetBridge($this)); - $latte->render('{snippet foo}{php $presenter->renderFoo()}{/snippet}', ['presenter' => $this]); - } - - - public function renderFoo() - { - $latte = new Latte\Engine; - $latte->setLoader(new Latte\Loaders\StringLoader); - UIMacros::install($latte->getCompiler()); - $latte->addProvider('uiControl', $this); - $latte->addProvider('snippetBridge', new SnippetBridge($this)); - $latte->render('Hello'); - } -} - - -$presenter = new TestPresenter; -$presenter->snippetMode = true; -$presenter->redrawControl('foo'); -$presenter->render(); -Assert::same([ - 'snippets' => [ - 'snippet--foo' => 'Hello', - ], -], (array) $presenter->payload); diff --git a/tests/Bridges.Latte2/UIMacros.renderSnippets5.phpt b/tests/Bridges.Latte2/UIMacros.renderSnippets5.phpt deleted file mode 100644 index a915657fe..000000000 --- a/tests/Bridges.Latte2/UIMacros.renderSnippets5.phpt +++ /dev/null @@ -1,59 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - - -class TestPresenter extends Nette\Application\UI\Presenter -{ - public function render(string $template) - { - $latte = new Latte\Engine; - $latte->setLoader(new Latte\Loaders\StringLoader); - UIMacros::install($latte->getCompiler()); - $latte->addProvider('uiControl', $this); - $latte->addProvider('snippetBridge', new SnippetBridge($this)); - $latte->render($template, ['presenter' => $this]); - } -} - - -$presenter = new TestPresenter; -$presenter->snippetMode = true; -$presenter->redrawControl('foo'); -$presenter->render('
Hello
'); -Assert::same([ - 'snippets' => [ - 'snippet--foo' => 'Hello', - ], -], (array) $presenter->payload); - - -$presenter = new TestPresenter; -$presenter->snippetMode = true; -$presenter->redrawControl('foo'); -Assert::exception(function () use ($presenter) { - $presenter->render('
Hello
'); -}, Latte\CompileException::class, 'Cannot combine HTML attribute id with n:snippet.'); - - -$presenter = new TestPresenter; -$presenter->snippetMode = true; -$presenter->redrawControl('foo'); -Assert::exception(function () use ($presenter) { - $presenter->render('
Hello
'); -}, Latte\CompileException::class, 'Cannot combine HTML attribute id with n:snippet.'); diff --git a/tests/Bridges.Latte2/UIMacros.renderSnippets6.phpt b/tests/Bridges.Latte2/UIMacros.renderSnippets6.phpt deleted file mode 100644 index dc4e32a25..000000000 --- a/tests/Bridges.Latte2/UIMacros.renderSnippets6.phpt +++ /dev/null @@ -1,45 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -class TestPresenter extends Nette\Application\UI\Presenter -{ - public function render(string $template) - { - $latte = new Latte\Engine; - $latte->setLoader(new Latte\Loaders\StringLoader); - UIMacros::install($latte->getCompiler()); - $latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($this)); - $latte->onCompile[] = function ($latte) { - $latte->getCompiler()->getMacros()['snippet'][0]->snippetAttribute = 'data-snippet'; - }; - $latte->render($template); - } -} - - -$presenter = new TestPresenter; -ob_start(); -$presenter->render('
hello
'); -$content = ob_get_clean(); -Assert::same('
hello
', $content); - - -$presenter = new TestPresenter; -Assert::exception(function () use ($presenter) { - $presenter->render('
hello
'); -}, Latte\CompileException::class, 'Cannot combine HTML attribute data-snippet with n:snippet.'); diff --git a/tests/Bridges.Latte2/expected/UIMacros.isLinkCurrent.php b/tests/Bridges.Latte2/expected/UIMacros.isLinkCurrent.php deleted file mode 100644 index 15ef390af..000000000 --- a/tests/Bridges.Latte2/expected/UIMacros.isLinkCurrent.php +++ /dev/null @@ -1,22 +0,0 @@ -%A%n:href before n:class - -n:href after n:class - -href before n:class - -href after n:class - -'; - if ($this->global->uiPresenter->getLastCreatedRequestFlag("current")) { - echo 'empty'; - } - echo ' - -'; - if ($this->global->uiPresenter->isLinkCurrent("default")) { - echo 'default'; - } - echo ' - -global->fn->isLinkCurrent)('default') ? 'current' : null%A%>custom function -%A% diff --git a/tests/Bridges.Latte2/expected/UIMacros.renderSnippets.html b/tests/Bridges.Latte2/expected/UIMacros.renderSnippets.html deleted file mode 100644 index 3ff3683ed..000000000 --- a/tests/Bridges.Latte2/expected/UIMacros.renderSnippets.html +++ /dev/null @@ -1,20 +0,0 @@ -
Hello
world! - -

Included file #3 (A, B)

-
- -
Value 1
-
Value 2
-
Value 3
-
- -
Value 1
-
Value 2
-
Value 3
- - -
Hello include snippet
- - -
Foo
-
diff --git a/tests/Bridges.Latte2/templates/include3.latte b/tests/Bridges.Latte2/templates/include3.latte deleted file mode 100644 index 14caf4cb4..000000000 --- a/tests/Bridges.Latte2/templates/include3.latte +++ /dev/null @@ -1 +0,0 @@ -

Included file #3 ({$localvar}, {$hello})

diff --git a/tests/Bridges.Latte2/templates/snippet-include.latte b/tests/Bridges.Latte2/templates/snippet-include.latte deleted file mode 100644 index 8a1ec964d..000000000 --- a/tests/Bridges.Latte2/templates/snippet-include.latte +++ /dev/null @@ -1,25 +0,0 @@ -{snippet hello}Hello{/snippet} world! - -{snippet include} - {include include3.latte localvar => 'A', hello => 'B'} -{/snippet} - -{snippet array} - {foreach [1, 2, 3] as $id} - {snippet "array-$id"}Value {$id}{/snippet} - {/foreach} -{/snippet} - -{snippetArea array2} - {foreach [1, 2, 3] as $id} - {snippet "array2-$id"}Value {$id}{/snippet} - {/foreach} -{/snippetArea} - -{snippetArea foo} - {include snippet-included.latte say => 'Hello include snippet'} -{/snippetArea} - -{snippet nested1} - {snippet nested2}Foo{/snippet} -{/snippet} diff --git a/tests/Bridges.Latte2/templates/snippet-included.latte b/tests/Bridges.Latte2/templates/snippet-included.latte deleted file mode 100644 index a392b6227..000000000 --- a/tests/Bridges.Latte2/templates/snippet-included.latte +++ /dev/null @@ -1 +0,0 @@ -{snippet includeSay}{$say}{/snippet} diff --git a/tests/Bridges.Latte3/Template.getParentName().phpt b/tests/Bridges.Latte3/Template.getParentName().phpt index f007ab01c..37b968809 100644 --- a/tests/Bridges.Latte3/Template.getParentName().phpt +++ b/tests/Bridges.Latte3/Template.getParentName().phpt @@ -6,10 +6,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - Tester\Environment::bypassFinals(); $presenter = Mockery::mock(Nette\Application\UI\Presenter::class) diff --git a/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt b/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt index 976f99b78..a76c9d50e 100644 --- a/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt +++ b/tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt @@ -14,10 +14,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - Tester\Environment::bypassFinals(); diff --git a/tests/Bridges.Latte3/TemplateFactory.filters.phpt b/tests/Bridges.Latte3/TemplateFactory.filters.phpt index 27d45ba94..41b9800ce 100644 --- a/tests/Bridges.Latte3/TemplateFactory.filters.phpt +++ b/tests/Bridges.Latte3/TemplateFactory.filters.phpt @@ -11,10 +11,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class LatteFactory implements Nette\Bridges\ApplicationLatte\LatteFactory { diff --git a/tests/Bridges.Latte3/TemplateFactory.nonce.control.phpt b/tests/Bridges.Latte3/TemplateFactory.nonce.control.phpt index 2a7c94cb2..eee9b1304 100644 --- a/tests/Bridges.Latte3/TemplateFactory.nonce.control.phpt +++ b/tests/Bridges.Latte3/TemplateFactory.nonce.control.phpt @@ -12,10 +12,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latteFactory = Mockery::mock(ApplicationLatte\LatteFactory::class); diff --git a/tests/Bridges.Latte3/TemplateFactory.nonce.presenter.phpt b/tests/Bridges.Latte3/TemplateFactory.nonce.presenter.phpt index 23297efce..e5c2942ef 100644 --- a/tests/Bridges.Latte3/TemplateFactory.nonce.presenter.phpt +++ b/tests/Bridges.Latte3/TemplateFactory.nonce.presenter.phpt @@ -12,10 +12,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - Tester\Environment::bypassFinals(); $latte = new Latte\Engine; diff --git a/tests/Bridges.Latte3/TemplateFactory.onCreate.phpt b/tests/Bridges.Latte3/TemplateFactory.onCreate.phpt index ed6e9b61c..987e86aea 100644 --- a/tests/Bridges.Latte3/TemplateFactory.onCreate.phpt +++ b/tests/Bridges.Latte3/TemplateFactory.onCreate.phpt @@ -14,10 +14,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - test('', function () { $engine = new Latte\Engine; diff --git a/tests/Bridges.Latte3/isLinkCurrent().phpt b/tests/Bridges.Latte3/isLinkCurrent().phpt index b297db9bd..83ee33179 100644 --- a/tests/Bridges.Latte3/isLinkCurrent().phpt +++ b/tests/Bridges.Latte3/isLinkCurrent().phpt @@ -10,10 +10,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - Tester\Environment::bypassFinals(); $latte = new Latte\Engine; diff --git a/tests/Bridges.Latte3/n-snippet.2.phpt b/tests/Bridges.Latte3/n-snippet.2.phpt index 983c46ce5..a5cfc2a20 100644 --- a/tests/Bridges.Latte3/n-snippet.2.phpt +++ b/tests/Bridges.Latte3/n-snippet.2.phpt @@ -6,10 +6,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); $latte->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension(null)); diff --git a/tests/Bridges.Latte3/n-snippet.block.phpt b/tests/Bridges.Latte3/n-snippet.block.phpt index 107dd6ebc..27a83c2f7 100644 --- a/tests/Bridges.Latte3/n-snippet.block.phpt +++ b/tests/Bridges.Latte3/n-snippet.block.phpt @@ -6,10 +6,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); diff --git a/tests/Bridges.Latte3/n-snippet.dynamic.phpt b/tests/Bridges.Latte3/n-snippet.dynamic.phpt index ab2827bca..a794e2d0c 100644 --- a/tests/Bridges.Latte3/n-snippet.dynamic.phpt +++ b/tests/Bridges.Latte3/n-snippet.dynamic.phpt @@ -6,10 +6,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); diff --git a/tests/Bridges.Latte3/n-snippet.phpt b/tests/Bridges.Latte3/n-snippet.phpt index c9ff1b893..ac2247eec 100644 --- a/tests/Bridges.Latte3/n-snippet.phpt +++ b/tests/Bridges.Latte3/n-snippet.phpt @@ -6,9 +6,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} class Test { diff --git a/tests/Bridges.Latte3/renderSnippets.phpt b/tests/Bridges.Latte3/renderSnippets.phpt index 4d5aa565a..1cd05d94a 100644 --- a/tests/Bridges.Latte3/renderSnippets.phpt +++ b/tests/Bridges.Latte3/renderSnippets.phpt @@ -11,10 +11,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class InnerControl extends Nette\Application\UI\Control { diff --git a/tests/Bridges.Latte3/renderSnippets2.phpt b/tests/Bridges.Latte3/renderSnippets2.phpt index f65dc3238..dcd2bbb90 100644 --- a/tests/Bridges.Latte3/renderSnippets2.phpt +++ b/tests/Bridges.Latte3/renderSnippets2.phpt @@ -11,10 +11,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class InnerControl extends Nette\Application\UI\Control { diff --git a/tests/Bridges.Latte3/renderSnippets3.phpt b/tests/Bridges.Latte3/renderSnippets3.phpt index 1139c8a40..c3b0780fe 100644 --- a/tests/Bridges.Latte3/renderSnippets3.phpt +++ b/tests/Bridges.Latte3/renderSnippets3.phpt @@ -11,10 +11,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class TestControl extends Nette\Application\UI\Control { diff --git a/tests/Bridges.Latte3/renderSnippets4.phpt b/tests/Bridges.Latte3/renderSnippets4.phpt index 93d64e3be..90ed7e8ae 100644 --- a/tests/Bridges.Latte3/renderSnippets4.phpt +++ b/tests/Bridges.Latte3/renderSnippets4.phpt @@ -11,10 +11,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class TestPresenter extends Nette\Application\UI\Presenter { diff --git a/tests/Bridges.Latte3/renderSnippets5.phpt b/tests/Bridges.Latte3/renderSnippets5.phpt index c43b680b9..6d1a282c5 100644 --- a/tests/Bridges.Latte3/renderSnippets5.phpt +++ b/tests/Bridges.Latte3/renderSnippets5.phpt @@ -11,10 +11,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class TestPresenter extends Nette\Application\UI\Presenter { diff --git a/tests/Bridges.Latte3/renderSnippets6.phpt b/tests/Bridges.Latte3/renderSnippets6.phpt index b2da961c1..025ec5e8d 100644 --- a/tests/Bridges.Latte3/renderSnippets6.phpt +++ b/tests/Bridges.Latte3/renderSnippets6.phpt @@ -11,10 +11,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class TestPresenter extends Nette\Application\UI\Presenter { diff --git a/tests/Bridges.Latte3/renderSnippets7.phpt b/tests/Bridges.Latte3/renderSnippets7.phpt index fb17b0d54..57ac04b46 100644 --- a/tests/Bridges.Latte3/renderSnippets7.phpt +++ b/tests/Bridges.Latte3/renderSnippets7.phpt @@ -9,10 +9,6 @@ Tester\Environment::bypassFinals(); require __DIR__ . '/ControlMock.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $dataSets = [ diff --git a/tests/Bridges.Latte3/{control}.2.phpt b/tests/Bridges.Latte3/{control}.2.phpt index bb2cb9171..7086c7fd1 100644 --- a/tests/Bridges.Latte3/{control}.2.phpt +++ b/tests/Bridges.Latte3/{control}.2.phpt @@ -10,10 +10,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class MockComponent { diff --git a/tests/Bridges.Latte3/{control}.3.phpt b/tests/Bridges.Latte3/{control}.3.phpt index 7a270383f..d9317b057 100644 --- a/tests/Bridges.Latte3/{control}.3.phpt +++ b/tests/Bridges.Latte3/{control}.3.phpt @@ -10,9 +10,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} $control = new class { public function render() diff --git a/tests/Bridges.Latte3/{control}.phpt b/tests/Bridges.Latte3/{control}.phpt index a1ba85e15..8d78e3546 100644 --- a/tests/Bridges.Latte3/{control}.phpt +++ b/tests/Bridges.Latte3/{control}.phpt @@ -10,10 +10,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); diff --git a/tests/Bridges.Latte3/{ifCurrent}.phpt b/tests/Bridges.Latte3/{ifCurrent}.phpt index 2d2451c50..fa02d0193 100644 --- a/tests/Bridges.Latte3/{ifCurrent}.phpt +++ b/tests/Bridges.Latte3/{ifCurrent}.phpt @@ -6,10 +6,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - Tester\Environment::bypassFinals(); $latte = new Latte\Engine; diff --git a/tests/Bridges.Latte3/{link}.2.phpt b/tests/Bridges.Latte3/{link}.2.phpt index 816283b42..7fc270038 100644 --- a/tests/Bridges.Latte3/{link}.2.phpt +++ b/tests/Bridges.Latte3/{link}.2.phpt @@ -10,10 +10,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class MockControl { diff --git a/tests/Bridges.Latte3/{link}.phpt b/tests/Bridges.Latte3/{link}.phpt index e2457c9a7..9d8e296e6 100644 --- a/tests/Bridges.Latte3/{link}.phpt +++ b/tests/Bridges.Latte3/{link}.phpt @@ -10,10 +10,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); diff --git a/tests/Bridges.Latte3/{snippet}.dynamic.phpt b/tests/Bridges.Latte3/{snippet}.dynamic.phpt index 3b2068ed0..1eb5aacdd 100644 --- a/tests/Bridges.Latte3/{snippet}.dynamic.phpt +++ b/tests/Bridges.Latte3/{snippet}.dynamic.phpt @@ -6,10 +6,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); diff --git a/tests/Bridges.Latte3/{snippet}.phpt b/tests/Bridges.Latte3/{snippet}.phpt index bf9022dce..5afa062ef 100644 --- a/tests/Bridges.Latte3/{snippet}.phpt +++ b/tests/Bridges.Latte3/{snippet}.phpt @@ -6,10 +6,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); From 3cb0eaae1c5039f221c7ca132b0e044ebf5da1a6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 30 Aug 2021 10:18:19 +0200 Subject: [PATCH 24/42] Form: do not send 'do' when action is changed --- src/Application/UI/Form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/UI/Form.php b/src/Application/UI/Form.php index 7f699800d..21b4f785d 100644 --- a/src/Application/UI/Form.php +++ b/src/Application/UI/Form.php @@ -125,7 +125,7 @@ protected function beforeRender() { parent::beforeRender(); $key = ($this->isMethod('post') ? '_' : '') . Presenter::SignalKey; - if (!isset($this[$key])) { + if (!isset($this[$key]) && $this->getAction() !== '') { $do = $this->lookupPath(Presenter::class) . self::NameSeparator . 'submit'; $this[$key] = (new Nette\Forms\Controls\HiddenField($do))->setOmitted(); } From 65529fa77df947adb39e586e1cffabe790001e42 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 24 Jan 2023 01:23:33 +0100 Subject: [PATCH 25/42] Url is always without user info --- src/Application/MicroPresenter.php | 4 ++-- src/Application/UI/Presenter.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 64536e743..94ebde85c 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -52,7 +52,7 @@ public function run(Application\Request $request): Application\Response && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head')) ) { - $refUrl = $this->httpRequest->getUrl()->withoutUserInfo(); + $refUrl = $this->httpRequest->getUrl(); $url = $this->router->constructUrl($request->toArray(), $refUrl); if ($url !== null && !$refUrl->isEqual($url)) { return new Responses\RedirectResponse($url, Http\IResponse::S301_MovedPermanently); @@ -123,7 +123,7 @@ public function createTemplate(?string $class = null, ?callable $latteFactory = $template->presenter = $this; $template->context = $this->context; if ($this->httpRequest) { - $url = $this->httpRequest->getUrl()->withoutUserInfo(); + $url = $this->httpRequest->getUrl(); $template->baseUrl = rtrim($url->getBaseUrl(), '/'); $template->basePath = rtrim($url->getBasePath(), '/'); } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 8f6cd94ea..bff085270 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -700,7 +700,7 @@ public function canonicalize(?string $destination = null, ...$args): void } catch (InvalidLinkException $e) { } - if (!isset($url) || $this->httpRequest->getUrl()->withoutUserInfo()->isEqual($url)) { + if (!isset($url) || $this->httpRequest->getUrl()->isEqual($url)) { return; } @@ -963,7 +963,7 @@ protected function requestToUrl(Application\Request $request, ?bool $relative = { if (!isset($this->refUrlCache)) { $url = $this->httpRequest->getUrl(); - $this->refUrlCache = new Http\UrlScript($url->withoutUserInfo()->getHostUrl() . $url->getScriptPath()); + $this->refUrlCache = new Http\UrlScript($url->getHostUrl() . $url->getScriptPath()); } if (!$this->router) { From 66906e92b18f09d0081383a4b51a075811da3cf9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 12 Sep 2021 23:44:04 +0200 Subject: [PATCH 26/42] Component: only UI components can be added to presenter/component (BC break) WIP --- src/Application/UI/Component.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 5ee05b98b..d47224875 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -66,15 +66,17 @@ public function getUniqueId(): string } - protected function createComponent(string $name): ?Nette\ComponentModel\IComponent + public function addComponent( + Nette\ComponentModel\IComponent $component, + ?string $name, + ?string $insertBefore = null, + ): static { - $res = parent::createComponent($name); - if ($res && !$res instanceof SignalReceiver && !$res instanceof StatePersistent) { - $type = $res::class; - trigger_error("It seems that component '$name' of type $type is not intended to be used in the Presenter.", E_USER_NOTICE); + if (!$component instanceof SignalReceiver && !$component instanceof StatePersistent) { + throw new Nette\InvalidStateException("Component '$name' of type " . get_debug_type($component) . ' is not intended to be used in the Presenter.'); } - return $res; + return parent::addComponent($component, $name, $insertBefore = null); } From ea2da5229d406dff40aa0f9389f4621629598275 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 5 Dec 2022 00:49:39 +0100 Subject: [PATCH 27/42] uppercase constants marked as deprecated --- src/Application/UI/Presenter.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index bff085270..bb6f45d44 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -45,14 +45,31 @@ abstract class Presenter extends Control implements Application\IPresenter FlashKey = '_fid', DefaultAction = 'default'; + /** @deprecated use Presenter::InvalidLinkSilent */ public const INVALID_LINK_SILENT = self::InvalidLinkSilent; + + /** @deprecated use Presenter::InvalidLinkWarning */ public const INVALID_LINK_WARNING = self::InvalidLinkWarning; + + /** @deprecated use Presenter::InvalidLinkException */ public const INVALID_LINK_EXCEPTION = self::InvalidLinkException; + + /** @deprecated use Presenter::InvalidLinkTextual */ public const INVALID_LINK_TEXTUAL = self::InvalidLinkTextual; + + /** @deprecated use Presenter::PresenterKey */ public const PRESENTER_KEY = self::PresenterKey; + + /** @deprecated use Presenter::SignalKey */ public const SIGNAL_KEY = self::SignalKey; + + /** @deprecated use Presenter::ActionKey */ public const ACTION_KEY = self::ActionKey; + + /** @deprecated use Presenter::FlashKey */ public const FLASH_KEY = self::FlashKey; + + /** @deprecated use Presenter::DefaultAction */ public const DEFAULT_ACTION = self::DefaultAction; public int $invalidLinkMode = 0; From b4be5370f60a249de4c7822a651fb6a6084b512e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 24 Sep 2021 14:06:27 +0200 Subject: [PATCH 28/42] deprecated magic properties except for $template & $payload (BC break) --- src/Application/Request.php | 10 +++++----- src/Application/UI/Component.php | 4 ++-- src/Application/UI/ComponentReflection.php | 4 ++-- src/Application/UI/Presenter.php | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Application/Request.php b/src/Application/Request.php index 557db970d..add53ac9f 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -15,11 +15,11 @@ /** * Presenter request. * - * @property string $presenterName - * @property array $parameters - * @property array $post - * @property array $files - * @property string|null $method + * @property-deprecated string $presenterName + * @property-deprecated array $parameters + * @property-deprecated array $post + * @property-deprecated array $files + * @property-deprecated string|null $method */ final class Request { diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index d47224875..ec1770cb3 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -19,8 +19,8 @@ * other child components, and interact with user. Components have properties * for storing their status, and responds to user command. * - * @property-read Presenter $presenter - * @property-read bool $linkCurrent + * @property-deprecated Presenter $presenter + * @property-deprecated bool $linkCurrent */ abstract class Component extends Nette\ComponentModel\Container implements SignalReceiver, StatePersistent, \ArrayAccess { diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index c1aadc34c..e5f11f5a8 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -14,8 +14,8 @@ /** * Helpers for Presenter & Component. - * @property-read string $name - * @property-read string $fileName + * @property-deprecated string $name + * @property-deprecated string $fileName * @internal */ final class ComponentReflection extends \ReflectionClass diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index bb6f45d44..1c5c921e8 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -20,13 +20,13 @@ /** * Presenter component represents a webpage instance. It converts Request to Response. * - * @property-read Nette\Application\Request $request - * @property-read string $action - * @property string $view - * @property string|bool $layout + * @property-deprecated Nette\Application\Request $request + * @property-deprecated string $action + * @property-deprecated string $view + * @property-deprecated string|bool $layout * @property-read \stdClass $payload - * @property-read Nette\Http\Session $session - * @property-read Nette\Security\User $user + * @property-deprecated Nette\Http\Session $session + * @property-deprecated Nette\Security\User $user */ abstract class Presenter extends Control implements Application\IPresenter { From 29548e27ba23bd2bf611710011878e5c5d6a17c5 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 15 Oct 2021 18:14:52 +0200 Subject: [PATCH 29/42] removed support for obsolete inteface Nette\Application\IRouter (replaced by Nette\Routing\Router) --- src/Application/Routers/Route.php | 3 --- src/Application/Routers/RouteList.php | 3 --- src/Application/Routers/SimpleRouter.php | 3 --- src/compatibility-intf.php | 11 ----------- 4 files changed, 20 deletions(-) diff --git a/src/Application/Routers/Route.php b/src/Application/Routers/Route.php index ba611da0e..2e22d9679 100644 --- a/src/Application/Routers/Route.php +++ b/src/Application/Routers/Route.php @@ -187,6 +187,3 @@ public static function path2presenter(string $s): string return $s; } } - - -interface_exists(Nette\Application\IRouter::class); diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index d1f88b7eb..ac6aee9b6 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -141,6 +141,3 @@ public function offsetUnset($index): void $this->modify($index, null); } } - - -interface_exists(Nette\Application\IRouter::class); diff --git a/src/Application/Routers/SimpleRouter.php b/src/Application/Routers/SimpleRouter.php index 35d2c8ad9..2f99c51ba 100644 --- a/src/Application/Routers/SimpleRouter.php +++ b/src/Application/Routers/SimpleRouter.php @@ -38,6 +38,3 @@ public function __construct(array|string $defaults = []) parent::__construct($defaults); } } - - -interface_exists(Nette\Application\IRouter::class); diff --git a/src/compatibility-intf.php b/src/compatibility-intf.php index 5bee25bb1..0d5b2f8ff 100644 --- a/src/compatibility-intf.php +++ b/src/compatibility-intf.php @@ -9,17 +9,6 @@ namespace Nette\Application; -use Nette; - -if (false) { - /** @deprecated use Nette\Routing\Router */ - interface IRouter extends Nette\Routing\Router - { - } -} elseif (!interface_exists(IRouter::class)) { - class_alias(Nette\Routing\Router::class, IRouter::class); -} - if (false) { /** @deprecated use Nette\Application\Response */ interface IResponse extends Response From dd28fa31034bffac5e393f3c27650022c1fc9fb0 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 15 Oct 2021 18:19:42 +0200 Subject: [PATCH 30/42] RouteList: array access is deprecated --- src/Application/Routers/RouteList.php | 10 ++++++++++ tests/Bridges.DI/RoutingExtension.basic.phpt | 7 ++++--- tests/Routers/RouteList.basic.phpt | 3 +-- tests/Routers/RouteList.modules.phpt | 5 ++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index ac6aee9b6..72c024fc1 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -97,6 +97,13 @@ public function getModule(): ?string */ public function offsetSet($index, $router): void { + if ($router instanceof Route) { + trigger_error('Usage `$router[] = new Route(...)` is deprecated, use `$router->addRoute(...)`.', E_USER_DEPRECATED); + } else { + $class = getclass($router); + trigger_error("Usage `\$router[] = new $class` is deprecated, use `\$router->add(new $class)`.", E_USER_DEPRECATED); + } + if ($index === null) { $this->add($router); } else { @@ -111,6 +118,7 @@ public function offsetSet($index, $router): void */ public function offsetGet($index): mixed { + trigger_error('Usage `$route = $router[...]` is deprecated, use `$router->getRouters()`.', E_USER_DEPRECATED); if (!$this->offsetExists($index)) { throw new Nette\OutOfRangeException('Offset invalid or out of range'); } @@ -124,6 +132,7 @@ public function offsetGet($index): mixed */ public function offsetExists($index): bool { + trigger_error('Usage `isset($router[...])` is deprecated.', E_USER_DEPRECATED); return is_int($index) && $index >= 0 && $index < count($this->getRouters()); } @@ -134,6 +143,7 @@ public function offsetExists($index): bool */ public function offsetUnset($index): void { + trigger_error('Usage `unset($router[$index])` is deprecated, use `$router->modify($index, null)`.', E_USER_DEPRECATED); if (!$this->offsetExists($index)) { throw new Nette\OutOfRangeException('Offset invalid or out of range'); } diff --git a/tests/Bridges.DI/RoutingExtension.basic.phpt b/tests/Bridges.DI/RoutingExtension.basic.phpt index a8e13d1a6..0b6f57a72 100644 --- a/tests/Bridges.DI/RoutingExtension.basic.phpt +++ b/tests/Bridges.DI/RoutingExtension.basic.phpt @@ -31,9 +31,10 @@ test('', function () { $container = new Container1; $router = $container->getService('router'); Assert::type(Nette\Application\Routers\RouteList::class, $router); - Assert::same('index.php', $router[0]->getMask()); - Assert::same('item/', $router[1]->getMask()); + $routes = $router->getRouters(); + Assert::same('index.php', $routes[0]->getMask()); + Assert::same('item/', $routes[1]->getMask()); Assert::type(Nette\Application\Routers\RouteList::class, $router); - Assert::type(Nette\Application\Routers\Route::class, $router[0]); + Assert::type(Nette\Application\Routers\Route::class, $routes[0]); }); diff --git a/tests/Routers/RouteList.basic.phpt b/tests/Routers/RouteList.basic.phpt index 22afeda6c..b4783db95 100644 --- a/tests/Routers/RouteList.basic.phpt +++ b/tests/Routers/RouteList.basic.phpt @@ -6,7 +6,6 @@ declare(strict_types=1); -use Nette\Application\Routers\Route; use Nette\Application\Routers\RouteList; use Tester\Assert; @@ -17,7 +16,7 @@ require __DIR__ . '/Route.php'; $list = new RouteList; -$list[] = new Route('//'); +$list->addRoute('//'); Assert::same('http://example.com/front.homepage/', testRouteOut($list, ['presenter' => 'Front:Homepage'])); diff --git a/tests/Routers/RouteList.modules.phpt b/tests/Routers/RouteList.modules.phpt index db2aff0d2..ff1e15193 100644 --- a/tests/Routers/RouteList.modules.phpt +++ b/tests/Routers/RouteList.modules.phpt @@ -6,7 +6,6 @@ declare(strict_types=1); -use Nette\Application\Routers\Route; use Nette\Application\Routers\RouteList; @@ -16,12 +15,12 @@ require __DIR__ . '/Route.php'; $list = new RouteList; -$list[] = new Route('auth/[/]', [ +$list->addRoute('auth/[/]', [ 'module' => 'Auth', 'presenter' => 'Homepage', 'action' => 'default', ]); -$list[] = new Route('[/]', [ +$list->addRoute('[/]', [ 'module' => 'Default', 'presenter' => 'Homepage', 'action' => 'default', From ebbeb27a2e74a24200f7c772de9a1698e17bfc80 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 20 Oct 2021 01:53:14 +0200 Subject: [PATCH 31/42] Component::link() & etc uses variadic parameter --- src/Application/UI/Component.php | 50 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index ec1770cb3..8ede367dd 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -243,15 +243,15 @@ public static function formatSignalMethod(string $signal): string /** * Generates URL to presenter, action or signal. * @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]" - * @param array|mixed $args + * @param mixed ...$args * @throws InvalidLinkException */ - public function link(string $destination, $args = []): string + public function link(string $destination, ...$args): string { try { - $args = func_num_args() < 3 && is_array($args) - ? $args - : array_slice(func_get_args(), 1); + $args = count($args) === 1 && is_array($args[0] ?? null) + ? $args[0] + : $args; return $this->getPresenter()->createRequest($this, $destination, $args, 'link'); } catch (InvalidLinkException $e) { @@ -263,13 +263,13 @@ public function link(string $destination, $args = []): string /** * Returns destination as Link object. * @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]" - * @param array|mixed $args + * @param mixed ...$args */ - public function lazyLink(string $destination, $args = []): Link + public function lazyLink(string $destination, ...$args): Link { - $args = func_num_args() < 3 && is_array($args) - ? $args - : array_slice(func_get_args(), 1); + $args = count($args) === 1 && is_array($args[0] ?? null) + ? $args[0] + : $args; return new Link($this, $destination, $args); } @@ -277,15 +277,15 @@ public function lazyLink(string $destination, $args = []): Link /** * Determines whether it links to the current page. * @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]" - * @param array|mixed $args + * @param mixed ...$args * @throws InvalidLinkException */ - public function isLinkCurrent(?string $destination = null, $args = []): bool + public function isLinkCurrent(?string $destination = null, ...$args): bool { if ($destination !== null) { - $args = func_num_args() < 3 && is_array($args) - ? $args - : array_slice(func_get_args(), 1); + $args = count($args) === 1 && is_array($args[0] ?? null) + ? $args[0] + : $args; $this->getPresenter()->createRequest($this, $destination, $args, 'test'); } @@ -296,15 +296,15 @@ public function isLinkCurrent(?string $destination = null, $args = []): bool /** * Redirect to another presenter, action or signal. * @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]" - * @param array|mixed $args + * @param mixed ...$args * @return never * @throws Nette\Application\AbortException */ - public function redirect(string $destination, $args = []): void + public function redirect(string $destination, ...$args): void { - $args = func_num_args() < 3 && is_array($args) - ? $args - : array_slice(func_get_args(), 1); + $args = count($args) === 1 && is_array($args[0] ?? null) + ? $args[0] + : $args; $presenter = $this->getPresenter(); $presenter->redirectUrl($presenter->createRequest($this, $destination, $args, 'redirect')); } @@ -313,15 +313,15 @@ public function redirect(string $destination, $args = []): void /** * Permanently redirects to presenter, action or signal. * @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]" - * @param array|mixed $args + * @param mixed ...$args * @return never * @throws Nette\Application\AbortException */ - public function redirectPermanent(string $destination, $args = []): void + public function redirectPermanent(string $destination, ...$args): void { - $args = func_num_args() < 3 && is_array($args) - ? $args - : array_slice(func_get_args(), 1); + $args = count($args) === 1 && is_array($args[0] ?? null) + ? $args[0] + : $args; $presenter = $this->getPresenter(); $presenter->redirectUrl( $presenter->createRequest($this, $destination, $args, 'redirect'), From cc8d2a8a4444426dcfa7eb84e6ecf257ab7f8949 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 13 Nov 2021 16:44:20 +0100 Subject: [PATCH 32/42] Request: removed flag SECURED (BC break) --- src/Application/Application.php | 1 - src/Application/Request.php | 3 --- 2 files changed, 4 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index 2fbde802a..02448197b 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -114,7 +114,6 @@ public function createInitialRequest(): Request $params, $this->httpRequest->getPost(), $this->httpRequest->getFiles(), - [Request::SECURED => $this->httpRequest->isSecured()], ); } diff --git a/src/Application/Request.php b/src/Application/Request.php index add53ac9f..4d6d467ce 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -28,9 +28,6 @@ final class Request /** method */ public const FORWARD = 'FORWARD'; - /** flag */ - public const SECURED = 'secured'; - /** flag */ public const RESTORED = 'restored'; From 8147ef3199489632aa0ca0cecd983d17cc461a1b Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 2 Oct 2023 18:17:07 +0200 Subject: [PATCH 33/42] SnippetDriver renamed to SnippetRuntime --- src/Bridges/ApplicationLatte/Nodes/SnippetAreaNode.php | 4 ++-- src/Bridges/ApplicationLatte/Nodes/SnippetNode.php | 4 ++-- .../{SnippetDriver.php => SnippetRuntime.php} | 2 +- src/Bridges/ApplicationLatte/UIExtension.php | 2 +- tests/Bridges.Latte3/renderSnippets7.phpt | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) rename src/Bridges/ApplicationLatte/{SnippetDriver.php => SnippetRuntime.php} (99%) diff --git a/src/Bridges/ApplicationLatte/Nodes/SnippetAreaNode.php b/src/Bridges/ApplicationLatte/Nodes/SnippetAreaNode.php index 0f23c4b03..546518592 100644 --- a/src/Bridges/ApplicationLatte/Nodes/SnippetAreaNode.php +++ b/src/Bridges/ApplicationLatte/Nodes/SnippetAreaNode.php @@ -19,7 +19,7 @@ use Latte\Compiler\Tag; use Latte\Compiler\TemplateParser; use Latte\Runtime\Template; -use Nette\Bridges\ApplicationLatte\SnippetDriver; +use Nette\Bridges\ApplicationLatte\SnippetRuntime; /** @@ -67,7 +67,7 @@ public function print(PrintContext $context): string XX, $this->block->name, - SnippetDriver::TypeArea, + SnippetRuntime::TypeArea, $this->content, ); diff --git a/src/Bridges/ApplicationLatte/Nodes/SnippetNode.php b/src/Bridges/ApplicationLatte/Nodes/SnippetNode.php index 3ea8d3b01..989b887b3 100644 --- a/src/Bridges/ApplicationLatte/Nodes/SnippetNode.php +++ b/src/Bridges/ApplicationLatte/Nodes/SnippetNode.php @@ -22,7 +22,7 @@ use Latte\Compiler\Tag; use Latte\Compiler\TemplateParser; use Latte\Runtime\Template; -use Nette\Bridges\ApplicationLatte\SnippetDriver; +use Nette\Bridges\ApplicationLatte\SnippetRuntime; /** @@ -128,7 +128,7 @@ private function printContent(PrintContext $context, AreaNode $inner): string XX, $dynamic ? new AuxiliaryNode(fn() => '$ʟ_nm') : $this->block->name, - $dynamic ? SnippetDriver::TypeDynamic : SnippetDriver::TypeStatic, + $dynamic ? SnippetRuntime::TypeDynamic : SnippetRuntime::TypeStatic, $this->position, $inner, ); diff --git a/src/Bridges/ApplicationLatte/SnippetDriver.php b/src/Bridges/ApplicationLatte/SnippetRuntime.php similarity index 99% rename from src/Bridges/ApplicationLatte/SnippetDriver.php rename to src/Bridges/ApplicationLatte/SnippetRuntime.php index 776c88291..42d9459a5 100644 --- a/src/Bridges/ApplicationLatte/SnippetDriver.php +++ b/src/Bridges/ApplicationLatte/SnippetRuntime.php @@ -18,7 +18,7 @@ * Latte v3 snippet driver * @internal */ -final class SnippetDriver +final class SnippetRuntime { public const TypeStatic = 'static', diff --git a/src/Bridges/ApplicationLatte/UIExtension.php b/src/Bridges/ApplicationLatte/UIExtension.php index 3e7584ffa..5118a37a1 100644 --- a/src/Bridges/ApplicationLatte/UIExtension.php +++ b/src/Bridges/ApplicationLatte/UIExtension.php @@ -46,7 +46,7 @@ public function getProviders(): array 'coreParentFinder' => [$this, 'findLayoutTemplate'], 'uiControl' => $this->control, 'uiPresenter' => $presenter, - 'snippetDriver' => $this->control ? new SnippetDriver($this->control) : null, + 'snippetDriver' => $this->control ? new SnippetRuntime($this->control) : null, 'uiNonce' => $httpResponse ? $this->findNonce($httpResponse) : null, ]; } diff --git a/tests/Bridges.Latte3/renderSnippets7.phpt b/tests/Bridges.Latte3/renderSnippets7.phpt index 57ac04b46..a7689c434 100644 --- a/tests/Bridges.Latte3/renderSnippets7.phpt +++ b/tests/Bridges.Latte3/renderSnippets7.phpt @@ -195,7 +195,7 @@ foreach ($dataSets as $data) { $engine = new Latte\Engine; $engine->setLoader(new Latte\Loaders\StringLoader($data[0])); $engine->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension(null)); - $engine->addProvider('snippetDriver', new Nette\Bridges\ApplicationLatte\SnippetDriver($control)); + $engine->addProvider('snippetDriver', new Nette\Bridges\ApplicationLatte\SnippetRuntime($control)); $engine->render('main'); Assert::same($data[1], $control->payload); @@ -208,7 +208,7 @@ foreach ($dataSets as $data) { $engine = new Latte\Engine; $engine->setLoader(new Latte\Loaders\StringLoader($data[0])); $engine->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension(null)); - $engine->addProvider('snippetDriver', new Nette\Bridges\ApplicationLatte\SnippetDriver($control)); + $engine->addProvider('snippetDriver', new Nette\Bridges\ApplicationLatte\SnippetRuntime($control)); $result = $engine->renderToString('main'); From 6e67cfb2e03853ff2c7810374a979279e0e2ff80 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 4 May 2022 12:57:58 +0200 Subject: [PATCH 34/42] Presenter::injectPrimary() changing the order of parameters (BC break) --- src/Application/UI/Presenter.php | 5 ++--- tests/Application/Application.run.phpt | 4 ++-- tests/Application/Presenter.twoDomains.phpt | 5 ++--- tests/Bridges.Latte3/renderSnippets.phpt | 6 +++--- tests/Bridges.Latte3/renderSnippets2.phpt | 2 +- tests/Bridges.Latte3/renderSnippets3.phpt | 4 ++-- tests/Bridges.Latte3/renderSnippets4.phpt | 2 +- tests/Bridges.Latte3/renderSnippets5.phpt | 6 +++--- tests/Bridges.Latte3/renderSnippets6.phpt | 4 ++-- tests/UI/Component.isLinkCurrent().asserts.php | 5 ++--- tests/UI/Component.redirect().phpt | 5 ++--- tests/UI/Presenter.link().persistent.phpt | 5 ++--- tests/UI/Presenter.link().php74.phpt | 5 ++--- tests/UI/Presenter.link().phpt | 5 ++--- tests/UI/Presenter.paramChecking.phpt | 5 ++--- tests/UI/Presenter.parameters.phpt | 2 +- tests/UI/Presenter.storeRequest().phpt | 10 ++++------ 17 files changed, 35 insertions(+), 45 deletions(-) diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 1c5c921e8..1b3022236 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -1366,11 +1366,10 @@ public function getFlashSession(): Http\SessionSection final public function injectPrimary( - ?Nette\DI\Container $context, - ?Application\IPresenterFactory $presenterFactory, - ?Nette\Routing\Router $router, Http\IRequest $httpRequest, Http\IResponse $httpResponse, + ?Application\IPresenterFactory $presenterFactory = null, + ?Nette\Routing\Router $router = null, ?Http\Session $session = null, ?Nette\Security\User $user = null, ?TemplateFactory $templateFactory = null, diff --git a/tests/Application/Application.run.phpt b/tests/Application/Application.run.phpt index d1fbad045..7a5f2aa1e 100644 --- a/tests/Application/Application.run.phpt +++ b/tests/Application/Application.run.phpt @@ -340,8 +340,8 @@ Assert::noError(function () use ($httpRequest, $httpResponse) { $errors = []; - $presenter->injectPrimary(null, $presenterFactory, $router, $httpRequest, $httpResponse); - $errorPresenter->injectPrimary(null, $presenterFactory, $router, $httpRequest, $httpResponse); + $presenter->injectPrimary($httpRequest, $httpResponse, $presenterFactory, $router); + $errorPresenter->injectPrimary($httpRequest, $httpResponse, $presenterFactory, $router); $app = new Application($presenterFactory, $router, $httpRequest, $httpResponse); $app->catchExceptions = true; diff --git a/tests/Application/Presenter.twoDomains.phpt b/tests/Application/Presenter.twoDomains.phpt index 46943d99c..c3128a8ef 100644 --- a/tests/Application/Presenter.twoDomains.phpt +++ b/tests/Application/Presenter.twoDomains.phpt @@ -28,11 +28,10 @@ function testLink($domain) $presenter = new TestPresenter; $presenter->injectPrimary( - null, - Mockery::mock(Nette\Application\IPresenterFactory::class), - new Application\Routers\SimpleRouter, new Http\Request($url), new Http\Response, + Mockery::mock(Nette\Application\IPresenterFactory::class), + new Application\Routers\SimpleRouter, ); $request = new Application\Request('Test', Http\Request::Get, []); diff --git a/tests/Bridges.Latte3/renderSnippets.phpt b/tests/Bridges.Latte3/renderSnippets.phpt index 1cd05d94a..4d113171f 100644 --- a/tests/Bridges.Latte3/renderSnippets.phpt +++ b/tests/Bridges.Latte3/renderSnippets.phpt @@ -45,7 +45,7 @@ class TestPresenter extends Nette\Application\UI\Presenter $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); $presenter->snippetMode = true; $presenter->redrawControl(); $presenter['multi-1']->redrawControl(); @@ -69,7 +69,7 @@ Assert::same([ $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); $presenter->snippetMode = true; $presenter->redrawControl('hello'); $presenter->redrawControl('array'); @@ -85,7 +85,7 @@ Assert::same([ ], (array) $presenter->payload); $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); ob_start(); $presenter->render(); $content = ob_get_clean(); diff --git a/tests/Bridges.Latte3/renderSnippets2.phpt b/tests/Bridges.Latte3/renderSnippets2.phpt index dcd2bbb90..1a092d470 100644 --- a/tests/Bridges.Latte3/renderSnippets2.phpt +++ b/tests/Bridges.Latte3/renderSnippets2.phpt @@ -60,7 +60,7 @@ class TestPresenter extends Nette\Application\UI\Presenter $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); $presenter->snippetMode = true; $presenter['multi-1']->redrawControl(); $presenter->render(); diff --git a/tests/Bridges.Latte3/renderSnippets3.phpt b/tests/Bridges.Latte3/renderSnippets3.phpt index c3b0780fe..65a621014 100644 --- a/tests/Bridges.Latte3/renderSnippets3.phpt +++ b/tests/Bridges.Latte3/renderSnippets3.phpt @@ -42,7 +42,7 @@ class TestPresenter extends Nette\Application\UI\Presenter $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); $presenter->snippetMode = true; $presenter->redrawControl('foo'); $presenter['test']->redrawControl('foo'); @@ -55,7 +55,7 @@ Assert::same([ $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); $presenter->snippetMode = true; $presenter['test']->redrawControl('foo'); $presenter->render(); diff --git a/tests/Bridges.Latte3/renderSnippets4.phpt b/tests/Bridges.Latte3/renderSnippets4.phpt index 90ed7e8ae..c209301c6 100644 --- a/tests/Bridges.Latte3/renderSnippets4.phpt +++ b/tests/Bridges.Latte3/renderSnippets4.phpt @@ -34,7 +34,7 @@ class TestPresenter extends Nette\Application\UI\Presenter $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); $presenter->snippetMode = true; $presenter->redrawControl('foo'); $presenter->render(); diff --git a/tests/Bridges.Latte3/renderSnippets5.phpt b/tests/Bridges.Latte3/renderSnippets5.phpt index 6d1a282c5..340e36cf6 100644 --- a/tests/Bridges.Latte3/renderSnippets5.phpt +++ b/tests/Bridges.Latte3/renderSnippets5.phpt @@ -25,7 +25,7 @@ class TestPresenter extends Nette\Application\UI\Presenter $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); $presenter->snippetMode = true; $presenter->redrawControl('foo'); $presenter->render('
Hello
'); @@ -37,7 +37,7 @@ Assert::same([ $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); $presenter->snippetMode = true; $presenter->redrawControl('foo'); Assert::exception( @@ -49,7 +49,7 @@ Assert::exception( $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); $presenter->snippetMode = true; $presenter->redrawControl('foo'); Assert::exception( diff --git a/tests/Bridges.Latte3/renderSnippets6.phpt b/tests/Bridges.Latte3/renderSnippets6.phpt index 025ec5e8d..a9cda7417 100644 --- a/tests/Bridges.Latte3/renderSnippets6.phpt +++ b/tests/Bridges.Latte3/renderSnippets6.phpt @@ -26,7 +26,7 @@ class TestPresenter extends Nette\Application\UI\Presenter $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); ob_start(); $presenter->render('
hello
'); $content = ob_get_clean(); @@ -34,7 +34,7 @@ Assert::same('
hello
', $content); $presenter = new TestPresenter; -$presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript('/')), new Http\Response); +$presenter->injectPrimary(new Http\Request(new Http\UrlScript('/')), new Http\Response); Assert::exception( fn() => $presenter->render('
hello
'), Latte\CompileException::class, diff --git a/tests/UI/Component.isLinkCurrent().asserts.php b/tests/UI/Component.isLinkCurrent().asserts.php index 54be8d233..817b8132a 100644 --- a/tests/UI/Component.isLinkCurrent().asserts.php +++ b/tests/UI/Component.isLinkCurrent().asserts.php @@ -31,11 +31,10 @@ function callIsComponentLinkCurrent( $presenterFactory->shouldReceive('getPresenterClass')->andReturn('TestPresenter'); $presenter->injectPrimary( - null, - $presenterFactory, - new Application\Routers\SimpleRouter, new Http\Request($url), new Http\Response, + $presenterFactory, + new Application\Routers\SimpleRouter, ); $presenter->onStartup[] = function () use (&$res, $component, $destination, $args) { $res = $component->isLinkCurrent($destination, $args); diff --git a/tests/UI/Component.redirect().phpt b/tests/UI/Component.redirect().phpt index 1894fe1ed..f6abd0efd 100644 --- a/tests/UI/Component.redirect().phpt +++ b/tests/UI/Component.redirect().phpt @@ -34,11 +34,10 @@ class TestPresenter extends Application\UI\Presenter $presenter = new TestPresenter; $presenter->setParent(null, 'test'); $presenter->injectPrimary( - null, - null, - new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript('http://localhost')), new Http\Response, + null, + new Application\Routers\SimpleRouter, ); diff --git a/tests/UI/Presenter.link().persistent.phpt b/tests/UI/Presenter.link().persistent.phpt index 8bf8e73c0..6aacf49c0 100644 --- a/tests/UI/Presenter.link().persistent.phpt +++ b/tests/UI/Presenter.link().persistent.phpt @@ -142,11 +142,10 @@ $presenterFactory->shouldReceive('getPresenterClass') $presenter = new TestPresenter; $presenter->injectPrimary( - null, - $presenterFactory, - new Application\Routers\SimpleRouter, new Http\Request($url), new Http\Response, + $presenterFactory, + new Application\Routers\SimpleRouter, ); $presenter->invalidLinkMode = TestPresenter::InvalidLinkWarning; diff --git a/tests/UI/Presenter.link().php74.phpt b/tests/UI/Presenter.link().php74.phpt index a48cae932..6b9f6a488 100644 --- a/tests/UI/Presenter.link().php74.phpt +++ b/tests/UI/Presenter.link().php74.phpt @@ -308,11 +308,10 @@ $presenterFactory->shouldReceive('getPresenterClass') $presenter = new TestPresenter; $presenter->injectPrimary( - null, - $presenterFactory, - new Application\Routers\SimpleRouter, new Http\Request($url), new Http\Response, + $presenterFactory, + new Application\Routers\SimpleRouter, ); $presenter->invalidLinkMode = TestPresenter::InvalidLinkWarning; diff --git a/tests/UI/Presenter.link().phpt b/tests/UI/Presenter.link().phpt index 0d1993ef7..2e5e93bed 100644 --- a/tests/UI/Presenter.link().phpt +++ b/tests/UI/Presenter.link().phpt @@ -294,11 +294,10 @@ $presenterFactory->shouldReceive('getPresenterClass') $presenter = new TestPresenter; $presenter->injectPrimary( - null, - $presenterFactory, - new Application\Routers\SimpleRouter, new Http\Request($url), new Http\Response, + $presenterFactory, + new Application\Routers\SimpleRouter, ); $presenter->invalidLinkMode = TestPresenter::InvalidLinkWarning; diff --git a/tests/UI/Presenter.paramChecking.phpt b/tests/UI/Presenter.paramChecking.phpt index db14d7baf..dd433575d 100644 --- a/tests/UI/Presenter.paramChecking.phpt +++ b/tests/UI/Presenter.paramChecking.phpt @@ -17,11 +17,10 @@ require __DIR__ . '/../bootstrap.php'; $presenter = new ParamPresenter; $presenter->injectPrimary( - null, - null, - new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), new Http\Response, + null, + new Application\Routers\SimpleRouter, ); diff --git a/tests/UI/Presenter.parameters.phpt b/tests/UI/Presenter.parameters.phpt index 945eed562..f5b793fe3 100644 --- a/tests/UI/Presenter.parameters.phpt +++ b/tests/UI/Presenter.parameters.phpt @@ -36,7 +36,7 @@ class TestPresenter extends Application\UI\Presenter function createPresenter() { $presenter = new TestPresenter; - $presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript), new Http\Response); + $presenter->injectPrimary(new Http\Request(new Http\UrlScript), new Http\Response); $presenter->autoCanonicalize = false; return $presenter; } diff --git a/tests/UI/Presenter.storeRequest().phpt b/tests/UI/Presenter.storeRequest().phpt index e25726643..ae445d46a 100644 --- a/tests/UI/Presenter.storeRequest().phpt +++ b/tests/UI/Presenter.storeRequest().phpt @@ -120,11 +120,10 @@ class MockUser extends Security\User test('', function () { $presenter = new TestPresenter; $presenter->injectPrimary( - null, - null, - new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), new Http\Response, + null, + new Application\Routers\SimpleRouter, $session = new MockSession, $user = new MockUser, ); @@ -147,11 +146,10 @@ test('', function () { test('', function () { $presenter = new TestPresenter; $presenter->injectPrimary( - null, - null, - new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), new Http\Response, + null, + new Application\Routers\SimpleRouter, $session = new MockSession, ); From bfff2ee940ccf3bdb4b08900d12ed84a7b97ce34 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 21 Jun 2022 15:27:13 +0200 Subject: [PATCH 35/42] Component::getParameter() $default is deprecated --- src/Application/UI/Component.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 8ede367dd..3ea844ec7 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -187,6 +187,7 @@ public function saveState(array &$params): void final public function getParameter(string $name): mixed { if (func_num_args() > 1) { + trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED); $default = func_get_arg(1); } return $this->params[$name] ?? $default ?? null; From bc077326733ab14425a796c1d8fa73c1597dcc42 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 2 Oct 2023 18:48:23 +0200 Subject: [PATCH 36/42] ComponentReflection: merged getParameterType & getPropertyType --- src/Application/UI/ComponentReflection.php | 31 +++++++------------ src/Application/UI/Presenter.php | 2 +- tests/UI/ComponentReflection.combineArgs.phpt | 20 ++++++------ tests/UI/Presenter.link().phpt | 20 ++++++------ tests/UI/Presenter.paramChecking.phpt | 2 +- 5 files changed, 33 insertions(+), 42 deletions(-) diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index e5f11f5a8..bc9a1e3d0 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -42,7 +42,6 @@ public function getParameters(): array $params = []; $isPresenter = $this->isSubclassOf(Presenter::class); - $defaults = $this->getDefaultProperties(); foreach ($this->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) { if ($prop->isStatic()) { continue; @@ -50,10 +49,9 @@ public function getParameters(): array self::parseAnnotation($prop, 'persistent') || $prop->getAttributes(Nette\Application\Attributes\Persistent::class) ) { - $default = $defaults[$prop->getName()] ?? null; $params[$prop->getName()] = [ - 'def' => $default, - 'type' => self::getPropertyType($prop, $default), + 'def' => $prop->getDefaultValue(), + 'type' => self::getType($prop), 'since' => $isPresenter ? Nette\Utils\Reflection::getPropertyDeclaringClass($prop)->getName() : null, ]; } elseif ($prop->getAttributes(Nette\Application\Attributes\Parameter::class)) { @@ -174,7 +172,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a $res = []; foreach ($method->getParameters() as $i => $param) { $name = $param->getName(); - $type = self::getParameterType($param); + $type = self::getType($param); if (isset($args[$name])) { $res[$i] = $args[$name]; if (!self::convertType($res[$i], $type)) { @@ -284,22 +282,15 @@ public static function parseAnnotation(\Reflector $ref, string $name): ?array } - public static function getParameterType(\ReflectionParameter $param): string + public static function getType(\ReflectionParameter|\ReflectionProperty $item): string { - $default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null; - $type = $param->getType(); - return $type - ? ($type instanceof \ReflectionNamedType ? $type->getName() : (string) $type) - : ($default === null ? 'scalar' : get_debug_type($default)); - } - - - public static function getPropertyType(\ReflectionProperty $prop, $default): string - { - $type = $prop->getType(); - return $type - ? ($type instanceof \ReflectionNamedType ? $type->getName() : (string) $type) - : ($default === null ? 'scalar' : get_debug_type($default)); + if ($type = $item->getType()) { + return (string) $type; + } + $default = $item instanceof \ReflectionProperty || $item->isDefaultValueAvailable() + ? $item->getDefaultValue() + : null; + return $default === null ? 'scalar' : get_debug_type($default); } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 1b3022236..d645c9e05 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -1023,7 +1023,7 @@ public static function argsToParams( $i = 0; $rm = new \ReflectionMethod($class, $method); foreach ($rm->getParameters() as $param) { - $type = ComponentReflection::getParameterType($param); + $type = ComponentReflection::getType($param); $name = $param->getName(); if (array_key_exists($i, $args)) { diff --git a/tests/UI/ComponentReflection.combineArgs.phpt b/tests/UI/ComponentReflection.combineArgs.phpt index aa22439b6..f4153a359 100644 --- a/tests/UI/ComponentReflection.combineArgs.phpt +++ b/tests/UI/ComponentReflection.combineArgs.phpt @@ -143,31 +143,31 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '']), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNulls() must be int, string given.', + 'Argument $int passed to MyPresenter::hintsNulls() must be ?int, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => new stdClass]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNulls() must be int, stdClass given.', + 'Argument $int passed to MyPresenter::hintsNulls() must be ?int, stdClass given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => []]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNulls() must be int, array given.', + 'Argument $int passed to MyPresenter::hintsNulls() must be ?int, array given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), Nette\InvalidArgumentException::class, - 'Argument $bool passed to MyPresenter::hintsNulls() must be bool, string given.', + 'Argument $bool passed to MyPresenter::hintsNulls() must be ?bool, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), Nette\InvalidArgumentException::class, - 'Argument $arr passed to MyPresenter::hintsNulls() must be array, string given.', + 'Argument $arr passed to MyPresenter::hintsNulls() must be ?array, string given.', ); }); @@ -183,31 +183,31 @@ test('', function () { Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '']), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNullable() must be int, string given.', + 'Argument $int passed to MyPresenter::hintsNullable() must be ?int, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => new stdClass]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNullable() must be int, stdClass given.', + 'Argument $int passed to MyPresenter::hintsNullable() must be ?int, stdClass given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => []]), Nette\InvalidArgumentException::class, - 'Argument $int passed to MyPresenter::hintsNullable() must be int, array given.', + 'Argument $int passed to MyPresenter::hintsNullable() must be ?int, array given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '']), Nette\InvalidArgumentException::class, - 'Argument $bool passed to MyPresenter::hintsNullable() must be bool, string given.', + 'Argument $bool passed to MyPresenter::hintsNullable() must be ?bool, string given.', ); Assert::exception( fn() => Reflection::combineArgs($method, ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => '']), Nette\InvalidArgumentException::class, - 'Argument $arr passed to MyPresenter::hintsNullable() must be array, string given.', + 'Argument $arr passed to MyPresenter::hintsNullable() must be ?array, string given.', ); }); diff --git a/tests/UI/Presenter.link().phpt b/tests/UI/Presenter.link().phpt index 2e5e93bed..99d0ebea0 100644 --- a/tests/UI/Presenter.link().phpt +++ b/tests/UI/Presenter.link().phpt @@ -163,21 +163,21 @@ class TestPresenter extends Application\UI\Presenter Assert::same('/index.php?action=hintsNulls&presenter=Test', $this->link('hintsNulls', ['int' => null, 'bool' => null, 'str' => null, 'arr' => null])); Assert::same('/index.php?int=1&bool=1&str=abc&arr%5B0%5D=1&action=hintsNulls&presenter=Test', $this->link('hintsNulls', ['int' => '1', 'bool' => '1', 'str' => 'abc', 'arr' => [1]])); Assert::same('/index.php?int=0&bool=0&action=hintsNulls&presenter=Test', $this->link('hintsNulls', ['int' => 0, 'bool' => false, 'str' => '', 'arr' => []])); - Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNulls() must be int, string given.', $this->link('hintsNulls', ['int' => ''])); - Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNulls() must be int, stdClass given.', $this->link('hintsNulls', ['int' => new stdClass])); - Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNulls() must be int, array given.', $this->link('hintsNulls', ['int' => []])); - Assert::same('#error: Argument $bool passed to TestPresenter::actionHintsNulls() must be bool, string given.', $this->link('hintsNulls', ['int' => '1', 'bool' => ''])); - Assert::same('#error: Argument $arr passed to TestPresenter::actionHintsNulls() must be array, string given.', $this->link('hintsNulls', ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => ''])); + Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNulls() must be ?int, string given.', $this->link('hintsNulls', ['int' => ''])); + Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNulls() must be ?int, stdClass given.', $this->link('hintsNulls', ['int' => new stdClass])); + Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNulls() must be ?int, array given.', $this->link('hintsNulls', ['int' => []])); + Assert::same('#error: Argument $bool passed to TestPresenter::actionHintsNulls() must be ?bool, string given.', $this->link('hintsNulls', ['int' => '1', 'bool' => ''])); + Assert::same('#error: Argument $arr passed to TestPresenter::actionHintsNulls() must be ?array, string given.', $this->link('hintsNulls', ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => ''])); Assert::same('/index.php?action=hintsNullable&presenter=Test', $this->link('hintsNullable', [])); Assert::same('/index.php?action=hintsNullable&presenter=Test', $this->link('hintsNullable', ['int' => null, 'bool' => null, 'str' => null, 'arr' => null])); Assert::same('/index.php?int=1&bool=1&str=abc&arr%5B0%5D=1&action=hintsNullable&presenter=Test', $this->link('hintsNullable', ['int' => '1', 'bool' => '1', 'str' => 'abc', 'arr' => [1]])); Assert::same('/index.php?int=0&bool=0&action=hintsNullable&presenter=Test', $this->link('hintsNullable', ['int' => 0, 'bool' => false, 'str' => '', 'arr' => []])); - Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNullable() must be int, string given.', $this->link('hintsNullable', ['int' => ''])); - Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNullable() must be int, stdClass given.', $this->link('hintsNullable', ['int' => new stdClass])); - Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNullable() must be int, array given.', $this->link('hintsNullable', ['int' => []])); - Assert::same('#error: Argument $bool passed to TestPresenter::actionHintsNullable() must be bool, string given.', $this->link('hintsNullable', ['int' => '1', 'bool' => ''])); - Assert::same('#error: Argument $arr passed to TestPresenter::actionHintsNullable() must be array, string given.', $this->link('hintsNullable', ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => ''])); + Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNullable() must be ?int, string given.', $this->link('hintsNullable', ['int' => ''])); + Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNullable() must be ?int, stdClass given.', $this->link('hintsNullable', ['int' => new stdClass])); + Assert::same('#error: Argument $int passed to TestPresenter::actionHintsNullable() must be ?int, array given.', $this->link('hintsNullable', ['int' => []])); + Assert::same('#error: Argument $bool passed to TestPresenter::actionHintsNullable() must be ?bool, string given.', $this->link('hintsNullable', ['int' => '1', 'bool' => ''])); + Assert::same('#error: Argument $arr passed to TestPresenter::actionHintsNullable() must be ?array, string given.', $this->link('hintsNullable', ['int' => '1', 'bool' => '1', 'str' => '', 'arr' => ''])); Assert::same('/index.php?action=hintsDefaults&presenter=Test', $this->link('hintsDefaults', [])); Assert::same('/index.php?action=hintsDefaults&presenter=Test', $this->link('hintsDefaults', ['int' => null, 'bool' => null, 'str' => null, 'arr' => null])); diff --git a/tests/UI/Presenter.paramChecking.phpt b/tests/UI/Presenter.paramChecking.phpt index dd433575d..958171c55 100644 --- a/tests/UI/Presenter.paramChecking.phpt +++ b/tests/UI/Presenter.paramChecking.phpt @@ -57,7 +57,7 @@ Assert::exception(function () use ($presenter) { Assert::exception(function () use ($presenter) { $request = new Application\Request('Test', Http\Request::Get, ['d' => 1]); $presenter->run($request); -}, Nette\Application\BadRequestException::class, 'Argument $d passed to ParamPresenter::actionDefault() must be array, int given.'); +}, Nette\Application\BadRequestException::class, 'Argument $d passed to ParamPresenter::actionDefault() must be ?array, int given.'); Assert::exception(function () use ($presenter) { From ec629b8ad1a41fbb6072f64b0eacf2a98929a23a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 4 Oct 2023 05:18:54 +0200 Subject: [PATCH 37/42] refactoring --- src/Application/UI/ComponentReflection.php | 31 +++++++++------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index bc9a1e3d0..f6bba990b 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -208,8 +208,19 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a */ public static function convertType(&$val, string $types): bool { + $scalars = ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'true' => 1, 'false' => 1]; + $tests = ['iterable' => 1, 'object' => 1, 'array' => 1, 'null' => 1]; + foreach (explode('|', ltrim($types, '?')) as $type) { - if (self::convertSingleType($val, $type)) { + $ok = match (true) { + isset($scalars[$type]) => self::dataLossConvert($val, $type), + isset($tests[$type]) => "is_$type"($val), + $type === 'scalar' => !is_array($val), // special historical type + $type === 'mixed' => true, + $type === 'callable' => false, + default => $val instanceof $type, + }; + if ($ok) { return true; } } @@ -218,24 +229,6 @@ public static function convertType(&$val, string $types): bool } - /** - * Non data-loss type conversion. - */ - private static function convertSingleType(&$val, string $type): bool - { - $scalars = ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'true' => 1, 'false' => 1]; - $tests = ['iterable' => 1, 'object' => 1, 'array' => 1, 'null' => 1]; - return match (true) { - isset($scalars[$type]) => self::dataLossConvert($val, $type), - isset($tests[$type]) => "is_$type"($val), - $type === 'scalar' => !is_array($val), // special historical type - $type === 'mixed' => true, - $type === 'callable' => false, - default => $val instanceof $type, - }; - } - - private static function dataLossConvert(&$val, string $type): bool { if (!is_scalar($val)) { From 50619438b06e4ed2fd6508cdf744ee9cbc02735a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 4 Oct 2023 05:24:46 +0200 Subject: [PATCH 38/42] uses nette/routing 4.0 --- .phpstorm.meta.php | 3 --- composer.json | 2 +- src/Application/Routers/RouteList.php | 6 +++--- src/Bridges/ApplicationTracy/RoutingPanel.php | 4 ++-- tests/Routers/RouteList.addRoute.phpt | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index 3c0ac5638..f6e829756 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -4,9 +4,6 @@ namespace PHPSTORM_META; -expectedArguments(\Nette\Application\Routers\Route::__construct(), 2, \Nette\Routing\Router::ONE_WAY); -expectedArguments(\Nette\Application\Routers\SimpleRouter::__construct(), 1, \Nette\Routing\Router::ONE_WAY); - registerArgumentsSet('nette_http_codes_3xx', \Nette\Http\IResponse::S300_MultipleChoices, \Nette\Http\IResponse::S301_MovedPermanently, diff --git a/composer.json b/composer.json index f51e89757..dc8d891ff 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "php": "8.0 - 8.3", "nette/component-model": "^4.0", "nette/http": "^4.0", - "nette/routing": "^3.0.2", + "nette/routing": "^4.0", "nette/utils": "^4.0" }, "suggest": { diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index 72c024fc1..e2c0d0de3 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -66,11 +66,11 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri public function addRoute( #[Language('TEXT')] string $mask, - $metadata = [], - int $flags = 0, + array|string|\Closure $metadata = [], + bool $oneWay = false, ): static { - $this->add(new Route($mask, $metadata), $flags); + $this->add(new Route($mask, $metadata), $oneWay); return $this; } diff --git a/src/Bridges/ApplicationTracy/RoutingPanel.php b/src/Bridges/ApplicationTracy/RoutingPanel.php index 01384cdf4..fb4168e59 100644 --- a/src/Bridges/ApplicationTracy/RoutingPanel.php +++ b/src/Bridges/ApplicationTracy/RoutingPanel.php @@ -80,7 +80,7 @@ private function analyse( string $module = '', ?string $path = null, int $level = -1, - int $flag = 0, + array $flag = [], ): void { if ($router instanceof Routing\RouteList) { @@ -119,7 +119,7 @@ private function analyse( return; } - $matched = $flag & Routing\RouteList::ONE_WAY ? 'oneway' : 'no'; + $matched = empty($flag['oneWay']) ? 'no' : 'oneway'; $params = $e = null; try { $params = $httpRequest diff --git a/tests/Routers/RouteList.addRoute.phpt b/tests/Routers/RouteList.addRoute.phpt index fd6ab423a..068f66805 100644 --- a/tests/Routers/RouteList.addRoute.phpt +++ b/tests/Routers/RouteList.addRoute.phpt @@ -12,7 +12,7 @@ require __DIR__ . '/Route.php'; $list = new RouteList; $list->addRoute('foo', ['presenter' => 'foo'], RouteList::ONE_WAY); -$list->addRoute('bar', ['presenter' => 'bar'], RouteList::ONE_WAY); +$list->addRoute('bar', ['presenter' => 'bar'], oneWay: true); $list->addRoute('hello', ['presenter' => 'hello']); From 7d1d24f2fa7a53b3657b8f80c3fcc73e01e46e94 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 9 Jan 2023 14:07:48 +0100 Subject: [PATCH 39/42] LatteExtension: added option 'variables' --- src/Bridges/ApplicationDI/LatteExtension.php | 7 +- .../ApplicationLatte/DefaultTemplate.php | 3 + .../ApplicationLatte/TemplateFactory.php | 2 + .../Bridges.DI/LatteExtension.variables.phpt | 78 +++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 tests/Bridges.DI/LatteExtension.variables.phpt diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 405acd910..64275eac0 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -42,6 +42,7 @@ public function getConfigSchema(): Nette\Schema\Schema 'strictTypes' => Expect::bool(false), 'strictParsing' => Expect::bool(false), 'phpLinter' => Expect::string(), + 'variables' => Expect::array([]), ]); } @@ -70,8 +71,10 @@ public function loadConfiguration() } $builder->addDefinition($this->prefix('templateFactory')) - ->setFactory(ApplicationLatte\TemplateFactory::class) - ->setArguments(['templateClass' => $config->templateClass]); + ->setFactory(ApplicationLatte\TemplateFactory::class, [ + 'templateClass' => $config->templateClass, + 'configVars' => $config->variables, + ]); if ($this->name === 'latte') { $builder->addAlias('nette.latteFactory', $this->prefix('latteFactory')); diff --git a/src/Bridges/ApplicationLatte/DefaultTemplate.php b/src/Bridges/ApplicationLatte/DefaultTemplate.php index bd93e1997..d35f00f13 100644 --- a/src/Bridges/ApplicationLatte/DefaultTemplate.php +++ b/src/Bridges/ApplicationLatte/DefaultTemplate.php @@ -30,6 +30,9 @@ final class DefaultTemplate extends Template /** @var \stdClass[] */ public array $flashes = []; + /** @var \stdClass */ + public mixed $config; + /** * Adds new template parameter. diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index becd5dc36..097fa8a29 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -30,6 +30,7 @@ public function __construct( private ?Nette\Security\User $user = null, private ?Nette\Caching\Storage $cacheStorage = null, $templateClass = null, + private array $configVars = [], ) { if ($templateClass && (!class_exists($templateClass) || !is_a($templateClass, Template::class, true))) { throw new Nette\InvalidArgumentException("Class $templateClass does not implement " . Template::class . ' or it does not exist.'); @@ -85,6 +86,7 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul 'flashes' => $flashes, 'control' => $control, 'presenter' => $presenter, + 'config' => $control instanceof UI\Presenter && $this->configVars ? (object) $this->configVars : null, ]; foreach ($params as $key => $value) { diff --git a/tests/Bridges.DI/LatteExtension.variables.phpt b/tests/Bridges.DI/LatteExtension.variables.phpt new file mode 100644 index 000000000..150417944 --- /dev/null +++ b/tests/Bridges.DI/LatteExtension.variables.phpt @@ -0,0 +1,78 @@ +load(Tester\FileMock::create(' + latte: + variables: + ', 'neon')); + + $compiler = new DI\Compiler; + $compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension('', false)); + $code = $compiler + ->addConfig($config) + ->setClassName('Container1') + ->compile(); + eval($code); + + $container = new Container1; + $latteFactory = $container->getService('latte.templateFactory'); + $presenter = Mockery::mock(Nette\Application\UI\Presenter::class); + $presenter->shouldReceive('getHttpResponse')->andReturn(Mockery::mock(Nette\Http\IResponse::class)->shouldIgnoreMissing()); + $presenter->shouldIgnoreMissing(); + + $template = $latteFactory->createTemplate($presenter); + Assert::notContains('config', $template->getParameters()); +}); + + +test('presenter presence', function () { + $loader = new DI\Config\Loader; + $config = $loader->load(Tester\FileMock::create(' + latte: + variables: + foo: bar + ', 'neon')); + + $compiler = new DI\Compiler; + $compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension('', false)); + $code = $compiler + ->addConfig($config) + ->setClassName('Container2') + ->compile(); + eval($code); + + $container = new Container2; + $latteFactory = $container->getService('latte.templateFactory'); + $template = $latteFactory->createTemplate(); + Assert::notContains('config', $template->getParameters()); + + + $presenter = Mockery::mock(Nette\Application\UI\Presenter::class); + $presenter->shouldReceive('getHttpResponse')->andReturn(Mockery::mock(Nette\Http\IResponse::class)->shouldIgnoreMissing()); + $presenter->shouldIgnoreMissing(); + + $template = $latteFactory->createTemplate($presenter); + Assert::equal( + (object) ['foo' => 'bar'], + $template->getParameters()['config'], + ); +}); From 3cfb4dfa8f2674cafb61926ee9d2e8cd76401d6e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 13 Nov 2021 17:26:35 +0100 Subject: [PATCH 40/42] AllowedFor wip --- src/Application/Attributes/AllowedFor.php | 21 +++++++++++++++++++++ src/Application/UI/Component.php | 7 +++++++ 2 files changed, 28 insertions(+) create mode 100644 src/Application/Attributes/AllowedFor.php diff --git a/src/Application/Attributes/AllowedFor.php b/src/Application/Attributes/AllowedFor.php new file mode 100644 index 000000000..5779f2c6d --- /dev/null +++ b/src/Application/Attributes/AllowedFor.php @@ -0,0 +1,21 @@ +getPresenter()->detectedCsrf(); } + + if ($attrs = $element->getAttributes(Nette\Application\Attributes\AllowedFor::class)) { + $method = strtolower($this->getPresenter()->getRequest()->getMethod()); + if (empty($attrs[0]->newInstance()->$method)) { + throw new Nette\Application\BadRequestException("Method '$method' is not allowed."); + } + } } From 602167c7f85e786d25e8bc5ef494a074a9f4bdea Mon Sep 17 00:00:00 2001 From: dakur Date: Thu, 5 Oct 2023 10:54:14 +0200 Subject: [PATCH 41/42] exception in application: pass reference to previous presenter --- src/Application/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index 02448197b..bc5a0c375 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -166,7 +166,7 @@ public function processException(\Throwable $e): void $this->httpResponse->setCode($e instanceof BadRequestException ? ($e->getHttpCode() ?: 404) : 500); } - $args = ['exception' => $e, 'request' => Arrays::last($this->requests) ?: null]; + $args = ['exception' => $e, 'previousPresenter' => $this->presenter, 'request' => Arrays::last($this->requests) ?: null]; if ($this->presenter instanceof UI\Presenter) { try { $this->presenter->forward(":$this->errorPresenter:", $args); From 7959a15e95a195f8ecea724e0631c1a9a34dc28b Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Thu, 5 Oct 2023 11:20:35 +0200 Subject: [PATCH 42/42] update test --- tests/Application/Application.run.phpt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Application/Application.run.phpt b/tests/Application/Application.run.phpt index 7a5f2aa1e..4cb473175 100644 --- a/tests/Application/Application.run.phpt +++ b/tests/Application/Application.run.phpt @@ -127,6 +127,7 @@ test('no route with error presenter', function () use ($httpRequest, $httpRespon Assert::equal($requests[0], $errorPresenter->request); Assert::null($errorPresenter->request->getParameter('request')); + Assert::null($errorPresenter->request->getParameter('previousPresenter')); Assert::type(BadRequestException::class, $errorPresenter->request->getParameter('exception')); }); @@ -154,6 +155,7 @@ test('route to error presenter', function () use ($httpRequest, $httpResponse) { Assert::equal($requests[1], $errorPresenter->request); Assert::equal($requests[0], $errorPresenter->request->getParameter('request')); + Assert::null($errorPresenter->request->getParameter('previousPresenter')); Assert::type(BadRequestException::class, $errorPresenter->request->getParameter('exception')); }); @@ -195,6 +197,7 @@ test('missing presenter with error presenter', function () use ($httpRequest, $h Assert::equal($requests[1], $errorPresenter->request); Assert::equal($requests[0], $errorPresenter->request->getParameter('request')); + Assert::null($errorPresenter->request->getParameter('previousPresenter')); Assert::type(BadRequestException::class, $errorPresenter->request->getParameter('exception')); }); @@ -213,10 +216,11 @@ Assert::exception(function () use ($httpRequest, $httpResponse) { test('presenter error with error presenter', function () use ($httpRequest, $httpResponse) { + $badPresenter = new BadPresenter; $errorPresenter = new ErrorPresenter; $presenterFactory = Mockery::mock(IPresenterFactory::class); - $presenterFactory->shouldReceive('createPresenter')->with('Bad')->andReturn(new BadPresenter); + $presenterFactory->shouldReceive('createPresenter')->with('Bad')->andReturn($badPresenter); $presenterFactory->shouldReceive('createPresenter')->with('Error')->andReturn($errorPresenter); $router = Mockery::mock(Router::class); @@ -236,6 +240,7 @@ test('presenter error with error presenter', function () use ($httpRequest, $htt Assert::equal($requests[1], $errorPresenter->request); Assert::equal($requests[0], $errorPresenter->request->getParameter('request')); + Assert::equal($badPresenter, $errorPresenter->request->getParameter('previousPresenter')); Assert::type(BadException::class, $errorPresenter->request->getParameter('exception')); });