@@ -160,11 +160,13 @@ it::
160
160
}
161
161
162
162
You will now get the speed of the PHP configured container with the ease of using
163
- configuration files. In the above example you will need to delete the cached
164
- container file whenever you make any changes. Adding a check for a variable that
165
- determines if you are in debug mode allows you to keep the speed of the cached
166
- container in production but getting an up to date configuration whilst developing
167
- your application::
163
+ configuration files. Additionally dumping the container in this way further optimizes
164
+ how the services are created by the container.
165
+
166
+ In the above example you will need to delete the cached container file whenever
167
+ you make any changes. Adding a check for a variable that determines if you are
168
+ in debug mode allows you to keep the speed of the cached container in production
169
+ but getting an up to date configuration whilst developing your application::
168
170
169
171
// ...
170
172
@@ -206,24 +208,24 @@ and use them as metadata for the cache::
206
208
$file = __DIR__ .'/cache/container.php';
207
209
$containerConfigCache = new ConfigCache($file, $isDebug);
208
210
209
- if ($cache->isFresh()) {
210
- require_once $file;
211
- $container = new MyCachedContainer();
212
- } else {
213
- $container = new ContainerBuilder();
211
+ if (!$cache->isFresh()) {
212
+ $containerBuilder = new ContainerBuilder();
214
213
//--
215
214
$container->compile();
216
215
217
- $dumper = new PhpDumper($container );
216
+ $dumper = new PhpDumper($containerBuilder );
218
217
$containerConfigCache->write(
219
218
$dumper->dump(array('class' => 'MyCachedContainer')),
220
- $container ->getResources()
219
+ $containerBuilder ->getResources()
221
220
);
222
221
}
223
222
224
- Now the cache is used regardless of whether debug mode is on or not. The difference
225
- is that the ``ConfigCache `` is set to debug mode with its second constructor
226
- argument. When the cache is not in debug mode the cached container will always
227
- be used if it exists. In debug mode, an additional metadata file is written with
228
- the timestamps of all the resource files. These are then checked to see if the files
229
- have changed, if they have the cache will be considered stale.
223
+ require_once $file;
224
+ $container = new MyCachedContainer();
225
+
226
+ Now the cached dumped container is used regardless of whether debug mode is on or not.
227
+ The difference is that the ``ConfigCache `` is set to debug mode with its second
228
+ constructor argument. When the cache is not in debug mode the cached container
229
+ will always be used if it exists. In debug mode, an additional metadata file
230
+ is written with the timestamps of all the resource files. These are then checked
231
+ to see if the files have changed, if they have the cache will be considered stale.
0 commit comments