[HttpKernel] Fix mem usage when stripping the prod container
This commit is contained in:
parent
6d5dbf7a75
commit
4fa58440be
@ -23,6 +23,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
|||||||
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
||||||
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface as ProxyDumper;
|
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface as ProxyDumper;
|
||||||
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\NullDumper;
|
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\NullDumper;
|
||||||
|
use Symfony\Component\HttpKernel\Kernel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PhpDumper dumps a service container as a PHP class.
|
* PhpDumper dumps a service container as a PHP class.
|
||||||
@ -53,6 +54,7 @@ class PhpDumper extends Dumper
|
|||||||
private $reservedVariables = array('instance', 'class');
|
private $reservedVariables = array('instance', 'class');
|
||||||
private $targetDirRegex;
|
private $targetDirRegex;
|
||||||
private $targetDirMaxMatches;
|
private $targetDirMaxMatches;
|
||||||
|
private $docStar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
|
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
|
||||||
@ -97,7 +99,9 @@ class PhpDumper extends Dumper
|
|||||||
$options = array_merge(array(
|
$options = array_merge(array(
|
||||||
'class' => 'ProjectServiceContainer',
|
'class' => 'ProjectServiceContainer',
|
||||||
'base_class' => 'Container',
|
'base_class' => 'Container',
|
||||||
|
'debug' => true,
|
||||||
), $options);
|
), $options);
|
||||||
|
$this->docStar = $options['debug'] ? '*' : '';
|
||||||
|
|
||||||
if (!empty($options['file']) && is_dir($dir = dirname($options['file']))) {
|
if (!empty($options['file']) && is_dir($dir = dirname($options['file']))) {
|
||||||
// Build a regexp where the first root dirs are mandatory,
|
// Build a regexp where the first root dirs are mandatory,
|
||||||
@ -219,9 +223,15 @@ class PhpDumper extends Dumper
|
|||||||
array($this->getProxyDumper(), 'isProxyCandidate')
|
array($this->getProxyDumper(), 'isProxyCandidate')
|
||||||
);
|
);
|
||||||
$code = '';
|
$code = '';
|
||||||
|
$strip = '' === $this->docStar && method_exists('Symfony\Component\HttpKernel\Kernel', 'stripComments');
|
||||||
|
|
||||||
foreach ($definitions as $definition) {
|
foreach ($definitions as $definition) {
|
||||||
$code .= "\n".$this->getProxyDumper()->getProxyCode($definition);
|
$proxyCode = "\n".$this->getProxyDumper()->getProxyCode($definition);
|
||||||
|
if ($strip) {
|
||||||
|
$proxyCode = "<?php\n".$proxyCode;
|
||||||
|
$proxyCode = substr(Kernel::stripComments($proxyCode), 5);
|
||||||
|
}
|
||||||
|
$code .= $proxyCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $code;
|
return $code;
|
||||||
@ -589,7 +599,7 @@ EOF;
|
|||||||
$visibility = $isProxyCandidate ? 'public' : 'protected';
|
$visibility = $isProxyCandidate ? 'public' : 'protected';
|
||||||
$code = <<<EOF
|
$code = <<<EOF
|
||||||
|
|
||||||
/**
|
/*{$this->docStar}
|
||||||
* Gets the '$id' service.$doc
|
* Gets the '$id' service.$doc
|
||||||
*$lazyInitializationDoc
|
*$lazyInitializationDoc
|
||||||
* $return
|
* $return
|
||||||
@ -699,7 +709,7 @@ EOF;
|
|||||||
|
|
||||||
return <<<EOF
|
return <<<EOF
|
||||||
|
|
||||||
/**
|
/*{$this->docStar}
|
||||||
* Updates the '$id' service.
|
* Updates the '$id' service.
|
||||||
*/
|
*/
|
||||||
protected function synchronize{$this->camelize($id)}Service()
|
protected function synchronize{$this->camelize($id)}Service()
|
||||||
@ -760,7 +770,7 @@ use Symfony\Component\DependencyInjection\Exception\LogicException;
|
|||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
$bagClass
|
$bagClass
|
||||||
|
|
||||||
/**
|
/*{$this->docStar}
|
||||||
* $class.
|
* $class.
|
||||||
*
|
*
|
||||||
* This class has been auto-generated
|
* This class has been auto-generated
|
||||||
@ -786,7 +796,7 @@ EOF;
|
|||||||
|
|
||||||
$code = <<<EOF
|
$code = <<<EOF
|
||||||
|
|
||||||
/**
|
/*{$this->docStar}
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
@ -823,7 +833,7 @@ EOF;
|
|||||||
|
|
||||||
$code = <<<EOF
|
$code = <<<EOF
|
||||||
|
|
||||||
/**
|
/*{$this->docStar}
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
@ -970,11 +980,14 @@ EOF;
|
|||||||
return $this->parameterBag;
|
return $this->parameterBag;
|
||||||
}
|
}
|
||||||
EOF;
|
EOF;
|
||||||
|
if ('' === $this->docStar) {
|
||||||
|
$code = str_replace('/**', '/*', $code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$code .= <<<EOF
|
$code .= <<<EOF
|
||||||
|
|
||||||
/**
|
/*{$this->docStar}
|
||||||
* Gets the default parameters.
|
* Gets the default parameters.
|
||||||
*
|
*
|
||||||
* @return array An array of the default parameters
|
* @return array An array of the default parameters
|
||||||
|
@ -650,10 +650,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
|||||||
$dumper->setProxyDumper(new ProxyDumper(md5((string) $cache)));
|
$dumper->setProxyDumper(new ProxyDumper(md5((string) $cache)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => (string) $cache));
|
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => (string) $cache, 'debug' => $this->debug));
|
||||||
if (!$this->debug) {
|
|
||||||
$content = static::stripComments($content);
|
|
||||||
}
|
|
||||||
|
|
||||||
$cache->write($content, $container->getResources());
|
$cache->write($content, $container->getResources());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user