@@ -72,6 +72,7 @@ class PhpDumper extends Dumper
72
72
private $ namespace ;
73
73
private $ asFiles ;
74
74
private $ hotPathTag ;
75
+ private $ inlineFactories ;
75
76
private $ inlineRequires ;
76
77
private $ inlinedRequires = [];
77
78
private $ circularReferences = [];
@@ -134,6 +135,7 @@ public function dump(array $options = [])
134
135
'as_files ' => false ,
135
136
'debug ' => true ,
136
137
'hot_path_tag ' => 'container.hot_path ' ,
138
+ 'inline_factories_parameter ' => 'container.dumper.inline_factories ' ,
137
139
'inline_class_loader_parameter ' => 'container.dumper.inline_class_loader ' ,
138
140
'service_locator_tag ' => 'container.service_locator ' ,
139
141
'build_time ' => time (),
@@ -143,6 +145,7 @@ public function dump(array $options = [])
143
145
$ this ->namespace = $ options ['namespace ' ];
144
146
$ this ->asFiles = $ options ['as_files ' ];
145
147
$ this ->hotPathTag = $ options ['hot_path_tag ' ];
148
+ $ this ->inlineFactories = $ options ['inline_factories_parameter ' ] && $ this ->container ->hasParameter ($ options ['inline_factories_parameter ' ]) && $ this ->container ->getParameter ($ options ['inline_factories_parameter ' ]);
146
149
$ this ->inlineRequires = $ options ['inline_class_loader_parameter ' ] && $ this ->container ->hasParameter ($ options ['inline_class_loader_parameter ' ]) && $ this ->container ->getParameter ($ options ['inline_class_loader_parameter ' ]);
147
150
$ this ->serviceLocatorTag = $ options ['service_locator_tag ' ];
148
151
@@ -257,14 +260,24 @@ public function dump(array $options = [])
257
260
}
258
261
$ files ['removed-ids.php ' ] = $ c .= "]; \n" ;
259
262
}
260
-
261
- foreach ($ this ->generateServiceFiles ($ services ) as $ file => $ c ) {
262
- $ files [$ file ] = $ fileStart .$ c ;
263
+ if (!$ this ->inlineFactories ) {
264
+ foreach ($ this ->generateServiceFiles ($ services ) as $ file => $ c ) {
265
+ $ files [$ file ] = $ fileStart .$ c ;
266
+ }
267
+ foreach ($ this ->generateProxyClasses () as $ file => $ c ) {
268
+ $ files [$ file ] = "<?php \n" .$ c ;
269
+ }
263
270
}
264
- foreach ($ this ->generateProxyClasses () as $ file => $ c ) {
265
- $ files [$ file ] = "<?php \n" .$ c ;
271
+
272
+ $ code .= $ this ->endClass ();
273
+
274
+ if ($ this ->inlineFactories ) {
275
+ foreach ($ this ->generateProxyClasses () as $ c ) {
276
+ $ code .= $ c ;
277
+ }
266
278
}
267
- $ files [$ options ['class ' ].'.php ' ] = $ code .$ this ->endClass ();
279
+
280
+ $ files [$ options ['class ' ].'.php ' ] = $ code ;
268
281
$ hash = ucfirst (strtr (ContainerBuilder::hash ($ files ), '._ ' , 'xx ' ));
269
282
$ code = [];
270
283
@@ -685,7 +698,7 @@ private function addService(string $id, Definition $definition): array
685
698
$ lazyInitialization = '' ;
686
699
}
687
700
688
- $ asFile = $ this ->asFiles && !$ this ->isHotPath ($ definition );
701
+ $ asFile = $ this ->asFiles && !$ this ->inlineFactories && ! $ this -> isHotPath ($ definition );
689
702
$ methodName = $ this ->generateMethodName ($ id );
690
703
if ($ asFile ) {
691
704
$ file = $ methodName .'.php ' ;
@@ -1140,7 +1153,7 @@ private function addMethodMap(): string
1140
1153
$ definitions = $ this ->container ->getDefinitions ();
1141
1154
ksort ($ definitions );
1142
1155
foreach ($ definitions as $ id => $ definition ) {
1143
- if (!$ definition ->isSynthetic () && $ definition ->isPublic () && (!$ this ->asFiles || $ this ->isHotPath ($ definition ))) {
1156
+ if (!$ definition ->isSynthetic () && $ definition ->isPublic () && (!$ this ->asFiles || $ this ->inlineFactories || $ this -> isHotPath ($ definition ))) {
1144
1157
$ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ this ->generateMethodName ($ id )).", \n" ;
1145
1158
}
1146
1159
}
@@ -1163,7 +1176,7 @@ private function addFileMap(): string
1163
1176
$ definitions = $ this ->container ->getDefinitions ();
1164
1177
ksort ($ definitions );
1165
1178
foreach ($ definitions as
9E7A
span> $ id => $ definition ) {
1166
- if (!$ definition ->isSynthetic () && $ definition ->isPublic () && !$ this ->isHotPath ($ definition )) {
1179
+ if (!$ definition ->isSynthetic () && $ definition ->isPublic () && !$ this ->inlineFactories && ! $ this -> isHotPath ($ definition )) {
1167
1180
$ code .= sprintf (" %s => '%s.php', \n" , $ this ->doExport ($ id ), $ this ->generateMethodName ($ id ));
1168
1181
}
1169
1182
}
@@ -1578,7 +1591,7 @@ private function dumpValue($value, bool $interpolate = true): string
1578
1591
continue ;
1579
1592
}
1580
1593
$ definition = $ this ->container ->findDefinition ($ id = (string ) $ v );
1581
- $ load = !($ definition ->hasErrors () && $ e = $ definition ->getErrors ()) ? $ this ->asFiles && !$ this ->isHotPath ($ definition ) : reset ($ e );
1594
+ $ load = !($ definition ->hasErrors () && $ e = $ definition ->getErrors ()) ? $ this ->asFiles && !$ this ->inlineFactories && ! $ this -> isHotPath ($ definition ) : reset ($ e );
1582
1595
$ serviceMap .= sprintf ("\n %s => [%s, %s, %s, %s], " ,
1583
1596
$ this ->export ($ k ),
1584
1597
$ this ->export ($ definition ->isShared () ? ($ definition ->isPublic () ? 'services ' : 'privates ' ) : false ),
@@ -1716,7 +1729,7 @@ private function getServiceCall(string $id, Reference $reference = null): string
1716
1729
$ code = sprintf ('$this->%s[%s] = %s ' , $ definition ->isPublic () ? 'services ' : 'privates ' , $ this ->doExport ($ id ), $ code );
1717
1730
}
1718
1731
$ code = "( $ code) " ;
1719
- } elseif ($ this ->asFiles && !$ this ->isHotPath ($ definition )) {
1732
+ } elseif ($ this ->asFiles && !$ this ->inlineFactories && ! $ this -> isHotPath ($ definition )) {
1720
1733
$ code = sprintf ("\$this->load('%s.php') " , $ this ->generateMethodName ($ id ));
1721
1734
if (!$ definition ->isShared ()) {
1722
1735
$ factory = sprintf ('$this->factories%s[%s] ' , $ definition ->isPublic () ? '' : "['service_container'] &q
F438
uot; , $ this ->doExport ($ id ));
0 commit comments