26
26
use Symfony \Component \DependencyInjection \ExpressionLanguage ;
27
27
use Symfony \Component \ExpressionLanguage \Expression ;
28
28
use Symfony \Component \ExpressionLanguage \ExpressionFunctionProviderInterface ;
29
+ use Symfony \Component \HttpKernel \Kernel ;
29
30
30
31
/**
31
32
* PhpDumper dumps a service container as a PHP class.
@@ -57,6 +58,7 @@ class PhpDumper extends Dumper
57
58
private $ expressionLanguage ;
58
59
private $ targetDirRegex ;
59
60
private $ targetDirMaxMatches ;
61
+ private $ docStar ;
60
62
61
63
/**
62
64
* @var ExpressionFunctionProviderInterface[]
@@ -108,7 +110,9 @@ public function dump(array $options = array())
108
110
'class ' => 'ProjectServiceContainer ' ,
109
111
'base_class ' => 'Container ' ,
110
112
'namespace ' => '' ,
113
+ 'debug ' => true ,
111
114
), $ options );
115
+ $ this ->docStar = $ options ['debug ' ] ? '* ' : '' ;
112
116
113
117
if (!empty ($ options ['file ' ]) && is_dir ($ dir = dirname ($ options ['file ' ]))) {
114
118
// Build a regexp where the first root dirs are mandatory,
@@ -233,9 +237,15 @@ private function addProxyClasses()
233
237
array ($ this ->getProxyDumper (), 'isProxyCandidate ' )
234
238
);
235
239
$ code = '' ;
240
+ $ strip = '' === $ this ->docStar && method_exists ('Symfony\Component\HttpKernel\Kernel ' , 'stripComments ' );
236
241
237
242
foreach ($ definitions as $ definition ) {
238
- $ code .= "\n" .$ this ->getProxyDumper ()->getProxyCode ($ definition );
243
+ $ proxyCode = "\n" .$ this ->getProxyDumper ()->getProxyCode ($ definition );
244
+ if ($ strip ) {
245
+ $ proxyCode = "<?php \n" .$ proxyCode ;
246
+ $ proxyCode = substr (Kernel::stripComments ($ proxyCode ), 5 );
247
+ }
248
+ $ code .= $ proxyCode ;
239
249
}
240
250
241
251
return $ code ;
@@ -637,7 +647,7 @@ private function addService($id, $definition)
637
647
$ visibility = $ isProxyCandidate ? 'public ' : 'protected ' ;
638
648
$ code = <<<EOF
639
649
640
- /**
650
+ /* { $ this -> docStar }
641
651
* Gets the ' $ id' service. $ doc
642
652
* $ lazyInitializationDoc
643
653
* $ return
@@ -757,7 +767,7 @@ private function addServiceSynchronizer($id, Definition $definition)
757
767
758
768
return <<<EOF
759
769
760
- /**
770
+ /* { $ this -> docStar }
761
771
* Updates the ' $ id' service.
762
772
*/
763
773
protected function synchronize {$ this ->camelize ($ id )}Service()
@@ -849,7 +859,7 @@ private function startClass($class, $baseClass, $namespace)
849
859
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
850
860
$ bagClass
851
861
852
- /**
862
+ /* { $ this -> docStar }
853
863
* $ class.
854
864
*
855
865
* This class has been auto-generated
@@ -875,7 +885,7 @@ private function addConstructor()
875
885
876
886
$ code = <<<EOF
877
887
878
- /**
888
+ /* { $ this -> docStar }
879
889
* Constructor.
880
890
*/
881
891
public function __construct()
@@ -912,7 +922,7 @@ private function addFrozenConstructor()
912
922
913
923
$ code = <<<EOF
914
924
915
- /**
925
+ /* { $ this -> docStar }
916
926
* Constructor.
917
927
*/
918
928
public function __construct()
@@ -959,7 +969,7 @@ private function addFrozenCompile()
959
969
{
960
970
return <<<EOF
961
971
962
- /**
972
+ /* { $ this -> docStar }
963
973
* {@inheritdoc}
964
974
*/
965
975
public function compile()
@@ -1080,11 +1090,14 @@ public function getParameterBag()
1080
1090
}
1081
1091
1082
1092
EOF;
1093
+ if ('' === $ this ->docStar ) {
1094
+ $ code = str_replace ('/** ' , '/* ' , $ code );
1095
+ }
1083
1096
}
1084
1097
1085
1098
$ code .= <<<EOF
1086
1099
1087
- /**
1100
+ /* { $ this -> docStar }
1088
1101
* Gets the default parameters.
1089
1102
*
1090
1103
* @return array An array of the default parameters
0 commit comments