|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
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 |
use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* This class is used to remove circular dependencies between individual passes. |
|
|
19 |
* |
|
|
20 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
21 |
* |
|
|
22 |
* @api |
|
|
23 |
*/ |
|
|
24 |
class Compiler |
|
|
25 |
{ |
|
|
26 |
private $passConfig; |
|
|
27 |
private $log; |
|
|
28 |
private $loggingFormatter; |
|
|
29 |
private $serviceReferenceGraph; |
|
|
30 |
|
|
|
31 |
/** |
|
|
32 |
* Constructor. |
|
|
33 |
*/ |
|
|
34 |
public function __construct() |
|
|
35 |
{ |
|
|
36 |
$this->passConfig = new PassConfig(); |
|
|
37 |
$this->serviceReferenceGraph = new ServiceReferenceGraph(); |
|
|
38 |
$this->loggingFormatter = new LoggingFormatter(); |
|
|
39 |
$this->log = array(); |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
/** |
|
|
43 |
* Returns the PassConfig. |
|
|
44 |
* |
|
|
45 |
* @return PassConfig The PassConfig instance |
|
|
46 |
* |
|
|
47 |
* @api |
|
|
48 |
*/ |
|
|
49 |
public function getPassConfig() |
|
|
50 |
{ |
|
|
51 |
return $this->passConfig; |
|
|
52 |
} |
|
|
53 |
|
|
|
54 |
/** |
|
|
55 |
* Returns the ServiceReferenceGraph. |
|
|
56 |
* |
|
|
57 |
* @return ServiceReferenceGraph The ServiceReferenceGraph instance |
|
|
58 |
* |
|
|
59 |
* @api |
|
|
60 |
*/ |
|
|
61 |
public function getServiceReferenceGraph() |
|
|
62 |
{ |
|
|
63 |
return $this->serviceReferenceGraph; |
|
|
64 |
} |
|
|
65 |
|
|
|
66 |
/** |
|
|
67 |
* Returns the logging formatter which can be used by compilation passes. |
|
|
68 |
* |
|
|
69 |
* @return LoggingFormatter |
|
|
70 |
*/ |
|
|
71 |
public function getLoggingFormatter() |
|
|
72 |
{ |
|
|
73 |
return $this->loggingFormatter; |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
/** |
|
|
77 |
* Adds a pass to the PassConfig. |
|
|
78 |
* |
|
|
79 |
* @param CompilerPassInterface $pass A compiler pass |
|
|
80 |
* @param string $type The type of the pass |
|
|
81 |
* |
|
|
82 |
* @api |
|
|
83 |
*/ |
|
|
84 |
public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION) |
|
|
85 |
{ |
|
|
86 |
$this->passConfig->addPass($pass, $type); |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
/** |
|
|
90 |
* Adds a log message. |
|
|
91 |
* |
|
|
92 |
* @param string $string The log message |
|
|
93 |
*/ |
|
|
94 |
public function addLogMessage($string) |
|
|
95 |
{ |
|
|
96 |
$this->log[] = $string; |
|
|
97 |
} |
|
|
98 |
|
|
|
99 |
/** |
|
|
100 |
* Returns the log. |
|
|
101 |
* |
|
|
102 |
* @return array Log array |
|
|
103 |
*/ |
|
|
104 |
public function getLog() |
|
|
105 |
{ |
|
|
106 |
return $this->log; |
|
|
107 |
} |
|
|
108 |
|
|
|
109 |
/** |
|
|
110 |
* Run the Compiler and process all Passes. |
|
|
111 |
* |
|
|
112 |
* @param ContainerBuilder $container |
|
|
113 |
* |
|
|
114 |
* @api |
|
|
115 |
*/ |
|
|
116 |
public function compile(ContainerBuilder $container) |
|
|
117 |
{ |
|
|
118 |
foreach ($this->passConfig->getPasses() as $pass) { |
|
|
119 |
$pass->process($container); |
|
|
120 |
} |
|
|
121 |
} |
|
|
122 |
} |