From 5ea8d13dd5b68c42788298b78ddd04285d911147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=A0pa=C4=8Dek?= Date: Sat, 11 Jan 2025 18:37:36 +0100 Subject: [PATCH] Update package nette/di - nette/di updated from v3.2.3 to v3.2.4 patch See changes: https://github.com/nette/di/compare/v3.2.3...v3.2.4 Release notes: https://github.com/nette/di/releases/tag/v3.2.4 --- app/composer.lock | 12 +++--- app/vendor/composer/installed.json | 14 +++---- app/vendor/composer/installed.php | 10 ++--- .../di/src/DI/Config/Adapters/NeonAdapter.php | 41 ++++++++++--------- .../src/DI/Definitions/LocatorDefinition.php | 12 ++++-- .../src/DI/Definitions/ServiceDefinition.php | 37 +++++++++++++---- .../di/src/DI/Extensions/DIExtension.php | 15 +++++++ .../src/DI/Extensions/DecoratorExtension.php | 1 + .../di/src/DI/Extensions/DefinitionSchema.php | 1 + .../src/DI/Extensions/ServicesExtension.php | 4 ++ app/vendor/nette/di/src/DI/PhpGenerator.php | 8 ++-- app/vendor/nette/di/src/DI/Resolver.php | 14 +++---- 12 files changed, 106 insertions(+), 63 deletions(-) diff --git a/app/composer.lock b/app/composer.lock index 279b2ed2d..1226cd483 100644 --- a/app/composer.lock +++ b/app/composer.lock @@ -706,16 +706,16 @@ }, { "name": "nette/di", - "version": "v3.2.3", + "version": "v3.2.4", "source": { "type": "git", "url": "https://github.com/nette/di.git", - "reference": "9b9bfb43dac31c7804b2c8900217046cc0ca3307" + "reference": "57f923a7af32435b6e4921c0adbc70c619625a17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/di/zipball/9b9bfb43dac31c7804b2c8900217046cc0ca3307", - "reference": "9b9bfb43dac31c7804b2c8900217046cc0ca3307", + "url": "https://api.github.com/repos/nette/di/zipball/57f923a7af32435b6e4921c0adbc70c619625a17", + "reference": "57f923a7af32435b6e4921c0adbc70c619625a17", "shasum": "" }, "require": { @@ -773,9 +773,9 @@ ], "support": { "issues": "https://github.com/nette/di/issues", - "source": "https://github.com/nette/di/tree/v3.2.3" + "source": "https://github.com/nette/di/tree/v3.2.4" }, - "time": "2024-10-05T03:14:33+00:00" + "time": "2025-01-10T04:57:37+00:00" }, { "name": "nette/forms", diff --git a/app/vendor/composer/installed.json b/app/vendor/composer/installed.json index 4738c5061..11b17ae8b 100644 --- a/app/vendor/composer/installed.json +++ b/app/vendor/composer/installed.json @@ -772,17 +772,17 @@ }, { "name": "nette/di", - "version": "v3.2.3", - "version_normalized": "3.2.3.0", + "version": "v3.2.4", + "version_normalized": "3.2.4.0", "source": { "type": "git", "url": "https://github.com/nette/di.git", - "reference": "9b9bfb43dac31c7804b2c8900217046cc0ca3307" + "reference": "57f923a7af32435b6e4921c0adbc70c619625a17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/di/zipball/9b9bfb43dac31c7804b2c8900217046cc0ca3307", - "reference": "9b9bfb43dac31c7804b2c8900217046cc0ca3307", + "url": "https://api.github.com/repos/nette/di/zipball/57f923a7af32435b6e4921c0adbc70c619625a17", + "reference": "57f923a7af32435b6e4921c0adbc70c619625a17", "shasum": "" }, "require": { @@ -800,7 +800,7 @@ "phpstan/phpstan": "^1.0", "tracy/tracy": "^2.9" }, - "time": "2024-10-05T03:14:33+00:00", + "time": "2025-01-10T04:57:37+00:00", "type": "library", "extra": { "branch-alias": { @@ -842,7 +842,7 @@ ], "support": { "issues": "https://github.com/nette/di/issues", - "source": "https://github.com/nette/di/tree/v3.2.3" + "source": "https://github.com/nette/di/tree/v3.2.4" }, "install-path": "../nette/di" }, diff --git a/app/vendor/composer/installed.php b/app/vendor/composer/installed.php index fd3842219..1a7dd7acd 100644 --- a/app/vendor/composer/installed.php +++ b/app/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'spaze/michalspacek.cz', 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => 'a80820cc549bcb1f1dc305f0dc92f9bb559f1846', + 'reference' => 'a847fe8c27a7eb84d574455477330e0af6f1b156', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -137,9 +137,9 @@ 'dev_requirement' => false, ), 'nette/di' => array( - 'pretty_version' => 'v3.2.3', - 'version' => '3.2.3.0', - 'reference' => '9b9bfb43dac31c7804b2c8900217046cc0ca3307', + 'pretty_version' => 'v3.2.4', + 'version' => '3.2.4.0', + 'reference' => '57f923a7af32435b6e4921c0adbc70c619625a17', 'type' => 'library', 'install_path' => __DIR__ . '/../nette/di', 'aliases' => array(), @@ -468,7 +468,7 @@ 'spaze/michalspacek.cz' => array( 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => 'a80820cc549bcb1f1dc305f0dc92f9bb559f1846', + 'reference' => 'a847fe8c27a7eb84d574455477330e0af6f1b156', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/app/vendor/nette/di/src/DI/Config/Adapters/NeonAdapter.php b/app/vendor/nette/di/src/DI/Config/Adapters/NeonAdapter.php index d806cd319..7de1eee1e 100644 --- a/app/vendor/nette/di/src/DI/Config/Adapters/NeonAdapter.php +++ b/app/vendor/nette/di/src/DI/Config/Adapters/NeonAdapter.php @@ -10,10 +10,11 @@ namespace Nette\DI\Config\Adapters; use Nette; -use Nette\DI\Config\Helpers; +use Nette\DI; use Nette\DI\Definitions\Reference; use Nette\DI\Definitions\Statement; use Nette\Neon; +use Nette\Neon\Node; /** @@ -43,7 +44,7 @@ public function load(string $file): array $node = $traverser->traverse($node, $this->removeUnderscoreVisitor(...)); $node = $traverser->traverse($node, $this->convertAtSignVisitor(...)); $node = $traverser->traverse($node, $this->deprecatedParametersVisitor(...)); - $node = $traverser->traverse($node, $this->resolveConstants(...)); + $node = $traverser->traverse($node, $this->resolveConstantsVisitor(...)); return $this->process((array) $node->toValue()); } @@ -63,7 +64,7 @@ public function process(array $arr): array } $key = substr($key, 0, -1); - $val[Helpers::PREVENT_MERGING] = true; + $val[DI\Config\Helpers::PREVENT_MERGING] = true; } if (is_array($val)) { @@ -150,12 +151,12 @@ function (&$val): void { } - private function firstClassCallableVisitor(Neon\Node $node): void + private function firstClassCallableVisitor(Node $node): void { - if ($node instanceof Neon\Node\EntityNode + if ($node instanceof Node\EntityNode && count($node->attributes) === 1 && $node->attributes[0]->key === null - && $node->attributes[0]->value instanceof Neon\Node\LiteralNode + && $node->attributes[0]->value instanceof Node\LiteralNode && $node->attributes[0]->value->value === '...' ) { $node->attributes[0]->value->value = Nette\DI\Resolver::getFirstClassCallable()[0]; @@ -163,9 +164,9 @@ private function firstClassCallableVisitor(Neon\Node $node): void } - private function removeUnderscoreVisitor(Neon\Node $node): void + private function removeUnderscoreVisitor(Node $node): void { - if (!$node instanceof Neon\Node\EntityNode) { + if (!$node instanceof Node\EntityNode) { return; } @@ -175,13 +176,13 @@ private function removeUnderscoreVisitor(Neon\Node $node): void continue; } - $attr->key = $index ? new Neon\Node\LiteralNode((string) $i) : null; + $attr->key = $index ? new Node\LiteralNode((string) $i) : null; - if ($attr->value instanceof Neon\Node\LiteralNode && $attr->value->value === '_') { + if ($attr->value instanceof Node\LiteralNode && $attr->value->value === '_') { unset($node->attributes[$i]); $index = true; - } elseif ($attr->value instanceof Neon\Node\LiteralNode && $attr->value->value === '...') { + } elseif ($attr->value instanceof Node\LiteralNode && $attr->value->value === '...') { trigger_error("Replace ... with _ in configuration file '$this->file'.", E_USER_DEPRECATED); unset($node->attributes[$i]); $index = true; @@ -190,9 +191,9 @@ private function removeUnderscoreVisitor(Neon\Node $node): void } - private function convertAtSignVisitor(Neon\Node $node): void + private function convertAtSignVisitor(Node $node): void { - if ($node instanceof Neon\Node\StringNode) { + if ($node instanceof Node\StringNode) { if (str_starts_with($node->value, '@@')) { trigger_error("There is no need to escape @ anymore, replace @@ with @ in: '$node->value' (used in $this->file)", E_USER_DEPRECATED); } else { @@ -200,7 +201,7 @@ private function convertAtSignVisitor(Neon\Node $node): void } } elseif ( - $node instanceof Neon\Node\LiteralNode + $node instanceof Node\LiteralNode && is_string($node->value) && str_starts_with($node->value, '@@') ) { @@ -209,9 +210,9 @@ private function convertAtSignVisitor(Neon\Node $node): void } - private function deprecatedParametersVisitor(Neon\Node $node): void + private function deprecatedParametersVisitor(Node $node): void { - if (($node instanceof Neon\Node\StringNode || $node instanceof Neon\Node\LiteralNode) + if (($node instanceof Node\StringNode || $node instanceof Node\LiteralNode) && is_string($node->value) && str_contains($node->value, '%parameters%') ) { @@ -220,16 +221,16 @@ private function deprecatedParametersVisitor(Neon\Node $node): void } - private function resolveConstants(Neon\Node $node): void + private function resolveConstantsVisitor(Node $node): void { $items = match (true) { - $node instanceof Neon\Node\ArrayNode => $node->items, - $node instanceof Neon\Node\EntityNode => $node->attributes, + $node instanceof Node\ArrayNode => $node->items, + $node instanceof Node\EntityNode => $node->attributes, default => null, }; if ($items) { foreach ($items as $item) { - if ($item->value instanceof Neon\Node\LiteralNode + if ($item->value instanceof Node\LiteralNode && is_string($item->value->value) && preg_match('#^([\w\\\\]*)::[A-Z]\w+$#D', $item->value->value) && defined(ltrim($item->value->value, ':')) diff --git a/app/vendor/nette/di/src/DI/Definitions/LocatorDefinition.php b/app/vendor/nette/di/src/DI/Definitions/LocatorDefinition.php index fe8b3aecd..a9e3f735a 100644 --- a/app/vendor/nette/di/src/DI/Definitions/LocatorDefinition.php +++ b/app/vendor/nette/di/src/DI/Definitions/LocatorDefinition.php @@ -149,10 +149,14 @@ public function generateMethod(Nette\PhpGenerator\Method $method, Nette\DI\PhpGe $class->addProperty('mapping', array_map(fn($item) => $item->getValue(), $this->references)) ->setPrivate(); - $methodInner->setBody('if (!isset($this->mapping[$name])) { - ' . ($nullable ? 'return null;' : 'throw new Nette\DI\MissingServiceException("Service \'$name\' is not defined.");') . ' -} -return $this->container->' . $m[1] . 'Service($this->mapping[$name]);') + $methodInner->setBody(<<<'XX' + if (!isset($this->mapping[$name])) { + + XX . "\t" . ($nullable ? 'return null;' : 'throw new Nette\DI\MissingServiceException("Service \'$name\' is not defined.");') . <<<'XX' + + } + return $this->container-> + XX . $m[1] . 'Service($this->mapping[$name]);') ->addParameter('name'); } elseif (isset($this->references[$name])) { diff --git a/app/vendor/nette/di/src/DI/Definitions/ServiceDefinition.php b/app/vendor/nette/di/src/DI/Definitions/ServiceDefinition.php index 6cec76a86..ff934c26a 100644 --- a/app/vendor/nette/di/src/DI/Definitions/ServiceDefinition.php +++ b/app/vendor/nette/di/src/DI/Definitions/ServiceDefinition.php @@ -11,6 +11,7 @@ use Nette; use Nette\DI\ServiceCreationException; +use Nette\Utils\Strings; /** @@ -24,6 +25,7 @@ final class ServiceDefinition extends Definition { use Nette\SmartObject; + public ?bool $lazy = null; private Statement $creator; /** @var Statement[] */ @@ -181,19 +183,36 @@ private function prependSelf(Statement $setup): Statement public function generateMethod(Nette\PhpGenerator\Method $method, Nette\DI\PhpGenerator $generator): void { - $code = $generator->formatStatement($this->creator) . ";\n"; - if (!$this->setup) { - $method->setBody('return ' . $code); - return; + $lines = []; + foreach ([$this->creator, ...$this->setup] as $stmt) { + $lines[] = $generator->formatStatement($stmt) . ";\n"; } - $code = '$service = ' . $code; - foreach ($this->setup as $setup) { - $code .= $generator->formatStatement($setup) . ";\n"; + if ($this->canBeLazy() && !preg_grep('#(?:func_get_arg|func_num_args)#i', $lines)) { // latteFactory workaround + $class = $this->creator->getEntity(); + $lines[0] = (new \ReflectionClass($class))->hasMethod('__construct') + ? $generator->formatPhp("\$service->__construct(...?:);\n", [$this->creator->arguments]) + : ''; + $method->setBody("return new ReflectionClass($class::class)->newLazyGhost(function (\$service) {\n" + . Strings::indent(implode('', $lines)) + . '});'); + + } elseif (count($lines) === 1) { + $method->setBody('return ' . $lines[0]); + + } else { + $method->setBody('$service = ' . implode('', $lines) . 'return $service;'); } + } - $code .= 'return $service;'; - $method->setBody($code); + + private function canBeLazy(): bool + { + return $this->lazy + && is_string($class = $this->creator->getEntity()) + && ($this->creator->arguments || $this->setup) + && ($ancestor = ($tmp = class_parents($class)) ? array_pop($tmp) : $class) + && !(new \ReflectionClass($ancestor))->isInternal(); } diff --git a/app/vendor/nette/di/src/DI/Extensions/DIExtension.php b/app/vendor/nette/di/src/DI/Extensions/DIExtension.php index 5b789cffa..99e9de0f1 100644 --- a/app/vendor/nette/di/src/DI/Extensions/DIExtension.php +++ b/app/vendor/nette/di/src/DI/Extensions/DIExtension.php @@ -10,6 +10,7 @@ namespace Nette\DI\Extensions; use Nette; +use Nette\DI\Definitions\ServiceDefinition; use Tracy; @@ -36,6 +37,7 @@ public function __construct(bool $debugMode = false) public array $excluded = []; public ?string $parentClass = null; public object $export; + public bool $lazy = false; }; $this->config->export = new class { public bool $parameters = true; @@ -56,6 +58,19 @@ public function loadConfiguration(): void } + public function beforeCompile(): void + { + if ($this->config->lazy && PHP_VERSION_ID >= 80400) { + $builder = $this->getContainerBuilder(); + foreach ($builder->getDefinitions() as $def) { + if ($def instanceof ServiceDefinition) { + $def->lazy ??= true; + } + } + } + } + + public function afterCompile(Nette\PhpGenerator\ClassType $class): void { if ($this->config->parentClass) { diff --git a/app/vendor/nette/di/src/DI/Extensions/DecoratorExtension.php b/app/vendor/nette/di/src/DI/Extensions/DecoratorExtension.php index e5a4cc129..0725d8086 100644 --- a/app/vendor/nette/di/src/DI/Extensions/DecoratorExtension.php +++ b/app/vendor/nette/di/src/DI/Extensions/DecoratorExtension.php @@ -13,6 +13,7 @@ use Nette\DI\Definitions; use Nette\Schema\Expect; + /** * Decorators for services. */ diff --git a/app/vendor/nette/di/src/DI/Extensions/DefinitionSchema.php b/app/vendor/nette/di/src/DI/Extensions/DefinitionSchema.php index a49ab3faa..487ddecae 100644 --- a/app/vendor/nette/di/src/DI/Extensions/DefinitionSchema.php +++ b/app/vendor/nette/di/src/DI/Extensions/DefinitionSchema.php @@ -173,6 +173,7 @@ private static function getServiceSchema(): Schema 'tags' => Expect::array(), 'reset' => Expect::array(), 'alteration' => Expect::bool(), + 'lazy' => Expect::bool(), ]); } diff --git a/app/vendor/nette/di/src/DI/Extensions/ServicesExtension.php b/app/vendor/nette/di/src/DI/Extensions/ServicesExtension.php index 8bb50257d..075cf54a3 100644 --- a/app/vendor/nette/di/src/DI/Extensions/ServicesExtension.php +++ b/app/vendor/nette/di/src/DI/Extensions/ServicesExtension.php @@ -113,6 +113,10 @@ private function updateServiceDefinition(Definitions\ServiceDefinition $definiti if (isset($config->inject)) { $definition->addTag(InjectExtension::TagInject, $config->inject); } + + if (isset($config->lazy)) { + $definition->lazy = $config->lazy; + } } diff --git a/app/vendor/nette/di/src/DI/PhpGenerator.php b/app/vendor/nette/di/src/DI/PhpGenerator.php index bbb4b574c..b5176c40d 100644 --- a/app/vendor/nette/di/src/DI/PhpGenerator.php +++ b/app/vendor/nette/di/src/DI/PhpGenerator.php @@ -66,11 +66,13 @@ public function generate(string $className): Php\ClassType public function toString(Php\ClassType $class): string { - return '/** @noinspection PhpParamsInspection,PhpMethodMayBeStaticInspection */ + return <<<'XX' + /** @noinspection PhpParamsInspection,PhpMethodMayBeStaticInspection */ + + declare(strict_types=1); -declare(strict_types=1); -' . $class->__toString(); + XX . $class->__toString(); } diff --git a/app/vendor/nette/di/src/DI/Resolver.php b/app/vendor/nette/di/src/DI/Resolver.php index 3e6afc3ff..a1e594495 100644 --- a/app/vendor/nette/di/src/DI/Resolver.php +++ b/app/vendor/nette/di/src/DI/Resolver.php @@ -241,6 +241,10 @@ public function completeStatement(Statement $statement, bool $currentServiceAllo break; case $entity instanceof Reference: + if ($arguments) { + $e = $this->completeException(new ServiceCreationException(sprintf('Parameters were passed to reference @%s, although references cannot have any parameters.', $entity->getValue())), $this->currentService); + trigger_error($e->getMessage(), E_USER_DEPRECATED); + } $entity = [new Reference(ContainerBuilder::ThisContainer), Container::getMethodName($entity->getValue())]; break; @@ -254,12 +258,7 @@ public function completeStatement(Statement $statement, bool $currentServiceAllo switch (true) { case $entity[0] === '': // function call - if (!Arrays::isList($arguments)) { - throw new ServiceCreationException(sprintf( - 'Unable to pass specified arguments to %s.', - $entity[0], - )); - } elseif (!function_exists($entity[1])) { + if (!function_exists($entity[1])) { throw new ServiceCreationException(sprintf("Function %s doesn't exist.", $entity[1])); } @@ -293,9 +292,6 @@ public function completeStatement(Statement $statement, bool $currentServiceAllo $arguments = self::autowireArguments($rm, $arguments, $getter); $this->addDependency($rm); - - } elseif (!Arrays::isList($arguments)) { - throw new ServiceCreationException(sprintf('Unable to pass specified arguments to %s::%s().', $type, $entity[1])); } } }