Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  Revert "minor symfony#47721 [Notifier] Use local copy of stella-maris/clock when testing (nicolas-grekas)"
  [Yaml] Minor: Update Inline parse phpdoc
  [FrameworkBundle] Fix deprecation when accessing a "container.private" service from the test container
  [DependencyInjection] Fix dumping inlined withers
  [HttpClient] Move Http clients data collecting at a late level
  [DependencyInjection] Fix support for named arguments on non-autowired services
  [FrameworkBundle] restore call to addGlobalIgnoredName
  Allow EmailValidator 4
  Fix detecting mapping with one line annotations
  • Loading branch information
nicolas-grekas committed Jan 11, 2023
2 parents 9aa058a + 22b5860 commit ac438a4
Show file tree
Hide file tree
Showing 29 changed files with 155 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- name: Find packages
id: find-packages
run: echo "packages=$(php .github/get-modified-packages.php $(find src/Symfony -mindepth 2 -maxdepth 6 -type f -name composer.json -printf '%h\n' | jq -R -s -c 'split("\n")[:-1]') $(git diff --name-only origin/${{ github.base_ref }} HEAD | grep src/ | jq -R -s -c 'split("\n")[:-1]'))" >> $GITHUB_OUTPUT
run: echo "packages=$(php .github/get-modified-packages.php $(find src/Symfony -mindepth 2 -type f -name composer.json -printf '%h\n' | jq -R -s -c 'split("\n")[:-1]') $(git diff --name-only origin/${{ github.base_ref }} HEAD | grep src/ | jq -R -s -c 'split("\n")[:-1]'))" >> $GITHUB_OUTPUT

- name: Verify meta files are correct
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
echo SYMFONY_DEPRECATIONS_HELPER=weak >> $GITHUB_ENV
cp composer.json composer.json.orig
echo -e '{\n"require":{'"$(grep phpunit-bridge composer.json)"'"php":"*"},"minimum-stability":"dev"}' > composer.json
php .github/build-packages.php HEAD^ $SYMFONY_VERSION $(find src/Symfony -mindepth 2 -maxdepth 6 -type f -name composer.json -printf '%h\n')
php .github/build-packages.php HEAD^ $SYMFONY_VERSION $(find src/Symfony -mindepth 2 -type f -name composer.json -printf '%h\n')
mv composer.json composer.json.phpunit
mv composer.json.orig composer.json
fi
Expand Down
9 changes: 0 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,6 @@
{
"type": "path",
"url": "src/Symfony/Component/Runtime"
},
{
"type": "path",
"url": "src/Symfony/Component/Notifier/Bridge/Mercure/Tests/stella-maris-clock",
"options": {
"versions": {
"stella-maris/clock": "0.1.x-dev"
}
}
}
],
"minimum-stability": "dev"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ private function detectMappingType(string $directory, ContainerBuilder $containe
break;
}
if (
preg_match('/^ \* @.*'.$quotedMappingObjectName.'\b/m', $content) ||
preg_match('/^ \* @.*Embeddable\b/m', $content)
preg_match('/^(?: \*|\/\*\*) @.*'.$quotedMappingObjectName.'\b/m', $content) ||
preg_match('/^(?: \*|\/\*\*) @.*Embeddable\b/m', $content)
) {
$type = 'annotation';
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public function testUnrecognizedCacheDriverException()
public function providerBundles()
{
yield ['AnnotationsBundle', 'annotation', '/Entity'];
yield ['AnnotationsOneLineBundle', 'annotation', '/Entity'];
yield ['FullEmbeddableAnnotationsBundle', 'annotation', '/Entity'];
yield ['AttributesBundle', 'attribute', '/Entity'];
yield ['FullEmbeddableAttributesBundle', 'attribute', '/Entity'];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fixtures\Bundles\AnnotationsOneLineBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AnnotationsOneLineBundle extends Bundle
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fixtures\Bundles\AnnotationsOneLineBundle\Entity;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;

/** @Entity */
class Person
{
/** @Id @Column(type="integer") */
protected $id;

/** @Column(type="string") */
public $name;

public function __construct($id, $name)
{
$this->id = $id;
$this->name = $name;
}

public function __toString(): string
{
return (string) $this->name;
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"require-dev": {
"doctrine/annotations": "^1.12|^2",
"egulias/email-validator": "^2.1.10|^3",
"egulias/email-validator": "^2.1.10|^3|^4",
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
"symfony/asset": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -38,6 +39,16 @@ public function process(ContainerBuilder $container)
}
}

foreach ($container->getAliases() as $id => $target) {
while ($container->hasAlias($target = (string) $target)) {
$target = $container->getAlias($target);
}

if ($definitions[$target]->hasTag('container.private')) {
$privateServices[$id] = new ServiceClosureArgument(new Reference($target));
}
}

$privateContainer->replaceArgument(0, $privateServices);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1569,11 +1569,14 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde

$loader->load('annotations.php');

// registerUniqueLoader exists since doctrine/annotations v1.6
if (!method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) {
// registerLoader exists only in doctrine/annotations v1
if (method_exists(AnnotationRegistry::class, 'registerLoader')) {
$container->getDefinition('annotations.dummy_registry')
->setMethodCalls([['registerLoader', ['class_exists']]]);
} else {
// remove the dummy registry when doctrine/annotations v2 is used
$container->removeDefinition('annotations.dummy_registry');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
->set('annotations.reader', AnnotationReader::class)
->call('addGlobalIgnoredName', [
'required',
service('annotations.dummy_registry')->ignoreOnInvalid(), // dummy arg to register class_exists as annotation loader only when required
service('annotations.dummy_registry')->nullOnInvalid(), // dummy arg to register class_exists as annotation loader only when required
])

->set('annotations.dummy_registry', AnnotationRegistry::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public function testProcess()
->setPublic(true)
->addTag('container.private', ['package' => 'foo/bar', 'version' => '1.42'])
;
$container->register('Test\soon_private_service_decorated')
->setPublic(true)
->addTag('container.private', ['package' => 'foo/bar', 'version' => '1.42'])
;
$container->register('Test\soon_private_service_decorator')
->setDecoratedService('Test\soon_private_service_decorated')
->setArguments(['Test\soon_private_service_decorator.inner']);

$container->register('Test\private_used_shared_service');
$container->register('Test\private_unused_shared_service');
Expand All @@ -55,6 +62,8 @@ public function testProcess()
'Test\private_used_shared_service' => new ServiceClosureArgument(new Reference('Test\private_used_shared_service')),
'Test\private_used_non_shared_service' => new ServiceClosureArgument(new Reference('Test\private_used_non_shared_service')),
'Test\soon_private_service' => new ServiceClosureArgument(new Reference('.container.private.Test\soon_private_service')),
'Test\soon_private_service_decorator' => new ServiceClosureArgument(new Reference('.container.private.Test\soon_private_service_decorated')),
'Test\soon_private_service_decorated' => new ServiceClosureArgument(new Reference('.container.private.Test\soon_private_service_decorated')),
];

$privateServices = $container->getDefinition('test.private_services_locator')->getArgument(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
foreach ($calls as $i => $call) {
[$method, $arguments] = $call;
$parameters = null;
$resolvedKeys = [];
$resolvedArguments = [];

foreach ($arguments as $key => $argument) {
Expand All @@ -51,6 +52,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
}

if (\is_int($key)) {
$resolvedKeys[$key] = $key;
$resolvedArguments[$key] = $argument;
continue;
}
Expand All @@ -71,9 +73,11 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
if ($key === '$'.$p->name) {
if ($p->isVariadic() && \is_array($argument)) {
foreach ($argument as $variadicArgument) {
$resolvedKeys[$j] = $j;
$resolvedArguments[$j++] = $variadicArgument;
}
} else {
$resolvedKeys[$j] = $p->name;
$resolvedArguments[$j] = $argument;
}

Expand All @@ -91,6 +95,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
$typeFound = false;
foreach ($parameters as $j => $p) {
if (!\array_key_exists($j, $resolvedArguments) && ProxyHelper::getTypeHint($r, $p, true) === $key) {
$resolvedKeys[$j] = $p->name;
$resolvedArguments[$j] = $argument;
$typeFound = true;
}
Expand All @@ -103,6 +108,12 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed

if ($resolvedArguments !== $call[1]) {
ksort($resolvedArguments);

if (!$value->isAutowired() && !array_is_list($resolvedArguments)) {
ksort($resolvedKeys);
$resolvedArguments = array_combine($resolvedKeys, $resolvedArguments);
}

$calls[$i][1] = $resolvedArguments;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ private function createService(Definition $definition, array &$inlineServices, b
} else {
$r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass()));

$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs(array_values($arguments));
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);

if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ private function addServiceMethodCalls(Definition $definition, string $variableN
$witherAssignation = '';

if ($call[2] ?? false) {
if (null !== $sharedNonLazyId && $lastWitherIndex === $k) {
if (null !== $sharedNonLazyId && $lastWitherIndex === $k && 'instance' === $variableName) {
$witherAssignation = sprintf('$this->%s[\'%s\'] = ', $definition->isPublic() ? 'services' : 'privates', $sharedNonLazyId);
}
$witherAssignation .= sprintf('$%s = ', $variableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function testInterfaceTypedArgument()
$pass = new ResolveNamedArgumentsPass();
$pass->process($container);

$this->assertSame($expected, $definition->getArgument(3));
$this->assertSame($expected, $definition->getArgument('container'));
}

public function testResolvesMultipleArgumentsOfTheSameType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,24 @@ public function testFindTags()

$this->assertSame(['tag1', 'tag2', 'tag3'], $container->findTags());
}

/**
* @requires PHP 8
*/
public function testNamedArgument()
{
$container = new ContainerBuilder();
$container->register(E::class)
->setPublic(true)
->setArguments(['$second' => 2]);

$container->compile();

$e = $container->get(E::class);

$this->assertSame('', $e->first);
$this->assertSame(2, $e->second);
}
}

class FooClass
Expand Down Expand Up @@ -1759,3 +1777,15 @@ class C implements X
class D implements X
{
}

class E
{
public $first;
public $second;

public function __construct($first = '', $second = '')
{
$this->first = $first;
$this->second = $second;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,8 @@ public function testAliasCanBeFoundInTheDumpedContainerWhenBothTheAliasAndTheSer
public function testWither()
{
$container = new ContainerBuilder();
$container->register(Foo::class);
$container->register(Foo::class)
->setAutowired(true);

$container
->register('wither', Wither::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

class Foo
{
/**
* @required
* @return static
*/
public function cloneFoo()
{
return clone $this;
}
}

class Bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function getWitherService()
$instance = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither();

$a = new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo();
$a = $a->cloneFoo();

$instance = $instance->withFoo1($a);
$this->services['wither'] = $instance = $instance->withFoo2($a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function registerClient(string $name, TraceableHttpClient $client)
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
}

public function lateCollect()
{
$this->reset();

Expand All @@ -50,12 +54,7 @@ public function collect(Request $request, Response $response, \Throwable $except

$this->data['request_count'] += \count($traces);
$this->data['error_count'] += $errorCount;
}
}

public function lateCollect()
{
foreach ($this->clients as $client) {
$client->reset();
}
}
Expand Down
Loading

0 comments on commit ac438a4

Please sign in to comment.