Skip to content

Commit

Permalink
Fixed typo's, replaced directory separators with slasges, changed com…
Browse files Browse the repository at this point in the history
…menting style
  • Loading branch information
matthiasnoback authored and weaverryan committed Jul 14, 2012
1 parent 7d04efa commit 43fc4e1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
36 changes: 19 additions & 17 deletions components/config/caching.rst
Expand Up @@ -5,7 +5,7 @@ Caching based on resources
==========================

When all configuration resources are loaded, you may want to process the configuration values and
combine them all in one file. This file acts like a cache. It’s contents don’t have to be
combine them all in one file. This file acts like a cache. Its contents don’t have to be
regenerated every time the application runs – only when the configuration resources are modified.

For example, the Symfony Routing component allows you to load all routes, and then dump a URL
Expand All @@ -16,39 +16,41 @@ invalidated and regenerated. This can be accomplished by making use of the

The example below shows you how to collect resources, then generate some code based on the
resources that were loaded, and write this code to the cache. The cache also receives the
collection of resources that were used for generating the code. By looking at the last modified
timestamp of these resources, the cache can tell if it is still fresh or that it’s contents should
collection of resources that were used for generating the code. By looking at the "last modified"
timestamp of these resources, the cache can tell if it is still fresh or that its contents should
be regenerated.

.. code-block:: php
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Resource\FileResource;
// $yamlUserFiles is filled before with an array of 'users.yml' file paths
$resources = array();
foreach ($yamlUserFiles as $yamlUserFile) {
$resources[] = new FileResource($yamlUserFile);
}
$cachePath = __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'appUserMatcher.php';
$cachePath = __DIR__.'/cache/appUserMatcher.php';
$userMatcherCache = new ConfigCache($cachePath, true);
// the second constructor argument indicates whether or not we are in debug mode
if (!$userMatcherCache->isFresh()) {
foreach ($resources as $resource) {
$delegatingLoader->load($resource->getResource());
// fill this with an array of 'users.yml' file paths
$yamlUserFiles = ...;
$resources = array();
foreach ($yamlUserFiles as $yamlUserFile) {
$delegatingLoader->load($yamlUserFile);
$resources[] = new FileResource($yamlUserFile);
}
// The code for the UserMatcher is generated elsewhere
// $code = ...;
$code = ...;
$userMatcherCache->write($code, $resources);
}
// you may want to require the cached code:
require $cachePath;
A ``.meta`` file is created in the same directory as the cache file itself. This ``.meta`` file
contains the serialized resources, for later reference.
In debug mode, a ``.meta`` file will be created in the same directory as the cache file itself.
This ``.meta`` file contains the serialized resources, whose timestamps are used to determine if
the cache is still fresh. When not in debug mode, the cache is considered to be "fresh" as soon
as it exists, and therefore no ``.meta`` file will be generated.
13 changes: 5 additions & 8 deletions components/config/definition.rst
Expand Up @@ -60,7 +60,7 @@ from a custom ``Configuration`` class which implements the
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('database');
// add node definitions to the root of the tree
// ... add node definitions to the root of the tree
return $treeBuilder;
}
Expand Down Expand Up @@ -244,6 +244,7 @@ A validation rule always has an "if" part. You can specify this part in the foll
- ``ifArray()``
- ``ifInArray()``
- ``ifNotInArray()``
- ``always()``

A validation rule also requires a "then" part:

Expand All @@ -252,12 +253,8 @@ A validation rule also requires a "then" part:
- ``thenInvalid()``
- ``thenUnset()``

The only exception is of course:

- ``always()``

Usually, “then” is a closure. It’s return value will be used as a new value for the node, instead
of the node’s original value.
Usually, "then" is a closure. Its return value will be used as a new value for the node, instead
of the node's original value.

Processing configuration values
-------------------------------
Expand All @@ -279,6 +276,6 @@ an exception will be thrown. Otherwise the result is a clean array of configurat
$configs = array($config1, $config2);
$processor = new Processor;
$processor = new Processor();
$configuration = new DatabaseConfiguration;
$processedConfiguration = $processor->processConfiguration($configuration, $configs);
8 changes: 4 additions & 4 deletions components/config/resources.rst
Expand Up @@ -14,7 +14,7 @@ can be done with the :class:`Symfony\\Component\\Config\\FileLocator`:
use Symfony\Component\Config\FileLocator;
$configDirectories = array(__DIR__ . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'config');
$configDirectories = array(__DIR__.'/app/config');
$locator = new FileLocator($configDirectories);
$yamlUserFiles = $locator->locate('users.yml', null, false);
Expand Down Expand Up @@ -44,7 +44,7 @@ importing other resources.
{
$configValues = Yaml::parse($resource);
// handle the config values
// ... handle the config values
// maybe import some other resource:
Expand All @@ -60,7 +60,7 @@ importing other resources.
Finding the right loader
------------------------

The :class:`Symfony\\Component\\Config\\Loader\\LoaderResolver` receives as it’s first constructor
The :class:`Symfony\\Component\\Config\\Loader\\LoaderResolver` receives as its first constructor
argument a collection of loaders. When a resource (for instance an XML file) should be loaded,
it loops through this collection of loaders and returns the loader which supports this
particular resource type.
Expand All @@ -77,7 +77,7 @@ In case the resolver has found a suitable loader, this loader will be asked to l
$loaderResolver = new LoaderResolver(array(new YamlUserLoader));
$delegatingLoader = new DelegatingLoader($loaderResolver);
$delegatingLoader->load(__DIR__ . DIRECTORY_SEPARATOR . '/users.yml');
$delegatingLoader->load(__DIR__.'/users.yml');
/*
The YamlUserLoader will be used to load this resource,
since it supports files with a "yml" extension
Expand Down

0 comments on commit 43fc4e1

Please sign in to comment.