Skip to content

Commit

Permalink
Merge branch '5.4' into 6.4
Browse files Browse the repository at this point in the history
* 5.4:
  Fix CI
  Bump ext-redis in CI on PHP >= 8.4
  Adjust pretty name of closures on PHP 8.4
  implement NodeVisitorInterface instead of extending AbstractNodeVisitor
  • Loading branch information
nicolas-grekas committed Apr 16, 2024
2 parents 05a8fcc + 32ac2f3 commit 8477f02
Show file tree
Hide file tree
Showing 23 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
coverage: "none"
ini-values: date.timezone=UTC,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
php-version: "${{ matrix.php }}"
extensions: "${{ env.extensions }}"
extensions: "${{ matrix.extensions || env.extensions }}"
tools: flex

- name: Configure environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
use Twig\Node\ModuleNode;
use Twig\Node\Node;
use Twig\Node\SetNode;
use Twig\NodeVisitor\AbstractNodeVisitor;
use Twig\NodeVisitor\NodeVisitorInterface;

/**
* @author Fabien Potencier <[email protected]>
*/
final class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
final class TranslationDefaultDomainNodeVisitor implements NodeVisitorInterface
{
private Scope $scope;

Expand All @@ -37,7 +37,7 @@ public function __construct()
$this->scope = new Scope();
}

protected function doEnterNode(Node $node, Environment $env): Node
public function enterNode(Node $node, Environment $env): Node
{
if ($node instanceof BlockNode || $node instanceof ModuleNode) {
$this->scope = $this->scope->enter();
Expand Down Expand Up @@ -83,7 +83,7 @@ protected function doEnterNode(Node $node, Environment $env): Node
return $node;
}

protected function doLeaveNode(Node $node, Environment $env): ?Node
public function leaveNode(Node $node, Environment $env): ?Node
{
if ($node instanceof TransDefaultDomainNode) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Node;
use Twig\NodeVisitor\AbstractNodeVisitor;
use Twig\NodeVisitor\NodeVisitorInterface;

/**
* TranslationNodeVisitor extracts translation messages.
*
* @author Fabien Potencier <[email protected]>
*/
final class TranslationNodeVisitor extends AbstractNodeVisitor
final class TranslationNodeVisitor implements NodeVisitorInterface
{
public const UNDEFINED_DOMAIN = '_undefined';

Expand All @@ -49,7 +49,7 @@ public function getMessages(): array
return $this->messages;
}

protected function doEnterNode(Node $node, Environment $env): Node
public function enterNode(Node $node, Environment $env): Node
{
if (!$this->enabled) {
return $node;
Expand Down Expand Up @@ -98,7 +98,7 @@ protected function doEnterNode(Node $node, Environment $env): Node
return $node;
}

protected function doLeaveNode(Node $node, Environment $env): ?Node
public function leaveNode(Node $node, Environment $env): ?Node
{
return $node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private function getCallableData(mixed $callable): array
$data['type'] = 'closure';

$r = new \ReflectionFunction($callable);
if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
return $data;
}
$data['name'] = $r->name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ protected function describeCallable(mixed $callable, array $options = []): void
$string .= "\n- Type: `closure`";

$r = new \ReflectionFunction($callable);
if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
$this->write($string."\n");

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ private function formatCallable(mixed $callable): string

if ($callable instanceof \Closure) {
$r = new \ReflectionFunction($callable);
if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
return 'Closure()';
}
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ private function getCallableDocument(mixed $callable): \DOMDocument
$callableXML->setAttribute('type', 'closure');

$r = new \ReflectionFunction($callable);
if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
return $dom;
}
$callableXML->setAttribute('name', $r->name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection

if (\is_array($controller) && [0, 1] === array_keys($controller) && $this === $controller[0]) {
$route->setDefault('_controller', ['kernel', $controller[1]]);
} elseif ($controller instanceof \Closure && $this === ($r = new \ReflectionFunction($controller))->getClosureThis() && !str_contains($r->name, '{closure}')) {
} elseif ($controller instanceof \Closure && $this === ($r = new \ReflectionFunction($controller))->getClosureThis() && !str_contains($r->name, '{closure')) {
$route->setDefault('_controller', ['kernel', $r->name]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private function formatCallable(mixed $callable): string

if ($callable instanceof \Closure) {
$r = new \ReflectionFunction($callable);
if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
return 'Closure()';
}
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
Expand Down
12 changes: 9 additions & 3 deletions src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public function testCreateConnection(string $dsn, string $expectedClass)
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
}

$mock = self::getObjectForTrait(RedisTrait::class);
$mock = new class () {
use RedisTrait;
};
$connection = $mock::createConnection($dsn);

self::assertInstanceOf($expectedClass, $connection);
Expand All @@ -43,7 +45,9 @@ public function testUrlDecodeParameters()
self::markTestSkipped('REDIS_AUTHENTICATED_HOST env var is not defined.');
}

$mock = self::getObjectForTrait(RedisTrait::class);
$mock = new class () {
use RedisTrait;
};
$connection = $mock::createConnection('redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST'));

self::assertInstanceOf(\Redis::class, $connection);
Expand Down Expand Up @@ -100,7 +104,9 @@ public function testPconnectSelectsCorrectDatabase()
}

try {
$mock = self::getObjectForTrait(RedisTrait::class);
$mock = new class () {
use RedisTrait;
};

$dsn = 'redis://'.getenv('REDIS_HOST');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function testCallErrorExceptionInfo()
$this->assertSame('Undefined variable $foo', $e->getMessage());
$this->assertSame(__FILE__, $e->getFile());
$this->assertSame(0, $e->getCode());
$this->assertSame('Symfony\Component\ErrorHandler\{closure}', $trace[0]['function']);
$this->assertStringMatchesFormat('%A{closure%A}', $trace[0]['function']);
$this->assertSame(ErrorHandler::class, $trace[0]['class']);
$this->assertSame('triggerNotice', $trace[1]['function']);
$this->assertSame(__CLASS__, $trace[1]['class']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(callable|array $listener, ?string $name, Stopwatch $
$this->callableRef .= '::'.$listener[1];
} elseif ($listener instanceof \Closure) {
$r = new \ReflectionFunction($listener);
if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
$this->pretty = $this->name = 'closure';
} elseif ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
$this->name = $class->name;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ public function testCopyForOriginUrlsAndExistingLocalFileDefaultsToCopy()
}

$finder = new PhpExecutableFinder();
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:8057']));
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', 'localhost:8057']));
$process->setWorkingDirectory(__DIR__.'/Fixtures/web');

$process->start();

do {
usleep(50000);
} while (!@fopen('http://127.0.0.1:8057', 'r'));
} while (!@fopen('http://localhost:8057', 'r'));

try {
$sourceFilePath = 'http://localhost:8057/logo_symfony_header.png';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private function checkController(Request $request, callable $controller): callab
$r = new \ReflectionFunction($controller);
$name = $r->name;

if (str_contains($name, '{closure}')) {
if (str_contains($name, '{closure')) {
$name = $class = \Closure::class;
} elseif ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
$class = $class->name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ private function parseController(array|object|string|null $controller): array|st
'line' => $r->getStartLine(),
];

if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
return $controller;
}
$controller['method'] = $r->name;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Event/ControllerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getAttributes(?string $className = null): array
} elseif (\is_string($this->controller) && false !== $i = strpos($this->controller, '::')) {
$class = new \ReflectionClass(substr($this->controller, 0, $i));
} else {
$class = str_contains($this->controllerReflector->name, '{closure}') ? null : (\PHP_VERSION_ID >= 80111 ? $this->controllerReflector->getClosureCalledClass() : $this->controllerReflector->getClosureScopeClass());
$class = str_contains($this->controllerReflector->name, '{closure') ? null : (\PHP_VERSION_ID >= 80111 ? $this->controllerReflector->getClosureCalledClass() : $this->controllerReflector->getClosureScopeClass());
}
$this->attributes = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static function provideControllerCallables(): array
'Closure',
fn () => 'foo',
[
'class' => __NAMESPACE__.'\{closure}',
'class' => \PHP_VERSION_ID >= 80400 ? sprintf('{closure:%s():%d}', __METHOD__, __LINE__ - 2) : __NAMESPACE__.'\{closure}',
'method' => null,
'file' => __FILE__,
'line' => __LINE__ - 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(callable $handler, array $options = [])

$r = new \ReflectionFunction($handler);

if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
$this->name = 'Closure';
} elseif (!$handler = $r->getClosureThis()) {
$class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass();
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Mime/Tests/Part/DataPartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ public function testFromPathWithUrl()
}

$finder = new PhpExecutableFinder();
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:8057']));
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', 'localhost:8057']));
$process->setWorkingDirectory(__DIR__.'/../Fixtures/web');
$process->start();

try {
do {
usleep(50000);
} while (!@fopen('http://127.0.0.1:8057', 'r'));
} while (!@fopen('http://localhost:8057', 'r'));
$p = DataPart::fromPath($file = 'http://localhost:8057/logo_symfony_header.png');
$content = file_get_contents($file);
$this->assertEquals($content, $p->getBody());
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/LazyString.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static function getPrettyName(callable $callback): string
} elseif ($callback instanceof \Closure) {
$r = new \ReflectionFunction($callback);

if (str_contains($r->name, '{closure}') || !$class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
if (str_contains($r->name, '{closure') || !$class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
return $r->name;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/Tests/LazyStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testReturnTypeError()
$s = LazyString::fromCallable(fn () => []);

$this->expectException(\TypeError::class);
$this->expectExceptionMessage('Return value of '.__NAMESPACE__.'\{closure}() passed to '.LazyString::class.'::fromCallable() must be of the type string, array returned.');
$this->expectExceptionMessageMatches('{^Return value of .*\{closure.*\}\(\) passed to '.preg_quote(LazyString::class).'::fromCallable\(\) must be of the type string, array returned\.$}');

(string) $s;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function castClosure(\Closure $c, array $a, Stub $stub, bool $isNe

$a = static::castFunctionAbstract($c, $a, $stub, $isNested, $filter);

if (!str_contains($c->name, '{closure}')) {
if (!str_contains($c->name, '{closure')) {
$stub->class = isset($a[$prefix.'class']) ? $a[$prefix.'class']->value.'::'.$c->name : $c->name;
unset($a[$prefix.'class']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private function summarizeListener(callable $callable, ?string $eventName = null

if ($callable instanceof \Closure) {
$r = new \ReflectionFunction($callable);
if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
$title = (string) $r;
} elseif ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
$title = $class->name.'::'.$r->name.'()';
Expand Down

0 comments on commit 8477f02

Please sign in to comment.