Skip to content

Commit 4e8160b

Browse files
Updated dumping DI container example to always use the dumped container
1 parent 879f293 commit 4e8160b

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

components/dependency_injection/compilation.rst

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,13 @@ it::
160160
}
161161

162162
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::
168170

169171
// ...
170172

@@ -206,24 +208,24 @@ and use them as metadata for the cache::
206208
$file = __DIR__ .'/cache/container.php';
207209
$containerConfigCache = new ConfigCache($file, $isDebug);
208210

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();
214213
//--
215214
$container->compile();
216215

217-
$dumper = new PhpDumper($container);
216+
$dumper = new PhpDumper($containerBuilder);
218217
$containerConfigCache->write(
219218
$dumper->dump(array('class' => 'MyCachedContainer')),
220-
$container->getResources()
219+
$containerBuilder->getResources()
221220
);
222221
}
223222

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

Comments
 (0)