File tree Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Symfony \Bundle \FrameworkBundle \FrameworkBundle ;
6
6
use Symfony \Component \Config \Loader \LoaderInterface ;
7
+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
7
8
use Symfony \Component \DependencyInjection \ContainerBuilder ;
8
9
use Symfony \Component \HttpKernel \Kernel ;
9
10
use Symfony \Component \Routing \RouteCollectionBuilder ;
@@ -33,6 +34,11 @@ class AppKernel extends Kernel
33
34
*/
34
35
private $ fakedProjectDir ;
35
36
37
+ /**
38
+ * @var CompilerPassInterface[]
39
+ */
40
+ private $ compilerPasses = [];
41
+
36
42
/**
37
43
* @param string $cachePrefix
38
44
*/
@@ -141,4 +147,27 @@ public function loadRoutes(LoaderInterface $loader)
141
147
142
148
return $ routes ->build ();
143
149
}
150
+
151
+ /**
152
+ * {@inheritdoc}
153
+ */
154
+ protected function buildContainer ()
155
+ {
156
+ $ container = parent ::buildContainer ();
157
+
158
+ foreach ($ this ->compilerPasses as $ pass ) {
159
+ $ container ->addCompilerPass ($ pass );
160
+ }
161
+
162
+ return $ container ;
163
+ }
164
+
165
+
166
+ /**
167
+ * @param CompilerPassInterface[] $compilerPasses
168
+ */
169
+ public function addCompilerPasses (array $ compilerPasses )
170
+ {
171
+ $ this ->compilerPasses = $ compilerPasses ;
172
+ }
144
173
}
Original file line number Diff line number Diff line change 3
3
namespace Nyholm \BundleTest ;
4
4
5
5
use PHPUnit \Framework \TestCase ;
6
+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
6
7
use Symfony \Component \DependencyInjection \ResettableContainerInterface ;
7
8
use Symfony \Component \HttpKernel \Kernel ;
8
9
@@ -16,6 +17,11 @@ abstract class BaseBundleTestCase extends TestCase
16
17
*/
17
18
private $ kernel ;
18
19
20
+ /**
21
+ * @var CompilerPassInterface[]
22
+ */
23
+ private $ compilerPasses = [];
24
+
19
25
/**
20
26
* @return string
21
27
*/
@@ -61,6 +67,7 @@ protected function createKernel()
61
67
62
68
$ this ->kernel = new $ class (uniqid ('cache ' ));
63
69
$ this ->kernel ->addBundle ($ this ->getBundleClass ());
70
+ $ this ->kernel ->addCompilerPasses ($ this ->compilerPasses );
64
71
65
72
return $ this ->kernel ;
66
73
}
@@ -86,4 +93,12 @@ protected function tearDown()
86
93
{
87
94
$ this ->ensureKernelShutdown ();
88
95
}
96
+
97
+ /**
98
+ * @param CompilerPassInterface $compilerPass
99
+ */
100
+ protected function addCompilerPass (CompilerPassInterface $ compilerPass )
101
+ {
102
+ $ this ->compilerPasses [] = $ compilerPass ;
103
+ }
89
104
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Nyholm \BundleTest \CompilerPass ;
4
+
5
+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
6
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
7
+
8
+ /**
9
+ * @author Tobias Nyholm <[email protected] >
10
+ */
11
+ class PublicServicePass implements CompilerPassInterface
12
+ {
13
+ /**
14
+ * A regex to match the services that should be public
15
+ * @var string
16
+ */
17
+ private $ regex ;
18
+
19
+ /**
20
+ * @param string $regex
21
+ */
22
+ public function __construct ($ regex = '|.*| ' )
23
+ {
24
+ $ this ->regex = $ regex ;
25
+ }
26
+
27
+ public function process (ContainerBuilder $ container ) {
28
+ foreach ($ container ->getDefinitions () as $ id => $ definition ) {
29
+ if (preg_match ($ this ->regex , $ id )) {
30
+ $ definition ->setPublic (true );
31
+ }
32
+ }
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments