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 ;
@@ -621,7 +631,7 @@ private function addService($id, $definition)
621
631
$ visibility = $ isProxyCandidate ? 'public ' : 'protected ' ;
622
632
$ code = <<<EOF
623
633
624
- /**
634
+ /* { $ this -> docStar }
625
635
* Gets the ' $ id' service. $ doc
626
636
* $ lazyInitializationDoc
627
637
* $ return
@@ -737,7 +747,7 @@ private function addServiceSynchronizer($id, Definition $definition)
737
747
738
748
return <<<EOF
739
749
740
- /**
750
+ /* { $ this -> docStar }
741
751
* Updates the ' $ id' service.
742
752
*/
743
753
protected function synchronize {$ this ->camelize ($ id )}Service()
@@ -829,7 +839,7 @@ private function startClass($class, $baseClass, $namespace)
829
839
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
830
840
$ bagClass
831
841
832
- /**
842
+ /* { $ this -> docStar }
833
843
* $ class.
834
844
*
835
845
* This class has been auto-generated
@@ -855,7 +865,7 @@ private function addConstructor()
855
865
856
866
$ code = <<<EOF
857
867
858
- /**
868
+ /* { $ this -> docStar }
859
869
* Constructor.
860
870
*/
861
871
public function __construct()
@@ -892,7 +902,7 @@ private function addFrozenConstructor()
892
902
893
903
$ code = <<<EOF
894
904
895
- /**
905
+ /* { $ this -> docStar }
896
906
* Constructor.
897
907
*/
898
908
public function __construct()
@@ -939,7 +949,7 @@ private function addFrozenCompile()
939
949
{
940
950
return <<<EOF
941
951
942
- /**
952
+ /* { $ this -> docStar }
943
953
* {@inheritdoc}
944
954
*/
945
955
public function compile()
@@ -1060,11 +1070,14 @@ public function getParameterBag()
1060
1070
}
1061
1071
1062
1072
EOF;
1073
+ if ('' === $ this ->docStar ) {
1074
+ $ code = str_replace ('/** ' , '/* ' , $ code );
1075
+ }
1063
1076
}
1064
1077
1065
1078
$ code .= <<<EOF
1066
1079
1067
- /**
1080
+ /* { $ this -> docStar }
1068
1081
* Gets the default parameters.
1069
1082
*
1070
1083
* @return array An array of the default parameters
0 commit comments