23
23
use Symfony \Component \DependencyInjection \Exception \ServiceCircularReferenceException ;
24
24
use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \DumperInterface as ProxyDumper ;
25
25
use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \NullDumper ;
26
+ use Symfony \Component \HttpKernel \Kernel ;
26
27
27
28
/**
28
29
* PhpDumper dumps a service container as a PHP class.
@@ -53,6 +54,7 @@ class PhpDumper extends Dumper
53
54
private $ reservedVariables = array ('instance ' , 'class ' );
54
55
private $ targetDirRegex ;
55
56
private $ targetDirMaxMatches ;
57
+ private $ docStar ;
56
58
57
59
/**
58
60
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
@@ -97,7 +99,9 @@ public function dump(array $options = array())
97
99
$ options = array_merge (array (
98
100
'class ' => 'ProjectServiceContainer ' ,
99
101
'base_class ' => 'Container ' ,
102
+ 'debug ' => true ,
100
103
), $ options );
104
+ $ this ->docStar = $ options ['debug ' ] ? '* ' : '' ;
101
105
102
106
if (!empty ($ options ['file ' ]) && is_dir ($ dir = dirname ($ options ['file ' ]))) {
103
107
// Build a regexp where the first root dirs are mandatory,
@@ -219,9 +223,15 @@ private function addProxyClasses()
219
223
array ($ this ->getProxyDumper (), 'isProxyCandidate ' )
220
224
);
221
225
$ code = '' ;
226
+ $ strip = '' === $ this ->docStar && method_exists ('Symfony\Component\HttpKernel\Kernel ' , 'stripComments ' );
222
227
223
228
foreach ($ definitions as $ definition ) {
224
- $ code .= "\n" .$ this ->getProxyDumper ()->getProxyCode ($ definition );
229
+ $ proxyCode = "\n" .$ this ->getProxyDumper ()->getProxyCode ($ definition );
230
+ if ($ strip ) {
231
+ $ proxyCode = "<?php \n" .$ proxyCode ;
232
+ $ proxyCode = substr (Kernel::stripComments ($ proxyCode ), 5 );
233
+ }
234
+ $ code .= $ proxyCode ;
225
235
}
226
236
227
237
return $ code ;
@@ -589,7 +599,7 @@ private function addService($id, $definition)
589
599
$ visibility = $ isProxyCandidate ? 'public ' : 'protected ' ;
590
600
$ code = <<<EOF
591
601
592
- /**
602
+ /* { $ this -> docStar }
593
603
* Gets the ' $ id' service. $ doc
594
604
* $ lazyInitializationDoc
595
605
* $ return
@@ -699,7 +709,7 @@ private function addServiceSynchronizer($id, Definition $definition)
699
709
700
710
return <<<EOF
701
711
702
- /**
712
+ /* { $ this -> docStar }
703
713
* Updates the ' $ id' service.
704
714
*/
705
715
protected function synchronize {$ this ->camelize ($ id )}Service()
@@ -760,7 +770,7 @@ private function startClass($class, $baseClass)
760
770
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
761
771
$ bagClass
762
772
763
- /**
773
+ /* { $ this -> docStar }
764
774
* $ class.
765
775
*
766
776
* This class has been auto-generated
@@ -786,7 +796,7 @@ private function addConstructor()
786
796
787
797
$ code = <<<EOF
788
798
789
- /**
799
+ /* { $ this -> docStar }
790
800
* Constructor.
791
801
*/
792
802
public function __construct()
@@ -823,7 +833,7 @@ private function addFrozenConstructor()
823
833
824
834
$ code = <<<EOF
825
835
826
- /**
836
+ /* { $ this -> docStar }
827
837
* Constructor.
828
838
*/
829
839
public function __construct()
@@ -970,11 +980,14 @@ public function getParameterBag()
970
980
return $this->parameterBag;
971
981
}
972
982
EOF;
983
+ if ('' === $ this ->docStar ) {
984
+ $ code = str_replace ('/** ' , '/* ' , $ code );
985
+ }
973
986
}
974
987
975
988
$ code .= <<<EOF
976
989
977
- /**
990
+ /* { $ this -> docStar }
978
991
* Gets the default parameters.
979
992
*
980
993
* @return array An array of the default parameters
0 commit comments