@@ -80,6 +80,7 @@ class PhpDumper extends Dumper
80
80
private $ addGetService = false ;
81
81
private $ locatedIds = array ();
82
82
private $ serviceLocatorTag ;
83
+ private $ exportedVariables = array ();
83
84
84
85
/**
85
86
* @var ProxyDumper
@@ -125,6 +126,7 @@ public function dump(array $options = array())
125
126
$ this ->locatedIds = array ();
126
127
$ this ->targetDirRegex = null ;
127
128
$ this ->inlinedRequires = array ();
129
+ $ this ->exportedVariables = array ();
128
130
$ options = array_merge (array (
129
131
'class ' => 'ProjectServiceContainer ' ,
130
132
'base_class ' => 'Container ' ,
@@ -304,6 +306,7 @@ public function dump(array $options = array())
304
306
$ this ->inlinedRequires = array ();
305
307
$ this ->circularReferences = array ();
306
308
$ this ->locatedIds = array ();
309
+ $ this ->exportedVariables = array ();
307
310
308
311
$ unusedEnvs = array ();
309
312
foreach ($ this ->container ->getEnvCounters () as $ env => $ use ) {
@@ -1768,6 +1771,10 @@ private function export($value)
1768
1771
1769
1772
private function doExport ($ value , $ resolveEnv = false )
1770
1773
{
1774
+ $ shouldCacheValue = $ resolveEnv && \is_string ($ value );
1775
+ if ($ shouldCacheValue && isset ($ this ->exportedVariables [$ value ])) {
1776
+ return $ this ->exportedVariables [$ value ];
1777
+ }
1771
1778
if (\is_string ($ value ) && false !== strpos ($ value , "\n" )) {
1772
1779
$ cleanParts = explode ("\n" , $ value );
1773
1780
$ cleanParts = array_map (function ($ part ) { return var_export ($ part , true ); }, $ cleanParts );
@@ -1789,6 +1796,10 @@ private function doExport($value, $resolveEnv = false)
1789
1796
}
1790
1797
}
1791
1798
1799
+ if ($ shouldCacheValue ) {
1800
+ $ this ->exportedVariables [$ value ] = $ export ;
1801
+ }
1802
+
1792
1803
return $ export ;
1793
1804
}
1794
1805
}
0 commit comments