Skip to content

Commit

Permalink
moved common configuration classes to a new Config component
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 13, 2011
1 parent d01a4e3 commit 5c905be
Show file tree
Hide file tree
Showing 124 changed files with 796 additions and 1,944 deletions.
Expand Up @@ -13,8 +13,8 @@

use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\FileLocator;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;

/**
* Semantic asset configuration.
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Bundle\AsseticBundle\Routing;

use Assetic\AssetManager;
use Symfony\Component\Routing\Loader\Loader;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

Expand Down
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Bundle\AsseticBundle\Tests\Kernel;

use Symfony\Component\DependencyInjection\Loader\LoaderInterface;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

class TestKernel extends Kernel
Expand Down
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Resource\FileResource;
use Symfony\Component\Config\Resource\FileResource;

/**
* This abstract classes groups common code that Doctrine Object Manager extensions (ORM, MongoDB, CouchDB) need.
Expand Down
Expand Up @@ -14,12 +14,12 @@
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Resource\FileResource;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Bundle\DoctrineAbstractBundle\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Component\Config\FileLocator;

/**
* DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
Expand Down
Expand Up @@ -18,7 +18,7 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\FileLocator;
use Symfony\Component\Config\FileLocator;

abstract class AbstractDoctrineExtensionTest extends TestCase
{
Expand Down
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\FileLocator;
use Symfony\Component\Config\FileLocator;

class XmlDoctrineExtensionTest extends AbstractDoctrineExtensionTest
{
Expand Down
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Loader\FileLocator;
use Symfony\Component\Config\FileLocator;

class YamlDoctrineExtensionTest extends AbstractDoctrineExtensionTest
{
Expand Down
Expand Up @@ -13,12 +13,12 @@

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Resource\FileResource;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\FileLocator;
use Symfony\Bundle\DoctrineAbstractBundle\DependencyInjection\AbstractDoctrineExtension;

/**
Expand Down
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\FileLocator;
use Symfony\Component\Config\FileLocator;

class XmlMongoDBExtensionTest extends AbstractMongoDBExtensionTest
{
Expand Down
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Loader\FileLocator;
use Symfony\Component\Config\FileLocator;

class YamlMongoDBExtensionTest extends AbstractMongoDBExtensionTest
{
Expand Down
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Config\FileLocatorInterface;

/**
* Computes the association between template names and their paths on the disk.
Expand All @@ -22,18 +23,21 @@
*/
class TemplatePathsCacheWarmer extends CacheWarmer
{
protected $locator;
protected $kernel;
protected $rootDir;

/**
* Constructor.
*
* @param KernelInterface $kernel A KernelInterface instance
* @param string $rootDir The directory where global templates can be stored
* @param KernelInterface $kernel A KernelInterface instance
* @param FileLocatorInterface $locator A FileLocatorInterface instance
* @param string $rootDir The directory where global templates can be stored
*/
public function __construct(KernelInterface $kernel, $rootDir)
public function __construct(KernelInterface $kernel, FileLocatorInterface $locator, $rootDir)
{
$this->kernel = $kernel;
$this->locator = $locator;
$this->rootDir = $rootDir;
}

Expand Down Expand Up @@ -74,7 +78,7 @@ protected function computeTemplatePaths()
$controllerSegment = empty($template['controller']) ? '' : $template['controller'].'/';
$resource = '@'.$template['bundle'].'/Resources/views/'.$controllerSegment.$template['name'].'.'.$template['format'].'.'.$template['engine'];

$templates[md5(serialize($template))] = $this->kernel->locateResource($resource, $this->rootDir);
$templates[md5(serialize($template))] = $this->locator->locate($resource, $this->rootDir);
}
}
}
Expand Down
Expand Up @@ -17,10 +17,10 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Configuration\Processor;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\FileLocator;
use Symfony\Component\DependencyInjection\Resource\FileResource;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;

/**
* FrameworkExtension.
Expand Down Expand Up @@ -341,7 +341,7 @@ private function registerTemplatingConfiguration(array $config, ContainerBuilder
$this->addClassesToCompile(array(
'Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface',
'Symfony\\Component\\Templating\\EngineInterface',
'Symfony\\Bundle\\FrameworkBundle\\Templating\\Loader\\TemplateLocatorInterface',
'Symfony\\Component\\Config\\FileLocatorInterface',
$container->findDefinition('templating.locator')->getClass(),
));

Expand Down
Expand Up @@ -8,8 +8,8 @@
<parameter key="router.class">Symfony\Component\Routing\Router</parameter>
<parameter key="router.cached.class">Symfony\Bundle\FrameworkBundle\Routing\CachedRouter</parameter>
<parameter key="routing.loader.class">Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader</parameter>
<parameter key="routing.file_locator.class">Symfony\Bundle\FrameworkBundle\Routing\FileLocator</parameter>
<parameter key="routing.resolver.class">Symfony\Component\Routing\Loader\LoaderResolver</parameter>
<parameter key="routing.file_locator.class">Symfony\Component\HttpKernel\Config\FileLocator</parameter>
<parameter key="routing.resolver.class">Symfony\Component\Config\Loader\LoaderResolver</parameter>
<parameter key="routing.loader.xml.class">Symfony\Component\Routing\Loader\XmlFileLoader</parameter>
<parameter key="routing.loader.yml.class">Symfony\Component\Routing\Loader\YamlFileLoader</parameter>
<parameter key="routing.loader.php.class">Symfony\Component\Routing\Loader\PhpFileLoader</parameter>
Expand Down
Expand Up @@ -13,6 +13,7 @@
<parameter key="filesystem.class">Symfony\Bundle\FrameworkBundle\Util\Filesystem</parameter>
<parameter key="cache_warmer.class">Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate</parameter>
<parameter key="cache_warmer.autoloader_map.class">Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassMapCacheWarmer</parameter>
<parameter key="file_locator.class">Symfony\Component\HttpKernel\Config\FileLocator</parameter>
</parameters>

<services>
Expand Down Expand Up @@ -55,5 +56,9 @@
</service>

<service id="filesystem" class="%filesystem.class%"></service>

<service id="file_locator" class="%file_locator.class%">
<argument type="service" id="kernel" />
</service>
</services>
</container>
Expand Up @@ -29,7 +29,7 @@
</service>

<service id="templating.locator" class="%templating.locator.class%" public="false">
<argument type="service" id="kernel" />
<argument type="service" id="file_locator" />
<argument>%kernel.root_dir%</argument>
</service>

Expand All @@ -39,6 +39,7 @@

<service id="templating.cache_warmer.template_paths" class="%templating.cache_warmer.template_paths.class%" public="false">
<argument type="service" id="kernel" />
<argument type="service" id="file_locator" />
<argument>%kernel.root_dir%/views</argument>
</service>

Expand Down
Expand Up @@ -12,8 +12,8 @@
namespace Symfony\Bundle\FrameworkBundle\Routing;

use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\Routing\Loader\DelegatingLoader as BaseDelegatingLoader;
use Symfony\Component\Routing\Loader\LoaderResolverInterface;
use Symfony\Component\Config\Loader\DelegatingLoader as BaseDelegatingLoader;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\HttpKernel\Log\LoggerInterface;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Routing/LazyLoader.php
Expand Up @@ -11,9 +11,9 @@

namespace Symfony\Bundle\FrameworkBundle\Routing;

use Symfony\Component\Routing\Loader\LoaderInterface;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Loader\LoaderResolver as BaseLoaderResolver;
use Symfony\Component\Config\Loader\LoaderResolver;

/**
* LazyLoader facilitate lazy loading of loader services.
Expand Down Expand Up @@ -78,7 +78,7 @@ public function getResolver()
*
* @param LoaderResolver $resolver A LoaderResolver instance
*/
public function setResolver(BaseLoaderResolver $resolver)
public function setResolver(LoaderResolver $resolver)
{
$this->container->get($this->service)->setResolver($resolver);
}
Expand Down
Expand Up @@ -11,12 +11,14 @@

namespace Symfony\Bundle\FrameworkBundle\Templating\Loader;

use Symfony\Component\Config\FileLocatorInterface;

/**
* CachedTemplateLocator locates templates in the cache.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class CachedTemplateLocator implements TemplateLocatorInterface
class CachedTemplateLocator implements FileLocatorInterface
{
protected $templates;

Expand All @@ -33,13 +35,16 @@ public function __construct($cacheDir)
}

/**
* Locates a template on the filesystem.
* Returns a full path for a given file.
*
* @param array $template The template name as an array
* @param string $currentPath The current path
*
* @param array $template The template name as an array
* @return string The full path for the file
*
* @return string An absolute file name
* @throws \InvalidArgumentException When file is not found
*/
public function locate($template)
public function locate($template, $currentPath = null, $first = true)
{
$key = md5(serialize($template));

Expand Down
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Templating\Storage\FileStorage;
use Symfony\Component\Templating\Loader\LoaderInterface;
use Symfony\Component\Config\FileLocatorInterface;

/**
* FilesystemLoader is a loader that read templates from the filesystem.
Expand All @@ -26,9 +27,9 @@ class FilesystemLoader implements LoaderInterface
/**
* Constructor.
*
* @param TemplateLocatorInterface $locator A TemplateLocatorInterface instance
* @param FileLocatorInterface $locator A FileLocatorInterface instance
*/
public function __construct(TemplateLocatorInterface $locator)
public function __construct(FileLocatorInterface $locator)
{
$this->locator = $locator;
}
Expand Down
Expand Up @@ -11,40 +11,43 @@

namespace Symfony\Bundle\FrameworkBundle\Templating\Loader;

use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Config\FileLocatorInterface;

/**
* TemplateLocator locates templates in bundles.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class TemplateLocator implements TemplateLocatorInterface
class TemplateLocator implements FileLocatorInterface
{
protected $kernel;
protected $locator;
protected $path;
protected $cache;

/**
* Constructor.
*
* @param KernelInterface $kernel A KernelInterface instance
* @param string $path A global fallback path
* @param FileLocatorInterface $locator A FileLocatorInterface instance
* @param string $path A global fallback path
*/
public function __construct(KernelInterface $kernel, $path)
public function __construct(FileLocatorInterface $locator, $path)
{
$this->kernel = $kernel;
$this->locator = $locator;
$this->path = $path;
$this->cache = array();
}

/**
* Locates a template on the filesystem.
* Returns a full path for a given file.
*
* @param array $template The template name as an array
* @param array $template The template name as an array
* @param string $currentPath The current path
*
* @return string An absolute file name
* @return string The full path for the file
*
* @throws \InvalidArgumentException When file is not found
*/
public function locate($template)
public function locate($template, $currentPath = null, $first = true)
{
$key = md5(serialize($template));

Expand All @@ -63,7 +66,7 @@ public function locate($template)
$resource = $template['bundle'].'/Resources/views/'.$template['controller'].'/'.$template['name'].'.'.$template['format'].'.'.$template['engine'];

try {
return $this->kernel->locateResource('@'.$resource, $this->path);
return $this->locator->locate('@'.$resource, $this->path);
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('Unable to find template "%s".', json_encode($template), $this->path), 0, $e);
}
Expand Down

0 comments on commit 5c905be

Please sign in to comment.