File tree 5 files changed +85
-43
lines changed
src/Symfony/Component/DependencyInjection
5 files changed +85
-43
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,12 @@ public function __construct()
71
71
new CheckArgumentsValidityPass (false ),
72
72
));
73
73
74
+ $ this ->beforeRemovingPasses = array (
75
+ -100 => array (
76
+ new ResolvePrivatesPass (),
77
+ ),
78
+ );
79
+
74
80
$ this ->removingPasses = array (array (
75
81
new RemovePrivateAliasesPass (),
76
82
new ReplaceAliasByActualDefinitionPass (),
Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \DependencyInjection \Compiler ;
13
13
14
14
use Symfony \Component \DependencyInjection \ChildDefinition ;
15
- use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
15
use Symfony \Component \DependencyInjection \Definition ;
17
16
use Symfony \Component \DependencyInjection \Exception \ExceptionInterface ;
18
17
use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
26
25
*/
27
26
class ResolveChildDefinitionsPass extends AbstractRecursivePass
28
27
{
29
- /**
30
- * {@inheritdoc}
31
- */
32
- public function process (ContainerBuilder $ container )
33
- {
34
- parent ::process ($ container );
35
-
36
- foreach ($ container ->getDefinitions () as $ definition ) {
37
- if ($ definition ->isPrivate ()) {
38
- $ definition ->setPublic (false );
39
- $ definition ->setPrivate (true );
40
- }
41
- }
42
-
43
- foreach ($ container ->getAliases () as $ alias ) {
44
- if ($ alias ->isPrivate ()) {
45
- $ alias ->setPublic (false );
46
- $ alias ->setPrivate (true );
47
- }
48
- }
49
- }
50
-
51
28
protected function processValue ($ value , $ isRoot = false )
52
29
{
53
30
if (!$ value instanceof Definition) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Component \DependencyInjection \Compiler ;
13
+
14
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
15
+
16
+ /**
17
+ * @author Nicolas Grekas <[email protected] >
18
+ */
19
+ class ResolvePrivatesPass implements CompilerPassInterface
20
+ {
21
+ /**
22
+ * {@inheritdoc}
23
+ */
24
+ public function process (ContainerBuilder $ container )
25
+ {
26
+ foreach ($ container ->getDefinitions () as $ id => $ definition ) {
27
+ if ($ definition ->isPrivate ()) {
28
+ $ definition ->setPublic (false );
29
+ $ definition ->setPrivate (true );
30
+ }
31
+ }
32
+
33
+ foreach ($ container ->getAliases () as $ id => $ alias ) {
34
+ if ($ alias ->isPrivate ()) {
35
+ $ alias ->setPublic (false );
36
+ $ alias ->setPrivate (true );
37
+ }
38
+ }
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -397,26 +397,6 @@ public function testSetAutoconfiguredOnServiceIsParent()
397
397
$ this ->assertFalse ($ container ->getDefinition ('child1 ' )->isAutoconfigured ());
398
398
}
399
399
400
- public function testPrivateHasHigherPrecedenceThanPublic ()
401
- {
402
- $ container = new ContainerBuilder ();
403
-
404
- $ container ->register ('foo ' , 'stdClass ' )
405
- ->setPublic (true )
406
- ->setPrivate (true )
407
- ;
408
-
409
- $ container ->setAlias ('bar ' , 'foo ' )
410
- ->setPublic (false )
411
- ->setPrivate (false )
412
- ;
413
-
414
- $ this ->process ($ container );
415
-
416
- $ this ->assertFalse ($ container ->getDefinition ('foo ' )->isPublic ());
417
- $ this ->assertFalse ($ container ->getAlias ('bar ' )->isPublic ());
418
- }
419
-
420
400
/**
421
401
* @group legacy
422
402
*/
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Component \DependencyInjection \Tests \Compiler ;
13
+
14
+ use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \DependencyInjection \Compiler \ResolvePrivatesPass ;
16
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
17
+
18
+ class ResolvePrivatesPassTest extends TestCase
19
+ {
20
+ public function testPrivateHasHigherPrecedenceThanPublic ()
21
+ {
22
+ $ container = new ContainerBuilder ();
23
+
24
+ $ container ->register ('foo ' , 'stdClass ' )
25
+ ->setPublic (true )
26
+ ->setPrivate (true )
27
+ ;
28
+
29
+ $ container ->setAlias ('bar ' , 'foo ' )
30
+ ->setPublic (false )
31
+ ->setPrivate (false )
32
+ ;
33
+
34
+ (new ResolvePrivatesPass ())->process ($ container );
35
+
36
+ $ this ->assertFalse ($ container ->getDefinition ('foo ' )->isPublic ());
37
+ $ this ->assertFalse ($ container ->getAlias ('bar ' )->isPublic ());
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments