Skip to content

Commit

Permalink
Update package nette/di (#459)
Browse files Browse the repository at this point in the history
 - nette/di updated from v3.2.3 to v3.2.4 patch
   See changes: nette/di@v3.2.3...v3.2.4
   Release notes: https://github.com/nette/di/releases/tag/v3.2.4
  • Loading branch information
spaze authored Jan 11, 2025
2 parents a847fe8 + 5ea8d13 commit ea591a7
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 63 deletions.
12 changes: 6 additions & 6 deletions app/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions app/vendor/composer/installed.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions app/vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
41 changes: 21 additions & 20 deletions app/vendor/nette/di/src/DI/Config/Adapters/NeonAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand Down Expand Up @@ -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());
}

Expand All @@ -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)) {
Expand Down Expand Up @@ -150,22 +151,22 @@ 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];
}
}


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;
}

Expand All @@ -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;
Expand All @@ -190,17 +191,17 @@ 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 {
$node->value = preg_replace('#^@#', '$0$0', $node->value); // escape
}

} elseif (
$node instanceof Neon\Node\LiteralNode
$node instanceof Node\LiteralNode
&& is_string($node->value)
&& str_starts_with($node->value, '@@')
) {
Expand All @@ -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%')
) {
Expand All @@ -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, ':'))
Expand Down
12 changes: 8 additions & 4 deletions app/vendor/nette/di/src/DI/Definitions/LocatorDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down
37 changes: 28 additions & 9 deletions app/vendor/nette/di/src/DI/Definitions/ServiceDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Nette;
use Nette\DI\ServiceCreationException;
use Nette\Utils\Strings;


/**
Expand All @@ -24,6 +25,7 @@ final class ServiceDefinition extends Definition
{
use Nette\SmartObject;

public ?bool $lazy = null;
private Statement $creator;

/** @var Statement[] */
Expand Down Expand Up @@ -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();
}


Expand Down
15 changes: 15 additions & 0 deletions app/vendor/nette/di/src/DI/Extensions/DIExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Nette\DI\Extensions;

use Nette;
use Nette\DI\Definitions\ServiceDefinition;
use Tracy;


Expand All @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Nette\DI\Definitions;
use Nette\Schema\Expect;


/**
* Decorators for services.
*/
Expand Down
1 change: 1 addition & 0 deletions app/vendor/nette/di/src/DI/Extensions/DefinitionSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private static function getServiceSchema(): Schema
'tags' => Expect::array(),
'reset' => Expect::array(),
'alteration' => Expect::bool(),
'lazy' => Expect::bool(),
]);
}

Expand Down
4 changes: 4 additions & 0 deletions app/vendor/nette/di/src/DI/Extensions/ServicesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down
8 changes: 5 additions & 3 deletions app/vendor/nette/di/src/DI/PhpGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit ea591a7

Please sign in to comment.