Skip to content

Commit 93123c0

Browse files
[DI] deprecate Definition/Alias::setPrivate()
1 parent 807ca4e commit 93123c0

File tree

66 files changed

+143
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+143
-218
lines changed

Alias.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ class Alias
1717
{
1818
private $id;
1919
private $public;
20-
private $private;
2120
private $deprecation = [];
2221

2322
private static $defaultDeprecationTemplate = 'The "%alias_id%" service alias is deprecated. You should stop using it, as it will be removed in the future.';
2423

25-
public function __construct(string $id, bool $public = true)
24+
public function __construct(string $id, bool $public = false)
2625
{
2726
$this->id = $id;
2827
$this->public = $public;
29-
$this->private = 2 > \func_num_args();
3028
}
3129

3230
/**
@@ -47,26 +45,22 @@ public function isPublic()
4745
public function setPublic(bool $boolean)
4846
{
4947
$this->public = $boolean;
50-
$this->private = false;
5148

5249
return $this;
5350
}
5451

5552
/**
5653
* Sets if this Alias is private.
5754
*
58-
* When set, the "private" state has a higher precedence than "public".
59-
* In version 3.4, a "private" alias always remains publicly accessible,
60-
* but triggers a deprecation notice when accessed from the container,
61-
* so that the alias can be made really private in 4.0.
62-
*
6355
* @return $this
56+
*
57+
* @deprecated since Symfony 5.2, use setPublic() instead
6458
*/
6559
public function setPrivate(bool $boolean)
6660
{
67-
$this->private = $boolean;
61+
trigger_deprecation('symfony/dependency-injection', '5.2', 'The "%s()" method is deprecated, use "setPublic()" instead.', __METHOD__);
6862

69-
return $this;
63+
return $this->setPublic(!$boolean);
7064
}
7165

7266
/**
@@ -76,7 +70,7 @@ public function setPrivate(bool $boolean)
7670
*/
7771
public function isPrivate()
7872
{
79-
return $this->private;
73+
return !$this->public;
8074
}
8175

8276
/**

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* added `param()` and `abstract_arg()` in the PHP-DSL
8+
* deprecated `Definition::setPrivate()` and `Alias::setPrivate()`, use `setPublic()` instead
89

910
5.1.0
1011
-----

ChildDefinition.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class ChildDefinition extends Definition
2929
public function __construct(string $parent)
3030
{
3131
$this->parent = $parent;
32-
$this->setPrivate(false);
3332
}
3433

3534
/**

Compiler/DecoratorServicePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function process(ContainerBuilder $container)
104104
$decoratingDefinitions[$inner] = $definition;
105105
}
106106

107-
$container->setAlias($inner, $id)->setPublic($public)->setPrivate($private);
107+
$container->setAlias($inner, $id)->setPublic($public);
108108
}
109109
}
110110

Compiler/PassConfig.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ public function __construct()
7474
new CheckArgumentsValidityPass(false),
7575
]];
7676

77-
$this->beforeRemovingPasses = [
78-
-100 => [
79-
new ResolvePrivatesPass(),
80-
],
81-
];
82-
8377
$this->removingPasses = [[
8478
new RemovePrivateAliasesPass(),
8579
new ReplaceAliasByActualDefinitionPass(),

Compiler/ReplaceAliasByActualDefinitionPass.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function process(ContainerBuilder $container)
4444
}
4545
// Check if target needs to be replaces
4646
if (isset($replacements[$targetId])) {
47-
$container->setAlias($definitionId, $replacements[$targetId])->setPublic($target->isPublic())->setPrivate($target->isPrivate());
47+
$container->setAlias($definitionId, $replacements[$targetId])->setPublic($target->isPublic());
4848
}
4949
// No need to process the same target twice
5050
if (isset($seenAliasTargets[$targetId])) {
@@ -65,8 +65,7 @@ public function process(ContainerBuilder $container)
6565
continue;
6666
}
6767
// Remove private definition and schedule for replacement
68-
$definition->setPublic(!$target->isPrivate());
69-
$definition->setPrivate($target->isPrivate());
68+
$definition->setPublic($target->isPublic());
7069
$container->setDefinition($definitionId, $definition);
7170
$container->removeDefinition($targetId);
7271
$replacements[$targetId] = $definitionId;

Compiler/ResolveChildDefinitionsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function doResolveDefinition(ChildDefinition $definition): Definition
132132
if (isset($changes['public'])) {
133133
$def->setPublic($definition->isPublic());
134134
} else {
135-
$def->setPrivate($definition->isPrivate() || $parentDef->isPrivate());
135+
$def->setPublic($parentDef->isPublic());
136136
}
137137
if (isset($changes['lazy'])) {
138138
$def->setLazy($definition->isLazy());

Compiler/ResolvePrivatesPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

14+
trigger_deprecation('symfony/dependency-injection', '5.2', 'The "%s" class is deprecated.', ResolvePrivatesPass::class);
15+
1416
use Symfony\Component\DependencyInjection\ContainerBuilder;
1517

1618
/**
1719
* @author Nicolas Grekas <[email protected]>
20+
*
21+
* @deprecated since Symfony 5.2
1822
*/
1923
class ResolvePrivatesPass implements CompilerPassInterface
2024
{

Compiler/ResolveReferencesToAliasesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function process(ContainerBuilder $container)
3434
$this->currentId = $id;
3535

3636
if ($aliasId !== $defId = $this->getDefinitionId($aliasId, $container)) {
37-
$container->setAlias($id, $defId)->setPublic($alias->isPublic())->setPrivate($alias->isPrivate());
37+
$container->setAlias($id, $defId)->setPublic($alias->isPublic());
3838
}
3939
}
4040
}

Compiler/ServiceLocatorTagPass.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public static function register(ContainerBuilder $container, array $refMap, stri
106106

107107
$locator = (new Definition(ServiceLocator::class))
108108
->addArgument($refMap)
109-
->setPublic(false)
110109
->addTag('container.service_locator');
111110

112111
if (null !== $callerId && $container->hasDefinition($callerId)) {
@@ -123,7 +122,6 @@ public static function register(ContainerBuilder $container, array $refMap, stri
123122
// to have them specialized per consumer service, we use a cloning factory
124123
// to derivate customized instances from the prototype one.
125124
$container->register($id .= '.'.$callerId, ServiceLocator::class)
126-
->setPublic(false)
127125
->setFactory([new Reference($locatorId), 'withContext'])
128126
->addTag('container.service_locator_context', ['id' => $callerId])
129127
->addArgument($callerId)

0 commit comments

Comments
 (0)