Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f1ce34

Browse files
[HttpKernel] Fix mem usage when stripping the prod container
1 parent 6d5dbf7 commit 5f1ce34

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class PhpDumper extends Dumper
5353
private $reservedVariables = array('instance', 'class');
5454
private $targetDirRegex;
5555
private $targetDirMaxMatches;
56+
private $docStar;
5657

5758
/**
5859
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
@@ -97,7 +98,9 @@ public function dump(array $options = array())
9798
$options = array_merge(array(
9899
'class' => 'ProjectServiceContainer',
99100
'base_class' => 'Container',
101+
'debug' => true,
100102
), $options);
103+
$this->docStar = $options['debug'] ? '*' : '';
101104

102105
if (!empty($options['file']) && is_dir($dir = dirname($options['file']))) {
103106
// Build a regexp where the first root dirs are mandatory,
@@ -223,6 +226,9 @@ private function addProxyClasses()
223226
foreach ($definitions as $definition) {
224227
$code .= "\n".$this->getProxyDumper()->getProxyCode($definition);
225228
}
229+
if ('' === $this->docStar) {
230+
$code = str_replace('/**', '/*', $code);
231+
}
226232

227233
return $code;
228234
}
@@ -589,7 +595,7 @@ private function addService($id, $definition)
589595
$visibility = $isProxyCandidate ? 'public' : 'protected';
590596
$code = <<<EOF
591597
592-
/**
598+
/*{$this->docStar}
593599
* Gets the '$id' service.$doc
594600
*$lazyInitializationDoc
595601
* $return
@@ -699,7 +705,7 @@ private function addServiceSynchronizer($id, Definition $definition)
699705

700706
return <<<EOF
701707
702-
/**
708+
/*{$this->docStar}
703709
* Updates the '$id' service.
704710
*/
705711
protected function synchronize{$this->camelize($id)}Service()
@@ -760,7 +766,7 @@ private function startClass($class, $baseClass)
760766
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
761767
$bagClass
762768
763-
/**
769+
/*{$this->docStar}
764770
* $class.
765771
*
766772
* This class has been auto-generated
@@ -786,7 +792,7 @@ private function addConstructor()
786792

787793
$code = <<<EOF
788794
789-
/**
795+
/*{$this->docStar}
790796
* Constructor.
791797
*/
792798
public function __construct()
@@ -823,7 +829,7 @@ private function addFrozenConstructor()
823829

824830
$code = <<<EOF
825831
826-
/**
832+
/*{$this->docStar}
827833
* Constructor.
828834
*/
829835
public function __construct()
@@ -970,11 +976,14 @@ public function getParameterBag()
970976
return $this->parameterBag;
971977
}
972978
EOF;
979+
if ('' === $this->docStar) {
980+
$code = str_replace('/**', '/*', $code);
981+
}
973982
}
974983

975984
$code .= <<<EOF
976985
977-
/**
986+
/*{$this->docStar}
978987
* Gets the default parameters.
979988
*
980989
* @return array An array of the default parameters

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,7 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container
650650
$dumper->setProxyDumper(new ProxyDumper(md5((string) $cache)));
651651
}
652652

653-
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => (string) $cache));
654-
if (!$this->debug) {
655-
$content = static::stripComments($content);
656-
}
653+
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => (string) $cache, 'debug' => $this->debug));
657654

658655
$cache->write($content, $container->getResources());
659656
}

0 commit comments

Comments
 (0)