25
25
use Symfony \Component \DependencyInjection \Parameter ;
26
26
use Symfony \Component \DependencyInjection \Exception \EnvParameterException ;
27
27
use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
28
+ use Symfony \Component \DependencyInjection \Exception \LogicException ;
28
29
use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
29
30
use Symfony \Component \DependencyInjection \Exception \ServiceCircularReferenceException ;
30
31
use Symfony \Component \DependencyInjection \LazyProxy \ProxyHelper ;
@@ -80,7 +81,7 @@ class PhpDumper extends Dumper
80
81
public function __construct (ContainerBuilder $ container )
81
82
{
82
83
if (!$ container ->isCompiled ()) {
83
- @ trigger_error ( ' Dumping an uncompiled ContainerBuilder is deprecated since version 3.3 and will not be supported anymore in 4.0. Compile the container beforehand. ' , E_USER_DEPRECATED );
84
+ throw new LogicException ( ' Cannot dump an uncompiled container. ' );
84
85
}
85
86
86
87
parent ::__construct ($ container );
@@ -154,17 +155,11 @@ public function dump(array $options = array())
154
155
}
155
156
}
156
157
157
- $ code = $ this ->startClass ($ options ['class ' ], $ options ['base_class ' ], $ options ['namespace ' ]);
158
-
159
- if ($ this ->container ->isCompiled ()) {
160
- $ code .= $ this ->addFrozenConstructor ();
161
- $ code .= $ this ->addFrozenCompile ();
162
- $ code .= $ this ->addFrozenIsCompiled ();
163
- } else {
164
- $ code .= $ this ->addConstructor ();
165
- }
166
-
167
- $ code .=
158
+ $ code =
159
+ $ this ->startClass ($ options ['class ' ], $ options ['base_class ' ], $ options ['namespace ' ]).
160
+ $ this ->addConstructor ().
161
+ $ this ->addCompile ().
162
+ $ this ->addIsCompiled ().
168
163
$ this ->addServices ().
169
164
$ this ->addDefaultParametersMethod ().
170
165
$ this ->endClass ().
@@ -783,7 +778,6 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
783
778
*/
784
779
private function startClass ($ class , $ baseClass , $ namespace )
785
780
{
786
- $ bagClass = $ this ->container ->isCompiled () ? 'use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; ' : 'use Symfony\Component\DependencyInjection\ParameterBag \\ParameterBag; ' ;
787
781
$ namespaceLine = $ namespace ? "\nnamespace $ namespace; \n" : '' ;
788
782
789
783
return <<<EOF
@@ -795,7 +789,7 @@ private function startClass($class, $baseClass, $namespace)
795
789
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
796
790
use Symfony\Component\DependencyInjection\Exception\LogicException;
797
791
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
798
- $ bagClass
792
+ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
799
793
800
794
/* {$ this ->docStar }
801
795
* $ class.
@@ -813,46 +807,12 @@ class $class extends $baseClass
813
807
EOF ;
814
808
}
815
809
816
- /**
817
- * Adds the constructor.
818
- *
819
- * @return string
820
- */
821
- private function addConstructor ()
822
- {
823
- $ targetDirs = $ this ->exportTargetDirs ();
824
- $ arguments = $ this ->container ->getParameterBag ()->all () ? 'new ParameterBag($this->getDefaultParameters()) ' : null ;
825
-
826
- $ code = <<<EOF
827
-
828
- /* {$ this ->docStar }
829
- * Constructor.
830
- */
831
- public function __construct()
832
- { {$ targetDirs }
833
- parent::__construct( $ arguments);
834
-
835
- EOF ;
836
-
837
- $ code .= $ this ->addNormalizedIds ();
838
- $ code .= $ this ->addMethodMap ();
839
- $ code .= $ this ->addPrivateServices ();
840
- $ code .= $ this ->addAliases ();
841
-
842
- $ code .= <<<'EOF'
843
- }
844
-
845
- EOF;
846
-
847
- return $ code ;
848
- }
849
-
850
810
/**
851
811
* Adds the constructor for a compiled container.
852
812
*
853
813
* @return string
854
814
*/
855
- private function addFrozenConstructor ()
815
+ private function addConstructor ()
856
816
{
857
817
$ targetDirs = $ this ->exportTargetDirs ();
858
818
@@ -888,7 +848,7 @@ public function __construct()
888
848
*
889
849
* @return string
890
850
*/
891
- private function addFrozenCompile ()
851
+ private function addCompile ()
892
852
{
893
853
return <<<EOF
894
854
@@ -908,7 +868,7 @@ public function compile()
908
868
*
909
869
* @return string
910
870
*/
911
- private function addFrozenIsCompiled ()
871
+ private function addIsCompiled ()
912
872
{
913
873
return <<<EOF
914
874
@@ -1001,7 +961,7 @@ private function addPrivateServices()
1001
961
private function addAliases ()
1002
962
{
1003
963
if (!$ aliases = $ this ->container ->getAliases ()) {
1004
- return $ this -> container -> isCompiled () ? "\n \$this->aliases = array(); \n" : '' ;
964
+ return "\n \$this->aliases = array(); \n" ;
1005
965
}
1006
966
1007
967
$ code = " \$this->aliases = array( \n" ;
@@ -1046,9 +1006,7 @@ private function addDefaultParametersMethod()
1046
1006
}
1047
1007
$ parameters = sprintf ("array( \n%s \n%s) " , implode ("\n" , $ php ), str_repeat (' ' , 8 ));
1048
1008
1049
- $ code = '' ;
1050
- if ($ this ->container ->isCompiled ()) {
1051
- $ code .= <<<'EOF'
1009
+ $ code = <<<'EOF'
1052
1010
1053
1011
/**
1054
1012
* {@inheritdoc}
@@ -1102,13 +1060,13 @@ public function getParameterBag()
1102
1060
}
1103
1061
1104
1062
EOF;
1105
- if ('' === $ this ->docStar ) {
1106
- $ code = str_replace ('/** ' , '/* ' , $ code );
1107
- }
1063
+ if ('' === $ this ->docStar ) {
1064
+ $ code = str_replace ('/** ' , '/* ' , $ code );
1065
+ }
1108
1066
1109
- if ($ dynamicPhp ) {
1110
- $ loadedDynamicParameters = $ this ->exportParameters (array_combine (array_keys ($ dynamicPhp ), array_fill (0 , count ($ dynamicPhp ), false )), '' , 8 );
1111
- $ getDynamicParameter = <<<'EOF'
1067
+ if ($ dynamicPhp ) {
1068
+ $ loadedDynamicParameters = $ this ->exportParameters (array_combine (array_keys ($ dynamicPhp ), array_fill (0 , count ($ dynamicPhp ), false )), '' , 8 );
1069
+ $ getDynamicParameter = <<<'EOF'
1112
1070
switch ($name) {
1113
1071
%s
1114
1072
default: throw new InvalidArgumentException(sprintf('The dynamic parameter "%%s" must be defined.', $name));
@@ -1117,13 +1075,13 @@ public function getParameterBag()
1117
1075
1118
1076
return $this->dynamicParameters[$name] = $value;
1119
1077
EOF;
1120
- $ getDynamicParameter = sprintf ($ getDynamicParameter , implode ("\n" , $ dynamicPhp ));
1121
- } else {
1122
- $ loadedDynamicParameters = 'array() ' ;
1123
- $ getDynamicParameter = str_repeat (' ' , 8 ).'throw new InvalidArgumentException(sprintf( \'The dynamic parameter "%s" must be defined. \', $name)); ' ;
1124
- }
1078
+ $ getDynamicParameter = sprintf ($ getDynamicParameter , implode ("\n" , $ dynamicPhp ));
1079
+ } else {
1080
+ $ loadedDynamicParameters = 'array() ' ;
1081
+ $ getDynamicParameter = str_repeat (' ' , 8 ).'throw new InvalidArgumentException(sprintf( \'The dynamic parameter "%s" must be defined. \', $name)); ' ;
1082
+ }
1125
1083
1126
- $ code .= <<<EOF
1084
+ $ code .= <<<EOF
1127
1085
1128
1086
private \$loadedDynamicParameters = {$ loadedDynamicParameters };
1129
1087
private \$dynamicParameters = array();
@@ -1142,13 +1100,6 @@ private function getDynamicParameter(\$name)
1142
1100
{$ getDynamicParameter }
1143
1101
}
1144
1102
1145
- EOF ;
1146
- } elseif ($ dynamicPhp ) {
1147
- throw new RuntimeException ('You cannot dump a not-frozen container with dynamic parameters. ' );
1148
- }
1149
-
1150
- $ code .= <<<EOF
1151
-
1152
1103
/* {$ this ->docStar }
1153
1104
* Gets the default parameters.
1154
1105
*
@@ -1595,7 +1546,7 @@ private function dumpLiteralClass($class)
1595
1546
*/
1596
1547
private function dumpParameter ($ name )
1597
1548
{
1598
- if ($ this ->container ->isCompiled () && $ this -> container -> hasParameter ($ name )) {
1549
+ if ($ this ->container ->hasParameter ($ name )) {
1599
1550
return $ this ->dumpValue ($ this ->container ->getParameter ($ name ), false );
1600
1551
}
1601
1552
0 commit comments