[DependencyInjection] Optimize exporting variables
This commit is contained in:
parent
261c0dea91
commit
768de2f7d9
@ -80,6 +80,7 @@ class PhpDumper extends Dumper
|
|||||||
private $addGetService = false;
|
private $addGetService = false;
|
||||||
private $locatedIds = array();
|
private $locatedIds = array();
|
||||||
private $serviceLocatorTag;
|
private $serviceLocatorTag;
|
||||||
|
private $exportedVariables = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ProxyDumper
|
* @var ProxyDumper
|
||||||
@ -125,6 +126,7 @@ class PhpDumper extends Dumper
|
|||||||
$this->locatedIds = array();
|
$this->locatedIds = array();
|
||||||
$this->targetDirRegex = null;
|
$this->targetDirRegex = null;
|
||||||
$this->inlinedRequires = array();
|
$this->inlinedRequires = array();
|
||||||
|
$this->exportedVariables = array();
|
||||||
$options = array_merge(array(
|
$options = array_merge(array(
|
||||||
'class' => 'ProjectServiceContainer',
|
'class' => 'ProjectServiceContainer',
|
||||||
'base_class' => 'Container',
|
'base_class' => 'Container',
|
||||||
@ -304,6 +306,7 @@ EOF;
|
|||||||
$this->inlinedRequires = array();
|
$this->inlinedRequires = array();
|
||||||
$this->circularReferences = array();
|
$this->circularReferences = array();
|
||||||
$this->locatedIds = array();
|
$this->locatedIds = array();
|
||||||
|
$this->exportedVariables = array();
|
||||||
|
|
||||||
$unusedEnvs = array();
|
$unusedEnvs = array();
|
||||||
foreach ($this->container->getEnvCounters() as $env => $use) {
|
foreach ($this->container->getEnvCounters() as $env => $use) {
|
||||||
@ -1768,6 +1771,10 @@ EOF;
|
|||||||
|
|
||||||
private function doExport($value, $resolveEnv = false)
|
private function doExport($value, $resolveEnv = false)
|
||||||
{
|
{
|
||||||
|
$shouldCacheValue = $resolveEnv && \is_string($value);
|
||||||
|
if ($shouldCacheValue && isset($this->exportedVariables[$value])) {
|
||||||
|
return $this->exportedVariables[$value];
|
||||||
|
}
|
||||||
if (\is_string($value) && false !== strpos($value, "\n")) {
|
if (\is_string($value) && false !== strpos($value, "\n")) {
|
||||||
$cleanParts = explode("\n", $value);
|
$cleanParts = explode("\n", $value);
|
||||||
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);
|
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);
|
||||||
@ -1789,6 +1796,10 @@ EOF;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($shouldCacheValue) {
|
||||||
|
$this->exportedVariables[$value] = $export;
|
||||||
|
}
|
||||||
|
|
||||||
return $export;
|
return $export;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user