2323use Symfony \Component \DependencyInjection \Exception \ServiceCircularReferenceException ;
2424use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \DumperInterface as ProxyDumper ;
2525use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \NullDumper ;
26+ use Symfony \Component \HttpKernel \Kernel ;
2627
2728/**
2829 * PhpDumper dumps a service container as a PHP class.
@@ -53,6 +54,7 @@ class PhpDumper extends Dumper
5354 private $ reservedVariables = array ('instance ' , 'class ' );
5455 private $ targetDirRegex ;
5556 private $ targetDirMaxMatches ;
57+ private $ docStar ;
5658
5759 /**
5860 * @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
@@ -97,7 +99,9 @@ public function dump(array $options = array())
9799 $ options = array_merge (array (
98100 'class ' => 'ProjectServiceContainer ' ,
99101 'base_class ' => 'Container ' ,
102+ 'debug ' => true ,
100103 ), $ options );
104+ $ this ->docStar = $ options ['debug ' ] ? '* ' : '' ;
101105
102106 if (!empty ($ options ['file ' ]) && is_dir ($ dir = dirname ($ options ['file ' ]))) {
103107 // Build a regexp where the first root dirs are mandatory,
@@ -219,9 +223,15 @@ private function addProxyClasses()
219223 array ($ this ->getProxyDumper (), 'isProxyCandidate ' )
220224 );
221225 $ code = '' ;
226+ $ strip = '' === $ this ->docStar && method_exists ('Symfony\Component\HttpKernel\Kernel ' , 'stripComments ' );
222227
223228 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 ;
225235 }
226236
227237 return $ code ;
@@ -589,7 +599,7 @@ private function addService($id, $definition)
589599 $ visibility = $ isProxyCandidate ? 'public ' : 'protected ' ;
590600 $ code = <<<EOF
591601
592- /**
602+ /* { $ this -> docStar }
593603 * Gets the ' $ id' service. $ doc
594604 * $ lazyInitializationDoc
595605 * $ return
@@ -699,7 +709,7 @@ private function addServiceSynchronizer($id, Definition $definition)
699709
700710 return <<<EOF
701711
702- /**
712+ /* { $ this -> docStar }
703713 * Updates the ' $ id' service.
704714 */
705715 protected function synchronize {$ this ->camelize ($ id )}Service()
@@ -760,7 +770,7 @@ private function startClass($class, $baseClass)
760770use Symfony\Component\DependencyInjection\Exception\RuntimeException;
761771$ bagClass
762772
763- /**
773+ /* { $ this -> docStar }
764774 * $ class.
765775 *
766776 * This class has been auto-generated
@@ -786,7 +796,7 @@ private function addConstructor()
786796
787797 $ code = <<<EOF
788798
789- /**
799+ /* { $ this -> docStar }
790800 * Constructor.
791801 */
792802 public function __construct()
@@ -823,7 +833,7 @@ private function addFrozenConstructor()
823833
824834 $ code = <<<EOF
825835
826- /**
836+ /* { $ this -> docStar }
827837 * Constructor.
828838 */
829839 public function __construct()
@@ -970,11 +980,14 @@ public function getParameterBag()
970980 return $this->parameterBag;
971981 }
972982EOF;
983+ if ('' === $ this ->docStar ) {
984+ $ code = str_replace ('/** ' , '/* ' , $ code );
985+ }
973986 }
974987
975988 $ code .= <<<EOF
976989
977- /**
990+ /* { $ this -> docStar }
978991 * Gets the default parameters.
979992 *
980993 * @return array An array of the default parameters
0 commit comments