Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
*/
class DecoratorServicePass extends AbstractRecursivePass
{
/**
* @var array<string, string>
*/
public array $decoratedServices = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public array $decoratedServices = [];
private array $decoratedServices = [];


/**
* @return void
*/
Expand All @@ -42,6 +47,7 @@ public function process(ContainerBuilder $container)
$definitions->insert([$id, $definition], [$decorated[2], --$order]);
}
$decoratingDefinitions = [];
$this->decoratedServices = [];

$tagsToKeep = $container->hasParameter('container.behavior_describing_tags')
? $container->getParameter('container.behavior_describing_tags')
Expand Down Expand Up @@ -111,9 +117,18 @@ public function process(ContainerBuilder $container)
}

$container->setAlias($inner, $id)->setPublic($public);
$this->decoratedServices[$inner] = $id;
}
}

/**
* @return array<string, string>
*/
public function getDecoratedServices(): array
{
return $this->decoratedServices;
}

protected function processValue(mixed $value, bool $isRoot = false): mixed
{
if ($value instanceof Reference && '.inner' === (string) $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public function __construct()
new AutowireRequiredPropertiesPass(),
new ResolveBindingsPass(),
new ServiceLocatorTagPass(),
new DecoratorServicePass(),
$decoratorPass = new DecoratorServicePass(),
new CheckDefinitionValidityPass(),
new AutowirePass(false),
new ServiceLocatorTagPass(),
new ResolveTaggedIteratorArgumentPass(),
new ResolveServiceSubscribersPass(),
new ResolveReferencesToAliasesPass(),
new ResolveReferencesToAliasesPass($decoratorPass),
new ResolveInvalidReferencesPass(),
new AnalyzeServiceReferencesPass(true),
new CheckCircularReferencesPass(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@
*/
class ResolveReferencesToAliasesPass extends AbstractRecursivePass
{
public function __construct(
private ?DecoratorServicePass $decoratorPass = null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private ?DecoratorServicePass $decoratorPass = null,
private readonly ?DecoratorServicePass $decoratorPass = null,

) {
}

/**
* @return void
*/
public function process(ContainerBuilder $container)
{
foreach ($this->decoratorPass?->getDecoratedServices() ?? [] as $inner => $id) {
$definition = $container->getDefinition($id);
$alias = $container->getAlias($inner);
$container->setAlias($id, $inner)->setPublic($definition->isPublic());
$container->setDefinition($inner, $definition)->setPublic($alias->isPublic());
}

parent::process($container);

foreach ($container->getAliases() as $id => $alias) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ services:
class: Symfony\Component\DependencyInjection\ContainerInterface
public: true
synthetic: true
foo:
bar:
class: Class2
public: true
file: file.php
lazy: true
arguments: [!service { class: Class1 }]
bar:
alias: foo
foo:
alias: bar
public: true
Original file line number Diff line number Diff line change
Expand Up @@ -165,33 +165,33 @@ class getConfiguredServiceSimpleService extends ProjectServiceContainer
}
}

[Container%s/getDecoratorServiceService.php] => <?php
[Container%s/getDecoratedService.php] => <?php
%A
class getDecoratorServiceService extends ProjectServiceContainer
class getDecoratedService extends ProjectServiceContainer
{
/**
* Gets the public 'decorator_service' shared service.
* Gets the public 'decorated' shared service.
*
* @return \stdClass
*/
public static function do($container, $lazyLoad = true)
{
return $container->services['decorator_service'] = new \stdClass();
return $container->services['decorated'] = new \stdClass();
}
}

[Container%s/getDecoratorServiceWithNameService.php] => <?php
[Container%s/getDecoratorServiceService.php] => <?php
%A
class getDecoratorServiceWithNameService extends ProjectServiceContainer
class getDecoratorServiceService extends ProjectServiceContainer
{
/**
* Gets the public 'decorator_service_with_name' shared service.
* Gets the public 'decorator_service' shared service.
*
* @return \stdClass
*/
public static function do($container, $lazyLoad = true)
{
return $container->services['decorator_service_with_name'] = new \stdClass();
return $container->services['decorator_service'] = new \stdClass();
}
}

Expand Down Expand Up @@ -585,8 +585,8 @@ class ProjectServiceContainer extends Container
'baz' => 'getBazService',
'configured_service' => 'getConfiguredServiceService',
'configured_service_simple' => 'getConfiguredServiceSimpleService',
'decorated' => 'getDecoratedService',
'decorator_service' => 'getDecoratorServiceService',
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
'deprecated_service' => 'getDeprecatedServiceService',
'factory_service' => 'getFactoryServiceService',
'factory_service_simple' => 'getFactoryServiceSimpleService',
Expand All @@ -608,7 +608,7 @@ class ProjectServiceContainer extends Container
$this->aliases = [
'alias_for_alias' => 'foo',
'alias_for_foo' => 'foo',
'decorated' => 'decorator_service_with_name',
'decorator_service_with_name' => 'decorated',
];
}

Expand Down Expand Up @@ -753,8 +753,8 @@ require __DIR__.'/Container%s/getFoo_BazService.php';
require __DIR__.'/Container%s/getFooService.php';
require __DIR__.'/Container%s/getFactoryServiceSimpleService.php';
require __DIR__.'/Container%s/getFactoryServiceService.php';
require __DIR__.'/Container%s/getDecoratorServiceWithNameService.php';
require __DIR__.'/Container%s/getDecoratorServiceService.php';
require __DIR__.'/Container%s/getDecoratedService.php';
require __DIR__.'/Container%s/getConfiguredServiceSimpleService.php';
require __DIR__.'/Container%s/getConfiguredServiceService.php';
require __DIR__.'/Container%s/getBazService.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function __construct()
'baz' => 'getBazService',
'configured_service' => 'getConfiguredServiceService',
'configured_service_simple' => 'getConfiguredServiceSimpleService',
'decorated' => 'getDecoratedService',
'decorator_service' => 'getDecoratorServiceService',
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
'deprecated_service' => 'getDeprecatedServiceService',
'factory_service' => 'getFactoryServiceService',
'factory_service_simple' => 'getFactoryServiceSimpleService',
Expand All @@ -57,7 +57,7 @@ public function __construct()
$this->aliases = [
'alias_for_alias' => 'foo',
'alias_for_foo' => 'foo',
'decorated' => 'decorator_service_with_name',
'decorator_service_with_name' => 'decorated',
];
}

Expand Down Expand Up @@ -203,23 +203,23 @@ protected static function getConfiguredServiceSimpleService($container)
}

/**
* Gets the public 'decorator_service' shared service.
* Gets the public 'decorated' shared service.
*
* @return \stdClass
*/
protected static function getDecoratorServiceService($container)
protected static function getDecoratedService($container)
{
return $container->services['decorator_service'] = new \stdClass();
return $container->services['decorated'] = new \stdClass();
}

/**
* Gets the public 'decorator_service_with_name' shared service.
* Gets the public 'decorator_service' shared service.
*
* @return \stdClass
*/
protected static function getDecoratorServiceWithNameService($container)
protected static function getDecoratorServiceService($container)
{
return $container->services['decorator_service_with_name'] = new \stdClass();
return $container->services['decorator_service'] = new \stdClass();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class ProjectServiceContainer extends Container
'baz' => 'getBazService',
'configured_service' => 'getConfiguredServiceService',
'configured_service_simple' => 'getConfiguredServiceSimpleService',
'decorated' => 'getDecoratedService',
'decorator_service' => 'getDecoratorServiceService',
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
'deprecated_service' => 'getDeprecatedServiceService',
'factory_service' => 'getFactoryServiceService',
'factory_service_simple' => 'getFactoryServiceSimpleService',
Expand All @@ -83,7 +83,7 @@ class ProjectServiceContainer extends Container
$this->aliases = [
'alias_for_alias' => 'foo',
'alias_for_foo' => 'foo',
'decorated' => 'decorator_service_with_name',
'decorator_service_with_name' => 'decorated',
];

$this->privates['service_container'] = static function ($container) {
Expand Down Expand Up @@ -222,23 +222,23 @@ class ProjectServiceContainer extends Container
}

/**
* Gets the public 'decorator_service' shared service.
* Gets the public 'decorated' shared service.
*
* @return \stdClass
*/
protected static function getDecoratorServiceService($container)
protected static function getDecoratedService($container)
{
return $container->services['decorator_service'] = new \stdClass();
return $container->services['decorated'] = new \stdClass();
}

/**
* Gets the public 'decorator_service_with_name' shared service.
* Gets the public 'decorator_service' shared service.
*
* @return \stdClass
*/
protected static function getDecoratorServiceWithNameService($container)
protected static function getDecoratorServiceService($container)
{
return $container->services['decorator_service_with_name'] = new \stdClass();
return $container->services['decorator_service'] = new \stdClass();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function __construct()
'baz' => 'getBazService',
'configured_service' => 'getConfiguredServiceService',
'configured_service_simple' => 'getConfiguredServiceSimpleService',
'decorated' => 'getDecoratedService',
'decorator_service' => 'getDecoratorServiceService',
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
'deprecated_service' => 'getDeprecatedServiceService',
'factory_service' => 'getFactoryServiceService',
'factory_service_simple' => 'getFactoryServiceSimpleService',
Expand All @@ -57,7 +57,7 @@ public function __construct()
$this->aliases = [
'alias_for_alias' => 'foo',
'alias_for_foo' => 'foo',
'decorated' => 'decorator_service_with_name',
'decorator_service_with_name' => 'decorated',
];
}

Expand Down Expand Up @@ -203,23 +203,23 @@ protected static function getConfiguredServiceSimpleService($container)
}

/**
* Gets the public 'decorator_service' shared service.
* Gets the public 'decorated' shared service.
*
* @return \stdClass
*/
protected static function getDecoratorServiceService($container)
protected static function getDecoratedService($container)
{
return $container->services['decorator_service'] = new \stdClass();
return $container->services['decorated'] = new \stdClass();
}

/**
* Gets the public 'decorator_service_with_name' shared service.
* Gets the public 'decorator_service' shared service.
*
* @return \stdClass
*/
protected static function getDecoratorServiceWithNameService($container)
protected static function getDecoratorServiceService($container)
{
return $container->services['decorator_service_with_name'] = new \stdClass();
return $container->services['decorator_service'] = new \stdClass();
}

/**
Expand Down