From 5c905beb13624d40a768e6e9ea98cb873e149c6e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 10 Feb 2011 16:15:51 +0100 Subject: [PATCH] moved common configuration classes to a new Config component --- .../DependencyInjection/AsseticExtension.php | 2 +- .../AsseticBundle/Routing/AsseticLoader.php | 2 +- .../AsseticBundle/Tests/Kernel/TestKernel.php | 2 +- .../AbstractDoctrineExtension.php | 2 +- .../DependencyInjection/DoctrineExtension.php | 4 +- .../AbstractDoctrineExtensionTest.php | 2 +- .../XmlDoctrineExtensionTest.php | 2 +- .../YamlDoctrineExtensionTest.php | 2 +- .../DoctrineMongoDBExtension.php | 4 +- .../XmlMongoDBExtensionTest.php | 2 +- .../YamlMongoDBExtensionTest.php | 2 +- .../CacheWarmer/TemplatePathsCacheWarmer.php | 12 +- .../FrameworkExtension.php | 6 +- .../Resources/config/routing.xml | 4 +- .../Resources/config/services.xml | 5 + .../Resources/config/templating.xml | 3 +- .../Routing/DelegatingLoader.php | 4 +- .../FrameworkBundle/Routing/LazyLoader.php | 6 +- .../Loader/CachedTemplateLocator.php | 15 +- .../Templating/Loader/FilesystemLoader.php | 5 +- .../Templating/Loader/TemplateLocator.php | 27 ++-- .../Loader/TemplateLocatorInterface.php | 29 ---- .../PhpFrameworkExtensionTest.php | 2 +- .../XmlFrameworkExtensionTest.php | 2 +- .../YamlFrameworkExtensionTest.php | 2 +- .../Bundle/FrameworkBundle/Tests/Kernel.php | 2 +- .../Translation/Translator.php | 78 ++-------- .../DependencyInjection/SecurityExtension.php | 4 +- .../PhpSecurityExtensionTest.php | 2 +- .../XmlSecurityExtensionTest.php | 2 +- .../YamlSecurityExtensionTest.php | 2 +- .../SwiftmailerExtension.php | 2 +- .../DependencyInjection/TwigExtension.php | 2 +- .../TwigBundle/Loader/FilesystemLoader.php | 6 +- .../Tests/Loader/FilesystemLoaderTest.php | 6 +- .../WebProfilerExtension.php | 4 +- .../DependencyInjection/ZendExtension.php | 2 +- src/Symfony/Component/Config/ConfigCache.php | 126 ++++++++++++++++ .../Loader => Config}/FileLocator.php | 55 ++++--- .../Component/Config/FileLocatorInterface.php | 30 ++++ .../Loader/DelegatingLoader.php | 14 +- .../Component/Config/Loader/FileLoader.php | 64 +++++++++ .../{Routing => Config}/Loader/Loader.php | 10 +- .../Loader/LoaderInterface.php | 12 +- .../Loader/LoaderResolver.php | 12 +- .../Loader/LoaderResolverInterface.php | 5 +- .../Resource/FileResource.php | 4 +- .../Resource/ResourceInterface.php | 4 +- .../DependencyInjection/ContainerBuilder.php | 4 +- .../Loader/ClosureLoader.php | 23 ++- .../Loader/DelegatingLoader.php | 72 ---------- .../DependencyInjection/Loader/FileLoader.php | 38 +---- .../Loader/FileLocator.php | 101 ------------- .../Loader/IniFileLoader.php | 12 +- .../DependencyInjection/Loader/Loader.php | 90 ------------ .../Loader/LoaderInterface.php | 85 ----------- .../Loader/PhpFileLoader.php | 12 +- .../Loader/XmlFileLoader.php | 12 +- .../Loader/YamlFileLoader.php | 10 +- .../Resource/FileResource.php | 68 --------- .../Resource/ResourceInterface.php | 43 ------ .../HttpKernel/Config}/FileLocator.php | 10 +- .../Loader/FileLocator.php | 50 ------- src/Symfony/Component/HttpKernel/Kernel.php | 58 ++------ .../Component/HttpKernel/KernelInterface.php | 2 +- .../HttpKernel/Resources/bin/packager.php | 2 + .../Component/HttpKernel/bootstrap.php | 121 +++++++++++----- .../Component/HttpKernel/bootstrap_cache.php | 51 ++----- .../Routing/Loader/AnnotationClassLoader.php | 5 +- .../Loader/AnnotationDirectoryLoader.php | 13 +- .../Routing/Loader/AnnotationFileLoader.php | 9 +- .../Routing/Loader/AnnotationGlobLoader.php | 2 +- .../Routing/Loader/ClosureLoader.php | 2 + .../Component/Routing/Loader/FileLoader.php | 56 -------- .../Routing/Loader/LoaderResolver.php | 75 ---------- .../Loader/LoaderResolverInterface.php | 30 ---- .../Routing/Loader/PhpFileLoader.php | 3 +- .../Routing/Loader/XmlFileLoader.php | 3 +- .../Routing/Loader/YamlFileLoader.php | 3 +- .../Component/Routing/RouteCollection.php | 2 +- src/Symfony/Component/Routing/Router.php | 73 ++-------- .../Translation/Loader/CsvFileLoader.php | 2 +- .../Translation/Loader/PhpFileLoader.php | 2 +- .../Translation/Loader/XliffFileLoader.php | 2 +- .../Translation/Loader/YamlFileLoader.php | 2 +- .../Translation/MessageCatalogue.php | 2 +- .../Translation/MessageCatalogueInterface.php | 2 +- .../Translation/Resource/FileResource.php | 60 -------- .../Resource/ResourceInterface.php | 43 ------ .../Component/Config/FileLocatorTest.php | 59 ++++++++ .../Tests/Component/Config/Fixtures/foo.xml | 0 .../Config/Loader/DelegatingLoaderTest.php | 87 +++++++++++ .../Loader/LoaderResolverTest.php | 28 ++-- .../{Routing => Config}/Loader/LoaderTest.php | 26 ++-- .../Resource/FileResourceTest.php | 16 +-- .../ContainerBuilderTest.php | 2 +- .../DependencyInjection/CrossCheckTest.php | 2 +- .../Loader/DelegatingLoaderTest.php | 86 ----------- .../Loader/FileLocatorTest.php | 36 ----- .../Loader/IniFileLoaderTest.php | 2 +- .../DependencyInjection/Loader/LoaderTest.php | 78 ---------- .../Loader/PhpFileLoaderTest.php | 4 +- .../Loader/XmlFileLoaderTest.php | 4 +- .../Loader/YamlFileLoaderTest.php | 4 +- .../Tests/Component/HttpKernel/KernelTest.php | 135 +----------------- .../Loader/AnnotationClassLoaderTest.php | 2 +- .../Loader/AnnotationDirectoryLoaderTest.php | 4 +- .../Loader/AnnotationFileLoaderTest.php | 4 +- .../Loader/AnnotationGlobLoaderTest.php | 4 +- .../Routing/Loader/ClosureLoaderTest.php | 2 +- .../Routing/Loader/DelegatingLoaderTest.php | 89 ------------ .../Routing/Loader/FileLocatorTest.php | 36 ----- .../Routing/Loader/LoaderResolverTest.php | 55 ------- .../Routing/Loader/PhpFileLoaderTest.php | 4 +- .../Routing/Loader/XmlFileLoaderTest.php | 4 +- .../Routing/Loader/YamlFileLoaderTest.php | 8 +- .../Routing/Resource/FileResourceTest.php | 38 ----- .../Component/Routing/RouteCollectionTest.php | 2 +- .../Translation/Loader/CsvFileLoaderTest.php | 2 +- .../Translation/Loader/PhpFileLoaderTest.php | 2 +- .../Loader/XliffFileLoaderTest.php | 2 +- .../Translation/Loader/YamlFileLoaderTest.php | 2 +- .../Translation/MessageCatalogTest.php | 12 +- .../Translation/Resource/FileResourceTest.php | 48 ------- 124 files changed, 796 insertions(+), 1944 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocatorInterface.php create mode 100644 src/Symfony/Component/Config/ConfigCache.php rename src/Symfony/Component/{Routing/Loader => Config}/FileLocator.php (55%) create mode 100644 src/Symfony/Component/Config/FileLocatorInterface.php rename src/Symfony/Component/{Routing => Config}/Loader/DelegatingLoader.php (76%) create mode 100644 src/Symfony/Component/Config/Loader/FileLoader.php rename src/Symfony/Component/{Routing => Config}/Loader/Loader.php (83%) rename src/Symfony/Component/{Routing => Config}/Loader/LoaderInterface.php (75%) rename src/Symfony/Component/{DependencyInjection => Config}/Loader/LoaderResolver.php (82%) rename src/Symfony/Component/{DependencyInjection => Config}/Loader/LoaderResolverInterface.php (81%) rename src/Symfony/Component/{Routing => Config}/Resource/FileResource.php (94%) rename src/Symfony/Component/{Routing => Config}/Resource/ResourceInterface.php (92%) delete mode 100644 src/Symfony/Component/DependencyInjection/Loader/DelegatingLoader.php delete mode 100644 src/Symfony/Component/DependencyInjection/Loader/FileLocator.php delete mode 100644 src/Symfony/Component/DependencyInjection/Loader/Loader.php delete mode 100644 src/Symfony/Component/DependencyInjection/Loader/LoaderInterface.php delete mode 100644 src/Symfony/Component/DependencyInjection/Resource/FileResource.php delete mode 100644 src/Symfony/Component/DependencyInjection/Resource/ResourceInterface.php rename src/Symfony/{Bundle/FrameworkBundle/Routing => Component/HttpKernel/Config}/FileLocator.php (75%) delete mode 100644 src/Symfony/Component/HttpKernel/DependencyInjection/Loader/FileLocator.php delete mode 100644 src/Symfony/Component/Routing/Loader/FileLoader.php delete mode 100644 src/Symfony/Component/Routing/Loader/LoaderResolver.php delete mode 100644 src/Symfony/Component/Routing/Loader/LoaderResolverInterface.php delete mode 100644 src/Symfony/Component/Translation/Resource/FileResource.php delete mode 100644 src/Symfony/Component/Translation/Resource/ResourceInterface.php create mode 100644 tests/Symfony/Tests/Component/Config/FileLocatorTest.php create mode 100644 tests/Symfony/Tests/Component/Config/Fixtures/foo.xml create mode 100644 tests/Symfony/Tests/Component/Config/Loader/DelegatingLoaderTest.php rename tests/Symfony/Tests/Component/{DependencyInjection => Config}/Loader/LoaderResolverTest.php (53%) rename tests/Symfony/Tests/Component/{Routing => Config}/Loader/LoaderTest.php (60%) rename tests/Symfony/Tests/Component/{DependencyInjection => Config}/Resource/FileResourceTest.php (56%) delete mode 100644 tests/Symfony/Tests/Component/DependencyInjection/Loader/DelegatingLoaderTest.php delete mode 100644 tests/Symfony/Tests/Component/DependencyInjection/Loader/FileLocatorTest.php delete mode 100644 tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderTest.php delete mode 100644 tests/Symfony/Tests/Component/Routing/Loader/DelegatingLoaderTest.php delete mode 100644 tests/Symfony/Tests/Component/Routing/Loader/FileLocatorTest.php delete mode 100644 tests/Symfony/Tests/Component/Routing/Loader/LoaderResolverTest.php delete mode 100644 tests/Symfony/Tests/Component/Routing/Resource/FileResourceTest.php delete mode 100644 tests/Symfony/Tests/Component/Translation/Resource/FileResourceTest.php diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php index 65307485ce71..c135db9b20aa 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php @@ -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. diff --git a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php index df7896e1beff..03bcb47d1ece 100644 --- a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php +++ b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php @@ -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; diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/Kernel/TestKernel.php b/src/Symfony/Bundle/AsseticBundle/Tests/Kernel/TestKernel.php index 1156449f761a..3cad4c3733db 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/Kernel/TestKernel.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/Kernel/TestKernel.php @@ -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 diff --git a/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php b/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php index a0b5dce60d62..d1589399f877 100644 --- a/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php @@ -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. diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php index bd787f042408..a173f488f2c1 100755 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php @@ -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. diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index d6405ca1f8e5..aec7f0ff086a 100755 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -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 { diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/XmlDoctrineExtensionTest.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/XmlDoctrineExtensionTest.php index 384383130043..3ae9731ec0d2 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/XmlDoctrineExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/XmlDoctrineExtensionTest.php @@ -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 { diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/YamlDoctrineExtensionTest.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/YamlDoctrineExtensionTest.php index 547479a6cc5f..933f103447eb 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/YamlDoctrineExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/YamlDoctrineExtensionTest.php @@ -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 { diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php index 66c726842b6e..117a5a1561b5 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php @@ -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; /** diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php index 2321cf5a737b..9cacee78dc24 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php @@ -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 { diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php index 32e12073a6cd..94bf1af05106 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php @@ -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 { diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php index 8da990cd21b1..242ad81f9aa1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php @@ -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. @@ -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; } @@ -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); } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index faee5952f8c1..ee0d3db7f07f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -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. @@ -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(), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index c75ca9aa9df1..89595deab2f9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -8,8 +8,8 @@ Symfony\Component\Routing\Router Symfony\Bundle\FrameworkBundle\Routing\CachedRouter Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader - Symfony\Bundle\FrameworkBundle\Routing\FileLocator - Symfony\Component\Routing\Loader\LoaderResolver + Symfony\Component\HttpKernel\Config\FileLocator + Symfony\Component\Config\Loader\LoaderResolver Symfony\Component\Routing\Loader\XmlFileLoader Symfony\Component\Routing\Loader\YamlFileLoader Symfony\Component\Routing\Loader\PhpFileLoader diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index 83ebe8b8a1e0..8b78ccd90182 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -13,6 +13,7 @@ Symfony\Bundle\FrameworkBundle\Util\Filesystem Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassMapCacheWarmer + Symfony\Component\HttpKernel\Config\FileLocator @@ -55,5 +56,9 @@ + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml index 1f8ac6f4801b..4b690da88b3e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml @@ -29,7 +29,7 @@ - + %kernel.root_dir% @@ -39,6 +39,7 @@ + %kernel.root_dir%/views diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php index 3194c4085b6e..2721286478d8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php @@ -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; /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/LazyLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/LazyLoader.php index b3632108e0b1..cb6d1536a203 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/LazyLoader.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/LazyLoader.php @@ -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. @@ -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); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php index af00a861b5d9..6fae569665d6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php @@ -11,12 +11,14 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Loader; +use Symfony\Component\Config\FileLocatorInterface; + /** * CachedTemplateLocator locates templates in the cache. * * @author Fabien Potencier */ -class CachedTemplateLocator implements TemplateLocatorInterface +class CachedTemplateLocator implements FileLocatorInterface { protected $templates; @@ -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)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/FilesystemLoader.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/FilesystemLoader.php index 7d381d1a770d..f239430e0c4a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/FilesystemLoader.php @@ -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. @@ -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; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php index bc89cdd72b4b..d47377c0f375 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php @@ -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 */ -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)); @@ -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); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocatorInterface.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocatorInterface.php deleted file mode 100644 index e452cb635e02..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocatorInterface.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Templating\Loader; - -/** - * Interfaces for classes that locates templates on disk - * - * @author Fabien Potencier - */ -interface TemplateLocatorInterface -{ - /** - * Locates a template on the filesystem. - * - * @param array $template The template name as an array - * - * @return string An absolute file name - */ - function locate($template); -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php index 649f63b401a8..38db48e0081e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php @@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\Config\FileLocator; class PhpFrameworkExtensionTest extends FrameworkExtensionTest { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php index 975d8fba1da2..cad3452bdd60 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php @@ -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 XmlFrameworkExtensionTest extends FrameworkExtensionTest { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php index 278d7d058ede..3490bf46831f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php @@ -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 YamlFrameworkExtensionTest extends FrameworkExtensionTest { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php index f6afcbdbf2d2..7498a4ea7dec 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php @@ -12,9 +12,9 @@ namespace Symfony\Bundle\FrameworkBundle\Tests; use Symfony\Component\HttpKernel\Kernel as BaseKernel; -use Symfony\Component\DependencyInjection\Loader\LoaderInterface; use Symfony\Bundle\FrameworkBundle\Util\Filesystem; use Symfony\Component\ClassLoader\UniversalClassLoader; +use Symfony\Component\Config\Loader\LoaderInterface; class Kernel extends BaseKernel { diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php index 2e70bdf004e5..113a7b88fec7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php @@ -16,6 +16,7 @@ use Symfony\Component\Translation\MessageSelector; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Session; +use Symfony\Component\Config\ConfigCache; /** * Translator. @@ -88,17 +89,24 @@ protected function loadCatalogue($locale) return parent::loadCatalogue($locale); } - if ($this->needsReload($locale)) { + $cache = new ConfigCache($this->options['cache_dir'], 'catalogue.'.$locale, $this->options['debug']); + if (!$cache->isFresh()) { $this->initialize(); parent::loadCatalogue($locale); - $this->updateCache($locale); + $content = sprintf( + "catalogues[$locale]->all(), true) + )); + + $cache->write($content, $this->catalogues[$locale]->getResources()); return; } - $this->catalogues[$locale] = include $this->getCacheFile($locale); + $this->catalogues[$locale] = include $cache; } protected function initialize() @@ -111,68 +119,4 @@ protected function initialize() $this->addResource($resource[0], $resource[1], $resource[2], $resource[3]); } } - - protected function updateCache($locale) - { - $this->writeCacheFile($this->getCacheFile($locale), sprintf( - "catalogues[$locale]->all(), true) - )); - - if ($this->options['debug']) { - $this->writeCacheFile($this->getCacheFile($locale, 'meta'), serialize($this->catalogues[$locale]->getResources())); - } - } - - protected function needsReload($locale) - { - $file = $this->getCacheFile($locale); - if (!file_exists($file)) { - return true; - } - - if (!$this->options['debug']) { - return false; - } - - $metadata = $this->getCacheFile($locale, 'meta'); - if (!file_exists($metadata)) { - return true; - } - - $time = filemtime($file); - $meta = unserialize(file_get_contents($metadata)); - foreach ($meta as $resource) { - if (!$resource->isUptodate($time)) { - return true; - } - } - - return false; - } - - protected function getCacheFile($locale, $extension = 'php') - { - return $this->options['cache_dir'].'/catalogue.'.$locale.'.'.$extension; - } - - /** - * @throws \RuntimeException When cache file can't be wrote - */ - protected function writeCacheFile($file, $content) - { - if (!is_dir(dirname($file))) { - @mkdir(dirname($file), 0777, true); - } - - $tmpFile = tempnam(dirname($file), basename($file)); - if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { - chmod($file, 0644); - - return; - } - - throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file)); - } } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index c633436e4c3e..e9167ac1a82b 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -17,13 +17,13 @@ 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\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; +use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpFoundation\RequestMatcher; /** diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpSecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpSecurityExtensionTest.php index 931dd72fbfaf..ebf26751a02d 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpSecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpSecurityExtensionTest.php @@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\Config\FileLocator; class PhpSecurityExtensionTest extends SecurityExtensionTest { diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlSecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlSecurityExtensionTest.php index 2b0605280e87..eb988bb72f0c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlSecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlSecurityExtensionTest.php @@ -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 XmlSecurityExtensionTest extends SecurityExtensionTest { diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlSecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlSecurityExtensionTest.php index bc45a9c19aa8..0ea5842f1e62 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlSecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlSecurityExtensionTest.php @@ -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 YamlSecurityExtensionTest extends SecurityExtensionTest { diff --git a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php index c70c6daab205..8948161ed9c4 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php @@ -13,9 +13,9 @@ 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\Reference; +use Symfony\Component\Config\FileLocator; /** * SwiftMailerExtension is an extension for the SwiftMailer library. diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 297edc616db6..93d571e7e931 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\Config\FileLocator; /** * TwigExtension. diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index 6700be1ae6dd..aa9f78d02f41 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -11,8 +11,8 @@ namespace Symfony\Bundle\TwigBundle\Loader; -use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocatorInterface; use Symfony\Component\Templating\TemplateNameParserInterface; +use Symfony\Component\Config\FileLocatorInterface; /** * FilesystemLoader extends the default Twig filesystem loader @@ -29,9 +29,9 @@ class FilesystemLoader implements \Twig_LoaderInterface /** * Constructor. * - * @param TemplateLocator $locator A TemplateLocator instance + * @param FileLocatorInterface $locator A FileLocatorInterface instance */ - public function __construct(TemplateLocatorInterface $locator, TemplateNameParserInterface $parser) + public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser) { $this->locator = $locator; $this->parser = $parser; diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php index 4f935f61e9b6..f94c7355c334 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php @@ -13,13 +13,13 @@ use Symfony\Bundle\TwigBundle\Tests\TestCase; use Symfony\Bundle\TwigBundle\Loader\FilesystemLoader; -use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocatorInterface; +use Symfony\Component\Config\FileLocatorInterface; use Symfony\Component\Templating\TemplateNameParserInterface; use InvalidArgumentException; class FilesystemLoaderTest extends TestCase { - /** @var TemplateLocatorInterface */ + /** @var FileLocatorInterface */ private $locator; /** @var TemplateNameParserInterface */ private $parser; @@ -30,7 +30,7 @@ protected function setUp() { parent::setUp(); - $this->locator = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocatorInterface'); + $this->locator = $this->getMock('Symfony\Component\Config\FileLocatorInterface'); $this->parser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface'); $this->loader = new FilesystemLoader($this->locator, $this->parser); } diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index d50fb1409c3b..eced6892bb52 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -13,11 +13,11 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; 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\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\Config\FileLocator; /** * WebProfilerExtension. diff --git a/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php b/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php index 8c12c0053631..ac3c57957948 100644 --- a/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php +++ b/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php @@ -13,8 +13,8 @@ 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\Config\FileLocator; /** * ZendExtension is an extension for the Zend Framework libraries. diff --git a/src/Symfony/Component/Config/ConfigCache.php b/src/Symfony/Component/Config/ConfigCache.php new file mode 100644 index 000000000000..7d3c25219edc --- /dev/null +++ b/src/Symfony/Component/Config/ConfigCache.php @@ -0,0 +1,126 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config; + +/** + * ConfigCache manages PHP cache files. + * + * When debug is enabled, it knows when to flush the cache + * thanks to an array of ResourceInterface instances. + * + * @author Fabien Potencier + */ +class ConfigCache +{ + protected $debug; + protected $cacheDir; + protected $file; + + /** + * Constructor. + * + * @param string $cacheDir The cache directory + * @param string $file The cache file name (without the .php extension) + * @param Boolean $debug Whether debugging is enabled or not + */ + public function __construct($cacheDir, $file, $debug) + { + $this->cacheDir = $cacheDir; + $this->file = $file; + $this->debug = (Boolean) $debug; + } + + /** + * Gets the cache file path. + * + * @return string The cache file path + */ + public function __toString() + { + return $this->cacheDir.'/'.$this->file.'.php'; + } + + /** + * Checks if the cache is still fresh. + * + * This method always returns true is debug is on and the cache file exists. + * + * @return Boolean true if the cache is fresh, false otherwise + */ + public function isFresh() + { + $file = $this->getCacheFile(); + if (!file_exists($file)) { + return false; + } + + if (!$this->debug) { + return true; + } + + $metadata = $this->getCacheFile('meta'); + if (!file_exists($metadata)) { + return false; + } + + $time = filemtime($file); + $meta = unserialize(file_get_contents($metadata)); + foreach ($meta as $resource) { + if (!$resource->isFresh($time)) { + return false; + } + } + + return true; + } + + /** + * Writes cache. + * + * @param string $content The content to write in the cache + * @param array $metadata An array of ResourceInterface instances + * + * @throws \RuntimeException When cache file can't be wrote + */ + public function write($content, array $metadata = null) + { + $file = $this->getCacheFile(); + $dir = dirname($file); + if (!is_dir($dir)) { + if (false === @mkdir($dir, 0777, true)) { + throw new \RuntimeException(sprintf('Unable to create the %s directory', $dir)); + } + } elseif (!is_writable($dir)) { + throw new \RuntimeException(sprintf('Unable to write in the %s directory', $dir)); + } + + $tmpFile = tempnam(dirname($file), basename($file)); + if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { + chmod($file, 0666); + } else { + throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $this->file)); + } + + if (null !== $metadata && true === $this->debug) { + $file = $this->getCacheFile('meta'); + $tmpFile = tempnam(dirname($file), basename($file)); + if (false !== @file_put_contents($tmpFile, serialize($metadata)) && @rename($tmpFile, $file)) { + chmod($file, 0666); + } + } + } + + protected function getCacheFile($extension = 'php') + { + return $this->cacheDir.'/'.$this->file.'.'.$extension; + } +} diff --git a/src/Symfony/Component/Routing/Loader/FileLocator.php b/src/Symfony/Component/Config/FileLocator.php similarity index 55% rename from src/Symfony/Component/Routing/Loader/FileLocator.php rename to src/Symfony/Component/Config/FileLocator.php index 17ce70fa0aad..f62c8b9724f7 100644 --- a/src/Symfony/Component/Routing/Loader/FileLocator.php +++ b/src/Symfony/Component/Config/FileLocator.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Routing\Loader; +namespace Symfony\Component\Config; /** * FileLocator uses an array of pre-defined paths to find files. * * @author Fabien Potencier */ -class FileLocator +class FileLocator implements FileLocatorInterface { protected $paths; @@ -34,48 +34,41 @@ public function __construct($paths = array()) } /** - * Returns a full path for a given file. + * Returns a full path for a given file name. * - * @param string $file A file path + * @param mixed $name The file name to locate * @param string $currentPath The current path * * @return string The full path for the file * * @throws \InvalidArgumentException When file is not found */ - public function locate($file, $currentPath = null) + public function locate($name, $currentPath = null, $first = true) { - $path = $this->getAbsolutePath($file, $currentPath); - if (!file_exists($path)) { - throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $file, implode(', ', $this->paths))); + if ($this->isAbsolutePath($name)) { + if (!file_exists($name)) { + throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name)); + } + + return $name; } - return $path; - } + $filepaths = array(); + if (null !== $currentPath && file_exists($currentPath.DIRECTORY_SEPARATOR.$name)) { + $filepaths[] = $currentPath.DIRECTORY_SEPARATOR.$name; + } - /** - * Gets the absolute path for the file path if possible. - * - * @param string $file A file path - * @param string $currentPath The current path - * - * @return string - */ - public function getAbsolutePath($file, $currentPath = null) - { - if ($this->isAbsolutePath($file)) { - return $file; - } else if (null !== $currentPath && file_exists($currentPath.DIRECTORY_SEPARATOR.$file)) { - return $currentPath.DIRECTORY_SEPARATOR.$file; - } else { - foreach ($this->paths as $path) { - if (file_exists($path.DIRECTORY_SEPARATOR.$file)) { - return $path.DIRECTORY_SEPARATOR.$file; - } + foreach ($this->paths as $path) { + if (file_exists($path.DIRECTORY_SEPARATOR.$name)) { + $filepaths[] = $path.DIRECTORY_SEPARATOR.$name; } } - return $file; + if (!$filepaths) { + throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s%s).', $name, null !== $currentPath ? $currentPath.', ' : '', implode(', ', $this->paths))); + } + + return true === $first ? $filepaths[0] : $filepaths; } /** @@ -85,7 +78,7 @@ public function getAbsolutePath($file, $currentPath = null) * * @return Boolean */ - public function isAbsolutePath($file) + protected function isAbsolutePath($file) { if ($file[0] == '/' || $file[0] == '\\' || (strlen($file) > 3 && ctype_alpha($file[0]) diff --git a/src/Symfony/Component/Config/FileLocatorInterface.php b/src/Symfony/Component/Config/FileLocatorInterface.php new file mode 100644 index 000000000000..fff08e179c30 --- /dev/null +++ b/src/Symfony/Component/Config/FileLocatorInterface.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config; + +/** + * @author Fabien Potencier + */ +interface FileLocatorInterface +{ + /** + * Returns a full path for a given file name. + * + * @param mixed $name The file name to locate + * @param string $currentPath The current path + * + * @return string The full path for the file + * + * @throws \InvalidArgumentException When file is not found + */ + function locate($name, $currentPath = null, $first = true); +} diff --git a/src/Symfony/Component/Routing/Loader/DelegatingLoader.php b/src/Symfony/Component/Config/Loader/DelegatingLoader.php similarity index 76% rename from src/Symfony/Component/Routing/Loader/DelegatingLoader.php rename to src/Symfony/Component/Config/Loader/DelegatingLoader.php index 998f570088e4..cec066fb96c0 100644 --- a/src/Symfony/Component/Routing/Loader/DelegatingLoader.php +++ b/src/Symfony/Component/Config/Loader/DelegatingLoader.php @@ -9,12 +9,10 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Routing\Loader; - -use Symfony\Component\Routing\RouteCollection; +namespace Symfony\Component\Config\Loader; /** - * DelegatingLoader delegates route loading to other loaders using a loader resolver. + * DelegatingLoader delegates loading to other loaders using a loader resolver. * * This loader acts as an array of LoaderInterface objects - each having * a chance to load a given resource (handled by the resolver) @@ -43,17 +41,13 @@ public function __construct(LoaderResolverInterface $resolver) * * @param mixed $resource A resource * @param string $type The resource type - * - * @return RouteCollection A RouteCollection instance - * - * @throws \InvalidArgumentException When the resource cannot be loaded */ public function load($resource, $type = null) { $loader = $this->resolver->resolve($resource, $type); if (false === $loader) { - throw new \InvalidArgumentException(sprintf('Unable to load the "%s" routing resource.', is_string($resource) ? $resource : (is_object($resource) ? get_class($resource) : 'RESOURCE'))); + throw new \InvalidArgumentException(sprintf('Unable to load the "%s" resource.', is_string($resource) ? $resource : (is_object($resource) ? get_class($resource) : 'RESOURCE'))); } return $loader->load($resource, $type); @@ -65,7 +59,7 @@ public function load($resource, $type = null) * @param mixed $resource A resource * @param string $type The resource type * - * @return Boolean True if this class supports the given resource, false otherwise + * @return Boolean true if this class supports the given resource, false otherwise */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/Config/Loader/FileLoader.php b/src/Symfony/Component/Config/Loader/FileLoader.php new file mode 100644 index 000000000000..5ab07c32634f --- /dev/null +++ b/src/Symfony/Component/Config/Loader/FileLoader.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config\Loader; + +use Symfony\Component\Config\FileLocatorInterface; + +/** + * FileLoader is the abstract class used by all built-in loaders that are file based. + * + * @author Fabien Potencier + */ +abstract class FileLoader extends Loader +{ + protected $locator; + protected $currentDir; + + /** + * Constructor. + */ + public function __construct(FileLocatorInterface $locator) + { + $this->locator = $locator; + } + + public function getLocator() + { + return $this->locator; + } + + /** + * Adds definitions and parameters from a resource. + * + * @param mixed $resource A Resource + * @param string $type The resource type + * @param Boolean $ignoreErrors Whether to ignore import errors or not + * + * @return mixed + */ + public function import($resource, $type = null, $ignoreErrors = false) + { + try { + $loader = $this->resolve($resource, $type); + + if ($loader instanceof FileLoader && null !== $this->currentDir) { + $resource = $this->locator->locate($resource, $this->currentDir); + } + + return $loader->load($resource); + } catch (\Exception $e) { + if (!$ignoreErrors) { + throw $e; + } + } + } +} diff --git a/src/Symfony/Component/Routing/Loader/Loader.php b/src/Symfony/Component/Config/Loader/Loader.php similarity index 83% rename from src/Symfony/Component/Routing/Loader/Loader.php rename to src/Symfony/Component/Config/Loader/Loader.php index a46116aa9ffc..20f24df0020e 100644 --- a/src/Symfony/Component/Routing/Loader/Loader.php +++ b/src/Symfony/Component/Config/Loader/Loader.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Routing\Loader; +namespace Symfony\Component\Config\Loader; /** * Loader is the abstract class used by all built-in loaders. @@ -41,18 +41,18 @@ public function setResolver(LoaderResolver $resolver) } /** - * Adds routes from a resource. + * Adds definitions and parameters from a resource. * * @param mixed $resource A Resource * @param string $type The resource type */ public function import($resource, $type = null) { - $this->resolve($resource, $type)->load($resource); + $this->resolve($resource)->load($resource, $type); } /** - * Finds a loader able to load an imported resource + * Finds a loader able to load an imported resource. * * @param mixed $resource A Resource * @param string $type The resource type @@ -71,7 +71,7 @@ public function resolve($resource, $type = null) } if (false === $loader) { - throw new \InvalidArgumentException(sprintf('Unable to load the "%s" routing resource.', is_string($resource) ? $resource : (is_object($resource) ? get_class($resource) : 'RESOURCE'))); + throw new \InvalidArgumentException(sprintf('Unable to load the "%s" resource.', is_string($resource) ? $resource : (is_object($resource) ? get_class($resource) : 'RESOURCE'))); } return $loader; diff --git a/src/Symfony/Component/Routing/Loader/LoaderInterface.php b/src/Symfony/Component/Config/Loader/LoaderInterface.php similarity index 75% rename from src/Symfony/Component/Routing/Loader/LoaderInterface.php rename to src/Symfony/Component/Config/Loader/LoaderInterface.php index a9de96640f3c..b803373d0a7e 100644 --- a/src/Symfony/Component/Routing/Loader/LoaderInterface.php +++ b/src/Symfony/Component/Config/Loader/LoaderInterface.php @@ -9,12 +9,10 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Routing\Loader; - -use Symfony\Component\Routing\Loader\LoaderResolver; +namespace Symfony\Component\Config\Loader; /** - * LoaderInterface is the interface that all loader classes must implement. + * LoaderInterface is the interface implemented by all loader classes. * * @author Fabien Potencier */ @@ -23,10 +21,8 @@ interface LoaderInterface /** * Loads a resource. * - * @param mixed $resource A resource + * @param mixed $resource The resource * @param string $type The resource type - * - * @return RouteCollection A RouteCollection instance */ function load($resource, $type = null); @@ -36,7 +32,7 @@ function load($resource, $type = null); * @param mixed $resource A resource * @param string $type The resource type * - * @return Boolean True if this class supports the given resource, false otherwise + * @return Boolean true if this class supports the given resource, false otherwise */ function supports($resource, $type = null); diff --git a/src/Symfony/Component/DependencyInjection/Loader/LoaderResolver.php b/src/Symfony/Component/Config/Loader/LoaderResolver.php similarity index 82% rename from src/Symfony/Component/DependencyInjection/Loader/LoaderResolver.php rename to src/Symfony/Component/Config/Loader/LoaderResolver.php index fe29bafdac23..f23c8dc2f6b9 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/LoaderResolver.php +++ b/src/Symfony/Component/Config/Loader/LoaderResolver.php @@ -9,14 +9,13 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\DependencyInjection\Loader; +namespace Symfony\Component\Config\Loader; /** * LoaderResolver selects a loader for a given resource. * - * A resource can be anything that can be converted to a ContainerBuilder - * instance (e.g. a full path to a config file or a Closure). Each - * loader determines whether it can load a resource and how. + * A resource can be anything (e.g. a full path to a config file or a Closure). + * Each loader determines whether it can load a resource and how. * * @author Fabien Potencier */ @@ -44,13 +43,14 @@ public function __construct(array $loaders = array()) * Returns a loader able to load the resource. * * @param mixed $resource A resource + * @param string $type The resource type * * @return LoaderInterface|false A LoaderInterface instance */ - public function resolve($resource) + public function resolve($resource, $type = null) { foreach ($this->loaders as $loader) { - if ($loader->supports($resource)) { + if ($loader->supports($resource, $type)) { return $loader; } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/LoaderResolverInterface.php b/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php similarity index 81% rename from src/Symfony/Component/DependencyInjection/Loader/LoaderResolverInterface.php rename to src/Symfony/Component/Config/Loader/LoaderResolverInterface.php index af36f3059dce..a1a0b836a24e 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/LoaderResolverInterface.php +++ b/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\DependencyInjection\Loader; +namespace Symfony\Component\Config\Loader; /** * LoaderResolverInterface selects a loader for a given resource. @@ -22,8 +22,9 @@ interface LoaderResolverInterface * Returns a loader able to load the resource. * * @param mixed $resource A resource + * @param string $type The resource type * * @return LoaderInterface A LoaderInterface instance */ - function resolve($resource); + function resolve($resource, $type = null); } diff --git a/src/Symfony/Component/Routing/Resource/FileResource.php b/src/Symfony/Component/Config/Resource/FileResource.php similarity index 94% rename from src/Symfony/Component/Routing/Resource/FileResource.php rename to src/Symfony/Component/Config/Resource/FileResource.php index 1f57d8f1d943..b4aa03146f52 100644 --- a/src/Symfony/Component/Routing/Resource/FileResource.php +++ b/src/Symfony/Component/Config/Resource/FileResource.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Routing\Resource; +namespace Symfony\Component\Config\Resource; /** * FileResource represents a resource stored on the filesystem. @@ -57,7 +57,7 @@ public function getResource() * * @return Boolean true if the resource has not been updated, false otherwise */ - public function isUptodate($timestamp) + public function isFresh($timestamp) { if (!file_exists($this->resource)) { return false; diff --git a/src/Symfony/Component/Routing/Resource/ResourceInterface.php b/src/Symfony/Component/Config/Resource/ResourceInterface.php similarity index 92% rename from src/Symfony/Component/Routing/Resource/ResourceInterface.php rename to src/Symfony/Component/Config/Resource/ResourceInterface.php index d55ce4d8ffb7..764d4a3677ee 100644 --- a/src/Symfony/Component/Routing/Resource/ResourceInterface.php +++ b/src/Symfony/Component/Config/Resource/ResourceInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Routing\Resource; +namespace Symfony\Component\Config\Resource; /** * ResourceInterface is the interface that must be implemented by all Resource classes. @@ -32,7 +32,7 @@ function __toString(); * * @return Boolean true if the resource has not been updated, false otherwise */ - function isUptodate($timestamp); + function isFresh($timestamp); /** * Returns the resource tied to this Resource. diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index eb38fc4cedba..e41854c7b6a1 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -17,8 +17,8 @@ use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\DependencyInjection\InterfaceInjector; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\DependencyInjection\Resource\FileResource; -use Symfony\Component\DependencyInjection\Resource\ResourceInterface; +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Config\Resource\ResourceInterface; /** * ContainerBuilder is a DI container that provides an API to easily describe services. diff --git a/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php b/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php index 31cf0ec5f352..bc4559557659 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php @@ -11,6 +11,9 @@ namespace Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Config\Loader\Loader; + /** * ClosureLoader loads service definitions from a PHP closure. * @@ -20,12 +23,25 @@ */ class ClosureLoader extends Loader { + protected $container; + + /** + * Constructor. + * + * @param ContainerBuilder $container A ContainerBuilder instance + */ + public function __construct(ContainerBuilder $container) + { + $this->container = $container; + } + /** * Loads a Closure. * * @param \Closure $resource The resource + * @param string $type The resource type */ - public function load($closure) + public function load($closure, $type = null) { call_user_func($closure, $this->container); } @@ -33,11 +49,12 @@ public function load($closure) /** * Returns true if this class supports the given resource. * - * @param mixed $resource A resource + * @param mixed $resource A resource + * @param string $type The resource type * * @return Boolean true if this class supports the given resource, false otherwise */ - public function supports($resource) + public function supports($resource, $type = null) { return $resource instanceof \Closure; } diff --git a/src/Symfony/Component/DependencyInjection/Loader/DelegatingLoader.php b/src/Symfony/Component/DependencyInjection/Loader/DelegatingLoader.php deleted file mode 100644 index cbbf92e37d01..000000000000 --- a/src/Symfony/Component/DependencyInjection/Loader/DelegatingLoader.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Loader; - -/** - * DelegatingLoader delegates loading to other loaders using a loader resolver. - * - * This loader acts as an array of LoaderInterface objects - each having - * a chance to load a given resource (handled by the resolver) - * - * @author Fabien Potencier - */ -class DelegatingLoader extends Loader -{ - /** - * @var LoaderResolverInterface - */ - protected $resolver; - - /** - * Constructor. - * - * @param LoaderResolverInterface $resolver A LoaderResolverInterface instance - */ - public function __construct(LoaderResolverInterface $resolver) - { - $this->resolver = $resolver; - } - - /** - * Loads a resource. - * - * @param mixed $resource A resource - */ - public function load($resource) - { - $loader = $this->resolver->resolve($resource); - - if (false === $loader) { - throw new \InvalidArgumentException(sprintf('Unable to load the "%s" container resource.', is_string($resource) ? $resource : (is_object($resource) ? get_class($resource) : 'RESOURCE'))); - } - - return $loader->load($resource); - } - - /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * - * @return Boolean true if this class supports the given resource, false otherwise - */ - public function supports($resource) - { - foreach ($this->resolver->getLoaders() as $loader) { - if ($loader->supports($resource)) { - return true; - } - } - - return false; - } -} diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php index e8751d9c8e35..7a729561c9ea 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php @@ -12,16 +12,17 @@ namespace Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Config\Loader\FileLoader as BaseFileLoader; +use Symfony\Component\Config\FileLocator; /** * FileLoader is the abstract class used by all built-in loaders that are file based. * * @author Fabien Potencier */ -abstract class FileLoader extends Loader +abstract class FileLoader extends BaseFileLoader { - protected $locator; - protected $currentDir; + protected $container; /** * Constructor. @@ -30,35 +31,8 @@ abstract class FileLoader extends Loader */ public function __construct(ContainerBuilder $container, FileLocator $locator) { - $this->locator = $locator; + $this->container = $container; - parent::__construct($container); - } - - public function getLocator() - { - return $this->locator; - } - - /** - * Adds definitions and parameters from a resource. - * - * @param mixed $resource A Resource - */ - public function import($resource, $ignoreErrors = false) - { - try { - $loader = $this->resolve($resource); - - if ($loader instanceof FileLoader && null !== $this->currentDir) { - $resource = $this->locator->locate($resource, $this->currentDir); - } - - $loader->load($resource); - } catch (\Exception $e) { - if (!$ignoreErrors) { - throw $e; - } - } + parent::__construct($locator); } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLocator.php b/src/Symfony/Component/DependencyInjection/Loader/FileLocator.php deleted file mode 100644 index a3a2616751ea..000000000000 --- a/src/Symfony/Component/DependencyInjection/Loader/FileLocator.php +++ /dev/null @@ -1,101 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Loader; - -/** - * FileLocator uses an array of pre-defined paths to find files. - * - * @author Fabien Potencier - */ -class FileLocator -{ - protected $paths; - - /** - * Constructor. - * - * @param string|array $paths A path or an array of paths where to look for resources - */ - public function __construct($paths = array()) - { - if (!is_array($paths)) { - $paths = array($paths); - } - $this->paths = $paths; - } - - /** - * Returns a full path for a given file. - * - * @param string $file A file path - * @param string $currentPath The current path - * - * @return string The full path for the file - * - * @throws \InvalidArgumentException When file is not found - */ - public function locate($file, $currentPath = null) - { - $path = $this->getAbsolutePath($file, $currentPath); - if (!file_exists($path)) { - throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $file, implode(', ', $this->paths))); - } - - return $path; - } - - /** - * Gets the absolute path for the file path if possible. - * - * @param string $file A file path - * @param string $currentPath The current path - * - * @return string - */ - public function getAbsolutePath($file, $currentPath = null) - { - if ($this->isAbsolutePath($file)) { - return $file; - } else if (null !== $currentPath && file_exists($currentPath.DIRECTORY_SEPARATOR.$file)) { - return $currentPath.DIRECTORY_SEPARATOR.$file; - } else { - foreach ($this->paths as $path) { - if (file_exists($path.DIRECTORY_SEPARATOR.$file)) { - return $path.DIRECTORY_SEPARATOR.$file; - } - } - } - - return $file; - } - - /** - * Returns whether the file path is an absolute path. - * - * @param string $file A file path - * - * @return Boolean - */ - public function isAbsolutePath($file) - { - if ($file[0] == '/' || $file[0] == '\\' - || (strlen($file) > 3 && ctype_alpha($file[0]) - && $file[1] == ':' - && ($file[2] == '\\' || $file[2] == '/') - ) - ) { - return true; - } - - return false; - } -} diff --git a/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php index 7dddd1c63f67..d8381384ca70 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php @@ -12,7 +12,7 @@ namespace Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; /** * IniFileLoader loads parameters from INI files. @@ -24,11 +24,12 @@ class IniFileLoader extends FileLoader /** * Loads a resource. * - * @param mixed $resource The resource + * @param mixed $resource The resource + * @param string $type The resource type * * @throws \InvalidArgumentException When ini file is not valid */ - public function load($file) + public function load($file, $type = null) { $path = $this->locator->locate($file); @@ -49,11 +50,12 @@ public function load($file) /** * Returns true if this class supports the given resource. * - * @param mixed $resource A resource + * @param mixed $resource A resource + * @param string $type The resource type * * @return Boolean true if this class supports the given resource, false otherwise */ - public function supports($resource) + public function supports($resource, $type = null) { return is_string($resource) && 'ini' === pathinfo($resource, PATHINFO_EXTENSION); } diff --git a/src/Symfony/Component/DependencyInjection/Loader/Loader.php b/src/Symfony/Component/DependencyInjection/Loader/Loader.php deleted file mode 100644 index 07c79e12fdcc..000000000000 --- a/src/Symfony/Component/DependencyInjection/Loader/Loader.php +++ /dev/null @@ -1,90 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Loader; - -use Symfony\Component\DependencyInjection\ContainerBuilder; - -/** - * Loader is the abstract class used by all built-in loaders. - * - * @author Fabien Potencier - */ -abstract class Loader implements LoaderInterface -{ - protected $container; - protected $resolver; - - /** - * Constructor. - * - * @param ContainerBuilder $container A ContainerBuilder instance - */ - public function __construct(ContainerBuilder $container) - { - $this->container = $container; - } - - /** - * Gets the loader resolver. - * - * @return LoaderResolver A LoaderResolver instance - */ - public function getResolver() - { - return $this->resolver; - } - - /** - * Sets the loader resolver. - * - * @param LoaderResolver $resolver A LoaderResolver instance - */ - public function setResolver(LoaderResolver $resolver) - { - $this->resolver = $resolver; - } - - /** - * Adds definitions and parameters from a resource. - * - * @param mixed $resource A Resource - */ - public function import($resource) - { - $this->resolve($resource)->load($resource); - } - - /** - * Finds a loader able to load an imported resource. - * - * @param mixed $resource A Resource - * - * @return LoaderInterface A LoaderInterface instance - * - * @throws \InvalidArgumentException if no loader is found - */ - public function resolve($resource) - { - $loader = false; - if ($this->supports($resource)) { - $loader = $this; - } elseif (null !== $this->resolver) { - $loader = $this->resolver->resolve($resource); - } - - if (false === $loader) { - throw new \InvalidArgumentException(sprintf('Unable to load the "%s" container resource.', is_string($resource) ? $resource : (is_object($resource) ? get_class($resource) : 'RESOURCE'))); - } - - return $loader; - } -} diff --git a/src/Symfony/Component/DependencyInjection/Loader/LoaderInterface.php b/src/Symfony/Component/DependencyInjection/Loader/LoaderInterface.php deleted file mode 100644 index 3353a008b811..000000000000 --- a/src/Symfony/Component/DependencyInjection/Loader/LoaderInterface.php +++ /dev/null @@ -1,85 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Loader; - -use Symfony\Component\DependencyInjection\ContainerBuilder; - -/** - * LoaderInterface is the interface implemented by all loader classes. - * - * $loader = new XXXLoader(); - * $config = $loader->load('resource_name'); - * - * $container = new ContainerBuilder(); - * $container->merge($config); - * - * @author Fabien Potencier - */ -interface LoaderInterface -{ - /** - * Loads a resource. - * - * A resource can be anything that can be converted to a - * ContainerBuilder instance. - * - * Some loaders support an array of resources as an argument to the - * constructor. - * - * If multiple resources are loaded, the services and parameters are merged. - * - * Remember that services and parameters are simple key/pair stores. - * - * When overriding a value, the old one is totally replaced, even if it is - * a "complex" value (an array for instance): - * - *
-     *   file1.xml
-     *   
-     *     true
-     *     false
-     *   
-     *
-     *   file2.xml
-     *   foo
-     * 
- * - * If you load file1.xml and file2.xml in this order, the value of complex - * will be "foo". - * - * @param mixed $resource The resource - */ - function load($resource); - - /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * - * @return Boolean true if this class supports the given resource, false otherwise - */ - function supports($resource); - - /** - * Gets the loader resolver. - * - * @return LoaderResolver A LoaderResolver instance - */ - function getResolver(); - - /** - * Sets the loader resolver. - * - * @param LoaderResolver $resolver A LoaderResolver instance - */ - function setResolver(LoaderResolver $resolver); -} diff --git a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php index 34ed56f86e52..eaa3b73ff466 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php @@ -11,7 +11,7 @@ namespace Symfony\Component\DependencyInjection\Loader; -use Symfony\Component\DependencyInjection\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; /** * PhpFileLoader loads service definitions from a PHP file. @@ -26,9 +26,10 @@ class PhpFileLoader extends FileLoader /** * Loads a PHP file. * - * @param mixed $resource The resource + * @param mixed $resource The resource + * @param string $type The resource type */ - public function load($file) + public function load($file, $type = null) { // the container and loader variables are exposed to the included file below $container = $this->container; @@ -44,11 +45,12 @@ public function load($file) /** * Returns true if this class supports the given resource. * - * @param mixed $resource A resource + * @param mixed $resource A resource + * @param string $type The resource type * * @return Boolean true if this class supports the given resource, false otherwise */ - public function supports($resource) + public function supports($resource, $type = null) { return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION); } diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 03420f00e384..6c89c17341ec 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -20,7 +20,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\SimpleXMLElement; -use Symfony\Component\DependencyInjection\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; /** * XmlFileLoader loads XML files service definitions. @@ -32,9 +32,10 @@ class XmlFileLoader extends FileLoader /** * Loads an XML file. * - * @param mixed $resource The resource + * @param mixed $resource The resource + * @param string $type The resource type */ - public function load($file) + public function load($file, $type = null) { $path = $this->locator->locate($file); @@ -64,11 +65,12 @@ public function load($file) /** * Returns true if this class supports the given resource. * - * @param mixed $resource A resource + * @param mixed $resource A resource + * @param string $type The resource type * * @return Boolean true if this class supports the given resource, false otherwise */ - public function supports($resource) + public function supports($resource, $type = null) { return is_string($resource) && 'xml' === pathinfo($resource, PATHINFO_EXTENSION); } diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index f57701803cf5..e4f0ae75dba2 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -19,7 +19,7 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Yaml\Yaml; /** @@ -35,8 +35,9 @@ class YamlFileLoader extends FileLoader * Loads a Yaml file. * * @param mixed $resource The resource + * @param string $type The resource type */ - public function load($file) + public function load($file, $type = null) { $path = $this->locator->locate($file); @@ -72,11 +73,12 @@ public function load($file) /** * Returns true if this class supports the given resource. * - * @param mixed $resource A resource + * @param mixed $resource A resource + * @param string $type The resource type * * @return Boolean true if this class supports the given resource, false otherwise */ - public function supports($resource) + public function supports($resource, $type = null) { return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION); } diff --git a/src/Symfony/Component/DependencyInjection/Resource/FileResource.php b/src/Symfony/Component/DependencyInjection/Resource/FileResource.php deleted file mode 100644 index 6ed6ddf513c5..000000000000 --- a/src/Symfony/Component/DependencyInjection/Resource/FileResource.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Resource; - -/** - * FileResource represents a resource stored on the filesystem. - * - * @author Fabien Potencier - */ -class FileResource implements ResourceInterface -{ - protected $resource; - - /** - * Constructor. - * - * @param string $resource The file path to the resource - */ - public function __construct($resource) - { - $this->resource = realpath($resource); - } - - /** - * Returns a string representation of the Resource. - * - * @return string A string representation of the Resource - */ - public function __toString() - { - return (string) $this->resource; - } - - /** - * Returns the resource tied to this Resource. - * - * @return mixed The resource - */ - public function getResource() - { - return $this->resource; - } - - /** - * Returns true if the resource has not been updated since the given timestamp. - * - * @param timestamp $timestamp The last time the resource was loaded - * - * @return Boolean true if the resource has not been updated, false otherwise - */ - public function isUptodate($timestamp) - { - if (!file_exists($this->resource)) { - return false; - } - - return filemtime($this->resource) < $timestamp; - } -} diff --git a/src/Symfony/Component/DependencyInjection/Resource/ResourceInterface.php b/src/Symfony/Component/DependencyInjection/Resource/ResourceInterface.php deleted file mode 100644 index e03a66835ae9..000000000000 --- a/src/Symfony/Component/DependencyInjection/Resource/ResourceInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Resource; - -/** - * ResourceInterface is the interface that must be implemented by all Resource classes. - * - * @author Fabien Potencier - */ -interface ResourceInterface -{ - /** - * Returns a string representation of the Resource. - * - * @return string A string representation of the Resource - */ - function __toString(); - - /** - * Returns true if the resource has not been updated since the given timestamp. - * - * @param int $timestamp The last time the resource was loaded - * - * @return Boolean true if the resource has not been updated, false otherwise - */ - function isUptodate($timestamp); - - /** - * Returns the resource tied to this Resource. - * - * @return mixed The resource - */ - function getResource(); -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/FileLocator.php b/src/Symfony/Component/HttpKernel/Config/FileLocator.php similarity index 75% rename from src/Symfony/Bundle/FrameworkBundle/Routing/FileLocator.php rename to src/Symfony/Component/HttpKernel/Config/FileLocator.php index 9b620b9e1c0a..bdd70d3838f5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/FileLocator.php +++ b/src/Symfony/Component/HttpKernel/Config/FileLocator.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Bundle\FrameworkBundle\Routing; +namespace Symfony\Component\HttpKernel\Config; -use Symfony\Component\Routing\Loader\FileLocator as BaseFileLocator; +use Symfony\Component\Config\FileLocator as BaseFileLocator; use Symfony\Component\HttpKernel\KernelInterface; /** @@ -39,12 +39,12 @@ public function __construct(KernelInterface $kernel, array $paths = array()) /** * {@inheritdoc} */ - public function locate($file, $currentPath = null) + public function locate($file, $currentPath = null, $first = true) { if ('@' === $file[0]) { - return $this->kernel->locateResource($file); + return $this->kernel->locateResource($file, $currentPath, $first); } - return parent::locate($file, $currentPath); + return parent::locate($file, $currentPath, $first); } } diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/Loader/FileLocator.php b/src/Symfony/Component/HttpKernel/DependencyInjection/Loader/FileLocator.php deleted file mode 100644 index d2a3616aacc9..000000000000 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/Loader/FileLocator.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpKernel\DependencyInjection\Loader; - -use Symfony\Component\DependencyInjection\Loader\FileLocator as BaseFileLocator; -use Symfony\Component\HttpKernel\KernelInterface; - -/** - * FileLocator uses the KernelInterface to locate resources in bundles. - * - * @author Fabien Potencier - */ -class FileLocator extends BaseFileLocator -{ - protected $kernel; - - /** - * Constructor. - * - * @param KernelInterface $kernel A KernelInterface instance - * @param string|array $paths A path or an array of paths where to look for resources - */ - public function __construct(KernelInterface $kernel, array $paths = array()) - { - $this->kernel = $kernel; - - parent::__construct($paths); - } - - /** - * {@inheritdoc} - */ - public function locate($file, $currentPath = null) - { - if ('@' === $file[0]) { - return $this->kernel->locateResource($file); - } - - return parent::locate($file, $currentPath); - } -} diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index a31cc064b96b..9151813d2123 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -15,9 +15,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Component\DependencyInjection\Loader\DelegatingLoader; -use Symfony\Component\DependencyInjection\Loader\LoaderInterface; -use Symfony\Component\DependencyInjection\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; @@ -26,7 +23,10 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface; -use Symfony\Component\HttpKernel\DependencyInjection\Loader\FileLocator; +use Symfony\Component\HttpKernel\Config\FileLocator; +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\DelegatingLoader; +use Symfony\Component\Config\ConfigCache; /** * The Kernel is the heart of the Symfony system. @@ -399,18 +399,16 @@ protected function initializeBundles() protected function initializeContainer() { $class = $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer'; - $location = $this->getCacheDir().'/'.$class; - $reload = $this->debug ? $this->needsReload($class, $location) : false; - + $cache = new ConfigCache($this->getCacheDir(), $class, $this->debug); $fresh = false; - if ($reload || !file_exists($location.'.php')) { + if (!$cache->isFresh()) { $container = $this->buildContainer(); - $this->dumpContainer($container, $class, $location.'.php'); + $this->dumpContainer($cache, $container, $class); $fresh = true; } - require_once $location.'.php'; + require_once $cache; $this->container = new $class(); $this->container->set('kernel', $this); @@ -454,23 +452,6 @@ protected function getEnvParameters() return $parameters; } - protected function needsReload($class, $location) - { - if (!file_exists($location.'.meta') || !file_exists($location.'.php')) { - return true; - } - - $meta = unserialize(file_get_contents($location.'.meta')); - $time = filemtime($location.'.php'); - foreach ($meta as $resource) { - if (!$resource->isUptodate($time)) { - return true; - } - } - - return false; - } - protected function buildContainer() { $parameterBag = new ParameterBag($this->getKernelParameters()); @@ -483,6 +464,7 @@ protected function buildContainer() $container->addObjectResource($bundle); } } + $container->addObjectResource($this); if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) { $container->merge($cont); @@ -492,7 +474,7 @@ protected function buildContainer() return $container; } - protected function dumpContainer(ContainerBuilder $container, $class, $file) + protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class) { foreach (array('cache', 'logs') as $name) { $dir = $container->getParameter(sprintf('kernel.%s_dir', $name)); @@ -511,14 +493,8 @@ protected function dumpContainer(ContainerBuilder $container, $class, $file) if (!$this->debug) { $content = self::stripComments($content); } - $this->writeCacheFile($file, $content); - if ($this->debug) { - $container->addObjectResource($this); - - // save the resources - $this->writeCacheFile($this->getCacheDir().'/'.$class.'.meta', serialize($container->getResources())); - } + $cache->write($content, $container->getResources()); } protected function getContainerLoader(ContainerInterface $container) @@ -565,18 +541,6 @@ static public function stripComments($source) return $output; } - protected function writeCacheFile($file, $content) - { - $tmpFile = tempnam(dirname($file), basename($file)); - if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { - chmod($file, 0644); - - return; - } - - throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file)); - } - public function serialize() { return serialize(array($this->environment, $this->debug)); diff --git a/src/Symfony/Component/HttpKernel/KernelInterface.php b/src/Symfony/Component/HttpKernel/KernelInterface.php index 7ca1928dd458..59d8f78b23e2 100644 --- a/src/Symfony/Component/HttpKernel/KernelInterface.php +++ b/src/Symfony/Component/HttpKernel/KernelInterface.php @@ -12,9 +12,9 @@ namespace Symfony\Component\HttpKernel; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\Loader\LoaderInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface; +use Symfony\Component\Config\Loader\LoaderInterface; /** * The Kernel is the heart of the Symfony system. diff --git a/src/Symfony/Component/HttpKernel/Resources/bin/packager.php b/src/Symfony/Component/HttpKernel/Resources/bin/packager.php index fda57302e3ae..b44064610d72 100644 --- a/src/Symfony/Component/HttpKernel/Resources/bin/packager.php +++ b/src/Symfony/Component/HttpKernel/Resources/bin/packager.php @@ -46,6 +46,8 @@ 'Symfony\\Component\\ClassLoader\\ClassCollectionLoader', 'Symfony\\Component\\ClassLoader\\UniversalClassLoader', 'Symfony\\Component\\ClassLoader\\MapFileClassLoader', + + 'Symfony\\Component\\Config\\ConfigCache', ), __DIR__.'/../..', 'bootstrap', false); if (file_exists(__DIR__.'/../../bootstrap_cache.php')) { diff --git a/src/Symfony/Component/HttpKernel/bootstrap.php b/src/Symfony/Component/HttpKernel/bootstrap.php index 41718f340e2b..58926619c850 100644 --- a/src/Symfony/Component/HttpKernel/bootstrap.php +++ b/src/Symfony/Component/HttpKernel/bootstrap.php @@ -440,9 +440,9 @@ protected function varToString($var) namespace Symfony\Component\HttpKernel { use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\Loader\LoaderInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface; +use Symfony\Component\Config\Loader\LoaderInterface; interface KernelInterface extends HttpKernelInterface, \Serializable { function registerRootDir(); @@ -470,9 +470,6 @@ function getLogDir(); use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Component\DependencyInjection\Loader\DelegatingLoader; -use Symfony\Component\DependencyInjection\Loader\LoaderInterface; -use Symfony\Component\DependencyInjection\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; @@ -481,7 +478,10 @@ function getLogDir(); use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface; -use Symfony\Component\HttpKernel\DependencyInjection\Loader\FileLocator; +use Symfony\Component\HttpKernel\Config\FileLocator; +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\DelegatingLoader; +use Symfony\Component\Config\ConfigCache; abstract class Kernel implements KernelInterface { protected $bundles; @@ -678,15 +678,14 @@ protected function initializeBundles() protected function initializeContainer() { $class = $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer'; - $location = $this->getCacheDir().'/'.$class; - $reload = $this->debug ? $this->needsReload($class, $location) : false; + $cache = new ConfigCache($this->getCacheDir(), $class, $this->debug); $fresh = false; - if ($reload || !file_exists($location.'.php')) { + if (!$cache->isFresh()) { $container = $this->buildContainer(); - $this->dumpContainer($container, $class, $location.'.php'); + $this->dumpContainer($cache, $container, $class); $fresh = true; } - require_once $location.'.php'; + require_once $cache; $this->container = new $class(); $this->container->set('kernel', $this); if ($fresh && 'cli' !== php_sapi_name()) { @@ -723,20 +722,6 @@ protected function getEnvParameters() } return $parameters; } - protected function needsReload($class, $location) - { - if (!file_exists($location.'.meta') || !file_exists($location.'.php')) { - return true; - } - $meta = unserialize(file_get_contents($location.'.meta')); - $time = filemtime($location.'.php'); - foreach ($meta as $resource) { - if (!$resource->isUptodate($time)) { - return true; - } - } - return false; - } protected function buildContainer() { $parameterBag = new ParameterBag($this->getKernelParameters()); @@ -747,13 +732,14 @@ protected function buildContainer() $container->addObjectResource($bundle); } } + $container->addObjectResource($this); if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) { $container->merge($cont); } $container->compile(); return $container; } - protected function dumpContainer(ContainerBuilder $container, $class, $file) + protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class) { foreach (array('cache', 'logs') as $name) { $dir = $container->getParameter(sprintf('kernel.%s_dir', $name)); @@ -770,11 +756,7 @@ protected function dumpContainer(ContainerBuilder $container, $class, $file) if (!$this->debug) { $content = self::stripComments($content); } - $this->writeCacheFile($file, $content); - if ($this->debug) { - $container->addObjectResource($this); - $this->writeCacheFile($this->getCacheDir().'/'.$class.'.meta', serialize($container->getResources())); - } + $cache->write($content, $container->getResources()); } protected function getContainerLoader(ContainerInterface $container) { @@ -803,15 +785,6 @@ static public function stripComments($source) $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output); return $output; } - protected function writeCacheFile($file, $content) - { - $tmpFile = tempnam(dirname($file), basename($file)); - if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { - chmod($file, 0644); - return; - } - throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file)); - } public function serialize() { return serialize(array($this->environment, $this->debug)); @@ -1978,3 +1951,73 @@ public function loadClass($class) } } } +namespace Symfony\Component\Config +{ +class ConfigCache +{ + protected $debug; + protected $cacheDir; + protected $file; + public function __construct($cacheDir, $file, $debug) + { + $this->cacheDir = $cacheDir; + $this->file = $file; + $this->debug = (Boolean) $debug; + } + public function __toString() + { + return $this->cacheDir.'/'.$this->file.'.php'; + } + public function isFresh() + { + $file = $this->getCacheFile(); + if (!file_exists($file)) { + return false; + } + if (!$this->debug) { + return true; + } + $metadata = $this->getCacheFile('meta'); + if (!file_exists($metadata)) { + return false; + } + $time = filemtime($file); + $meta = unserialize(file_get_contents($metadata)); + foreach ($meta as $resource) { + if (!$resource->isFresh($time)) { + return false; + } + } + return true; + } + public function write($content, array $metadata = null) + { + $file = $this->getCacheFile(); + $dir = dirname($file); + if (!is_dir($dir)) { + if (false === @mkdir($dir, 0777, true)) { + throw new \RuntimeException(sprintf('Unable to create the %s directory', $dir)); + } + } elseif (!is_writable($dir)) { + throw new \RuntimeException(sprintf('Unable to write in the %s directory', $dir)); + } + $tmpFile = tempnam(dirname($file), basename($file)); + if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { + chmod($file, 0666); + } else { + throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $this->file)); + } + if (null !== $metadata && true === $this->debug) { + $file = $this->getCacheFile('meta'); + $tmpFile = tempnam(dirname($file), basename($file)); + if (false !== @file_put_contents($tmpFile, serialize($metadata)) && @rename($tmpFile, $file)) { + chmod($file, 0666); + } + } + } + protected function getCacheFile($extension = 'php') + { + return $this->cacheDir.'/'.$this->file.'.'.$extension; + } +} +} diff --git a/src/Symfony/Component/HttpKernel/bootstrap_cache.php b/src/Symfony/Component/HttpKernel/bootstrap_cache.php index 960d3cbab892..93359e08960a 100644 --- a/src/Symfony/Component/HttpKernel/bootstrap_cache.php +++ b/src/Symfony/Component/HttpKernel/bootstrap_cache.php @@ -2,9 +2,9 @@ namespace Symfony\Component\HttpKernel { use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\Loader\LoaderInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface; +use Symfony\Component\Config\Loader\LoaderInterface; interface KernelInterface extends HttpKernelInterface, \Serializable { function registerRootDir(); @@ -32,9 +32,6 @@ function getLogDir(); use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Component\DependencyInjection\Loader\DelegatingLoader; -use Symfony\Component\DependencyInjection\Loader\LoaderInterface; -use Symfony\Component\DependencyInjection\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; @@ -43,7 +40,10 @@ function getLogDir(); use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface; -use Symfony\Component\HttpKernel\DependencyInjection\Loader\FileLocator; +use Symfony\Component\HttpKernel\Config\FileLocator; +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\DelegatingLoader; +use Symfony\Component\Config\ConfigCache; abstract class Kernel implements KernelInterface { protected $bundles; @@ -240,15 +240,14 @@ protected function initializeBundles() protected function initializeContainer() { $class = $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer'; - $location = $this->getCacheDir().'/'.$class; - $reload = $this->debug ? $this->needsReload($class, $location) : false; + $cache = new ConfigCache($this->getCacheDir(), $class, $this->debug); $fresh = false; - if ($reload || !file_exists($location.'.php')) { + if (!$cache->isFresh()) { $container = $this->buildContainer(); - $this->dumpContainer($container, $class, $location.'.php'); + $this->dumpContainer($cache, $container, $class); $fresh = true; } - require_once $location.'.php'; + require_once $cache; $this->container = new $class(); $this->container->set('kernel', $this); if ($fresh && 'cli' !== php_sapi_name()) { @@ -285,20 +284,6 @@ protected function getEnvParameters() } return $parameters; } - protected function needsReload($class, $location) - { - if (!file_exists($location.'.meta') || !file_exists($location.'.php')) { - return true; - } - $meta = unserialize(file_get_contents($location.'.meta')); - $time = filemtime($location.'.php'); - foreach ($meta as $resource) { - if (!$resource->isUptodate($time)) { - return true; - } - } - return false; - } protected function buildContainer() { $parameterBag = new ParameterBag($this->getKernelParameters()); @@ -309,13 +294,14 @@ protected function buildContainer() $container->addObjectResource($bundle); } } + $container->addObjectResource($this); if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) { $container->merge($cont); } $container->compile(); return $container; } - protected function dumpContainer(ContainerBuilder $container, $class, $file) + protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class) { foreach (array('cache', 'logs') as $name) { $dir = $container->getParameter(sprintf('kernel.%s_dir', $name)); @@ -332,11 +318,7 @@ protected function dumpContainer(ContainerBuilder $container, $class, $file) if (!$this->debug) { $content = self::stripComments($content); } - $this->writeCacheFile($file, $content); - if ($this->debug) { - $container->addObjectResource($this); - $this->writeCacheFile($this->getCacheDir().'/'.$class.'.meta', serialize($container->getResources())); - } + $cache->write($content, $container->getResources()); } protected function getContainerLoader(ContainerInterface $container) { @@ -365,15 +347,6 @@ static public function stripComments($source) $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output); return $output; } - protected function writeCacheFile($file, $content) - { - $tmpFile = tempnam(dirname($file), basename($file)); - if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { - chmod($file, 0644); - return; - } - throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file)); - } public function serialize() { return serialize(array($this->environment, $this->debug)); diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 3ba559d41f6c..1f3d7c56831b 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -13,10 +13,11 @@ use Doctrine\Common\Annotations\AnnotationReader; use Symfony\Component\Routing\Annotation\Route as RouteAnnotation; -use Symfony\Component\Routing\Loader\LoaderResolver; -use Symfony\Component\Routing\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\Config\Loader\LoaderResolver; /** * AnnotationClassLoader loads routing information from a PHP class and its methods. diff --git a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php index 71dd323306c8..01200be0f675 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php @@ -33,10 +33,7 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader */ public function load($path, $type = null) { - $dir = $this->locator->getAbsolutePath($path); - if (!file_exists($dir)) { - throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist (in: %s).', $dir, implode(', ', $this->paths))); - } + $dir = $this->locator->locate($path); $collection = new RouteCollection(); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { @@ -62,6 +59,12 @@ public function load($path, $type = null) */ public function supports($resource, $type = null) { - return is_string($resource) && is_dir($this->locator->getAbsolutePath($resource)) && (!$type || 'annotation' === $type); + try { + $path = $this->locator->locate($resource); + } catch (\Exception $e) { + return false; + } + + return is_string($resource) && is_dir($path) && (!$type || 'annotation' === $type); } } diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index e812459f5991..0dcbf0ca8d91 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -12,7 +12,9 @@ namespace Symfony\Component\Routing\Loader; use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Routing\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Config\Loader\FileLoader; +use Symfony\Component\Config\FileLocator; /** * AnnotationFileLoader loads routing information from annotations set @@ -53,10 +55,7 @@ public function __construct(FileLocator $locator, AnnotationClassLoader $loader, */ public function load($file, $type = null) { - $path = $this->locator->getAbsolutePath($file); - if (!file_exists($path)) { - throw new \InvalidArgumentException(sprintf('The file "%s" cannot be found (in: %s).', $file, implode(', ', $this->paths))); - } + $path = $this->locator->locate($file); $collection = new RouteCollection(); if ($class = $this->findClass($path)) { diff --git a/src/Symfony/Component/Routing/Loader/AnnotationGlobLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationGlobLoader.php index 7f168f1abdc8..b7ff9bac02e9 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationGlobLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationGlobLoader.php @@ -34,7 +34,7 @@ class AnnotationGlobLoader extends AnnotationDirectoryLoader public function load($glob, $type = null) { $collection = new RouteCollection(); - foreach ($this->locator->getAbsolutePaths($glob) as $path) { + foreach ($this->getAbsolutePaths($glob) as $path) { $collection->addCollection(parent::load($path, $type)); } diff --git a/src/Symfony/Component/Routing/Loader/ClosureLoader.php b/src/Symfony/Component/Routing/Loader/ClosureLoader.php index e86470b2427b..c00ace1a96c7 100644 --- a/src/Symfony/Component/Routing/Loader/ClosureLoader.php +++ b/src/Symfony/Component/Routing/Loader/ClosureLoader.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Routing\Loader; +use Symfony\Component\Config\Loader\Loader; + /** * ClosureLoader loads routes from a PHP closure. * diff --git a/src/Symfony/Component/Routing/Loader/FileLoader.php b/src/Symfony/Component/Routing/Loader/FileLoader.php deleted file mode 100644 index 69e98f0e9440..000000000000 --- a/src/Symfony/Component/Routing/Loader/FileLoader.php +++ /dev/null @@ -1,56 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Routing\Loader; - -use Symfony\Component\Routing\RouteCollection; - -/** - * FileLoader is the abstract class used by all built-in loaders that are file based. - * - * @author Fabien Potencier - */ -abstract class FileLoader extends Loader -{ - protected $locator; - protected $currentDir; - - public function __construct(FileLocator $locator) - { - $this->locator = $locator; - } - - public function getLocator() - { - return $this->locator; - } - - /** - * Adds routes from a resource. - * - * @param mixed $resource A Resource - * @param string $type The resource type - * - * @return RouteCollection A RouteCollection instance - * - * @throws \InvalidArgumentException When resource is expected to be a file and cannot be found - */ - public function import($resource, $type = null) - { - $loader = $this->resolve($resource, $type); - - if ($loader instanceof FileLoader && null !== $this->currentDir) { - $resource = $this->locator->locate($resource, $this->currentDir); - } - - return $loader->load($resource, $type); - } -} diff --git a/src/Symfony/Component/Routing/Loader/LoaderResolver.php b/src/Symfony/Component/Routing/Loader/LoaderResolver.php deleted file mode 100644 index 1411e9882aa6..000000000000 --- a/src/Symfony/Component/Routing/Loader/LoaderResolver.php +++ /dev/null @@ -1,75 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Routing\Loader; - -/** - * LoaderResolver selects a loader for a given resource. - * - * @author Fabien Potencier - */ -class LoaderResolver implements LoaderResolverInterface -{ - protected $loaders; - - /** - * Constructor. - * - * @param array $loaders An array of LoaderInterface instances to add - */ - public function __construct(array $loaders = array()) - { - $this->loaders = array(); - foreach ($loaders as $loader) { - $this->addLoader($loader); - } - } - - /** - * Returns a loader able to load the resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return LoaderInterface|false A LoaderInterface instance supporting the resource if one exists, false otherwise - */ - public function resolve($resource, $type = null) - { - foreach ($this->loaders as $loader) { - if ($loader->supports($resource, $type)) { - return $loader; - } - } - - return false; - } - - /** - * Adds a loader. - * - * @param LoaderInterface $loader A LoaderInterface instance - */ - public function addLoader(LoaderInterface $loader) - { - $this->loaders[] = $loader; - $loader->setResolver($this); - } - - /** - * Returns the registered loaders. - * - * @return array An array of LoaderInterface instances - */ - public function getLoaders() - { - return $this->loaders; - } -} diff --git a/src/Symfony/Component/Routing/Loader/LoaderResolverInterface.php b/src/Symfony/Component/Routing/Loader/LoaderResolverInterface.php deleted file mode 100644 index dea15ca47eba..000000000000 --- a/src/Symfony/Component/Routing/Loader/LoaderResolverInterface.php +++ /dev/null @@ -1,30 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Routing\Loader; - -/** - * LoaderResolverInterface selects a loader for a given resource. - * - * @author Fabien Potencier - */ -interface LoaderResolverInterface -{ - /** - * Returns a loader able to load the resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return LoaderInterface|false A LoaderInterface instance supporting the resource if one exists, false otherwise - */ - function resolve($resource, $type = null); -} diff --git a/src/Symfony/Component/Routing/Loader/PhpFileLoader.php b/src/Symfony/Component/Routing/Loader/PhpFileLoader.php index 3be9000d9c5f..906a79fda730 100644 --- a/src/Symfony/Component/Routing/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/PhpFileLoader.php @@ -11,7 +11,8 @@ namespace Symfony\Component\Routing\Loader; -use Symfony\Component\Routing\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Config\Loader\FileLoader; /** * PhpFileLoader loads routes from a PHP file. diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index 837f01d5b2b0..9d6b7a94d778 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -13,7 +13,8 @@ use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; -use Symfony\Component\Routing\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Config\Loader\FileLoader; /** * XmlFileLoader loads XML routing files. diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index cb39b06aff6b..c6cd045c3ea9 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -13,8 +13,9 @@ use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; -use Symfony\Component\Routing\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Yaml\Yaml; +use Symfony\Component\Config\Loader\FileLoader; /** * YamlFileLoader loads Yaml routing files. diff --git a/src/Symfony/Component/Routing/RouteCollection.php b/src/Symfony/Component/Routing/RouteCollection.php index 98d579386247..e54766f8d108 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Routing; -use Symfony\Component\Routing\Resource\ResourceInterface; +use Symfony\Component\Config\Resource\ResourceInterface; /** * A RouteCollection represents a set of Route instances. diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 1a39019abd79..3a98aaa00d1e 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -11,7 +11,8 @@ namespace Symfony\Component\Routing; -use Symfony\Component\Routing\Loader\LoaderInterface; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\Config\ConfigCache; /** * The Router class is an example of the integration of all pieces of the @@ -144,7 +145,8 @@ public function getMatcher() } $class = $this->options['matcher_cache_class']; - if ($this->needsReload($class)) { + $cache = new ConfigCache($this->options['cache_dir'], $class, $this->options['debug']); + if (!$cache->isFresh($class)) { $dumper = new $this->options['matcher_dumper_class']($this->getRouteCollection()); $options = array( @@ -152,10 +154,10 @@ public function getMatcher() 'base_class' => $this->options['matcher_base_class'], ); - $this->updateCache($class, $dumper->dump($options)); + $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources()); } - require_once $this->getCacheFile($class); + require_once $cache; return $this->matcher = new $class($this->context, $this->defaults); } @@ -176,7 +178,8 @@ public function getGenerator() } $class = $this->options['generator_cache_class']; - if ($this->needsReload($class)) { + $cache = new ConfigCache($this->options['cache_dir'], $class, $this->options['debug']); + if (!$cache->isFresh($class)) { $dumper = new $this->options['generator_dumper_class']($this->getRouteCollection()); $options = array( @@ -184,67 +187,11 @@ public function getGenerator() 'base_class' => $this->options['generator_base_class'], ); - $this->updateCache($class, $dumper->dump($options)); + $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources()); } - require_once $this->getCacheFile($class); + require_once $cache; return $this->generator = new $class($this->context, $this->defaults); } - - protected function updateCache($class, $dump) - { - $this->writeCacheFile($this->getCacheFile($class), $dump); - - if ($this->options['debug']) { - $this->writeCacheFile($this->getCacheFile($class, 'meta'), serialize($this->getRouteCollection()->getResources())); - } - } - - protected function needsReload($class) - { - $file = $this->getCacheFile($class); - if (!file_exists($file)) { - return true; - } - - if (!$this->options['debug']) { - return false; - } - - $metadata = $this->getCacheFile($class, 'meta'); - if (!file_exists($metadata)) { - return true; - } - - $time = filemtime($file); - $meta = unserialize(file_get_contents($metadata)); - foreach ($meta as $resource) { - if (!$resource->isUptodate($time)) { - return true; - } - } - - return false; - } - - protected function getCacheFile($class, $extension = 'php') - { - return $this->options['cache_dir'].'/'.$class.'.'.$extension; - } - - /** - * @throws \RuntimeException When cache file can't be wrote - */ - protected function writeCacheFile($file, $content) - { - $tmpFile = tempnam(dirname($file), basename($file)); - if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { - chmod($file, 0644); - - return; - } - - throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file)); - } } diff --git a/src/Symfony/Component/Translation/Loader/CsvFileLoader.php b/src/Symfony/Component/Translation/Loader/CsvFileLoader.php index 666cebd3a31f..efa2e466faba 100644 --- a/src/Symfony/Component/Translation/Loader/CsvFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/CsvFileLoader.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Translation\Loader; -use Symfony\Component\Translation\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; /** * CsvFileLoader loads translations from CSV files. diff --git a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php index 01c9f0023997..ff60acb538b9 100644 --- a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Translation\Loader; -use Symfony\Component\Translation\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; /** * PhpFileLoader loads translations from PHP files returning an array of translations. diff --git a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php index afd8762e6818..c46f1a73994f 100644 --- a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Translation\Loader; use Symfony\Component\Translation\MessageCatalogue; -use Symfony\Component\Translation\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; /** * XliffFileLoader loads translations from XLIFF files. diff --git a/src/Symfony/Component/Translation/Loader/YamlFileLoader.php b/src/Symfony/Component/Translation/Loader/YamlFileLoader.php index 248b293fa2b5..9eecff5146b5 100755 --- a/src/Symfony/Component/Translation/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/YamlFileLoader.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Translation\Loader; -use Symfony\Component\Translation\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Yaml\Yaml; /** diff --git a/src/Symfony/Component/Translation/MessageCatalogue.php b/src/Symfony/Component/Translation/MessageCatalogue.php index 6b7d32105267..9c69c32b7aef 100644 --- a/src/Symfony/Component/Translation/MessageCatalogue.php +++ b/src/Symfony/Component/Translation/MessageCatalogue.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Translation; -use Symfony\Component\Translation\Resource\ResourceInterface; +use Symfony\Component\Config\Resource\ResourceInterface; /** * MessageCatalogue. diff --git a/src/Symfony/Component/Translation/MessageCatalogueInterface.php b/src/Symfony/Component/Translation/MessageCatalogueInterface.php index 85d6e1f63101..56e4ec44cdc4 100644 --- a/src/Symfony/Component/Translation/MessageCatalogueInterface.php +++ b/src/Symfony/Component/Translation/MessageCatalogueInterface.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Translation; -use Symfony\Component\Translation\Resource\ResourceInterface; +use Symfony\Component\Config\Resource\ResourceInterface; /** * MessageCatalogueInterface. diff --git a/src/Symfony/Component/Translation/Resource/FileResource.php b/src/Symfony/Component/Translation/Resource/FileResource.php deleted file mode 100644 index fbe60ab401b7..000000000000 --- a/src/Symfony/Component/Translation/Resource/FileResource.php +++ /dev/null @@ -1,60 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Translation\Resource; - -/** - * FileResource represents a resource stored on the filesystem. - * - * @author Fabien Potencier - */ -class FileResource implements ResourceInterface -{ - protected $resource; - - /** - * Constructor. - * - * @param string $resource The file path to the resource - */ - public function __construct($resource) - { - if (!file_exists($resource)) { - throw new \InvalidArgumentException(sprintf('Resource "%s" does not exist.', $resource)); - } - - $this->resource = realpath($resource); - } - - /** - * {@inheritdoc} - */ - public function __toString() - { - return (string) $this->resource; - } - - /** - * {@inheritdoc} - */ - public function getResource() - { - return $this->resource; - } - - /** - * {@inheritdoc} - */ - public function isUptodate($timestamp) - { - return filemtime($this->resource) < $timestamp; - } -} diff --git a/src/Symfony/Component/Translation/Resource/ResourceInterface.php b/src/Symfony/Component/Translation/Resource/ResourceInterface.php deleted file mode 100644 index 11d876bac94d..000000000000 --- a/src/Symfony/Component/Translation/Resource/ResourceInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Translation\Resource; - -/** - * ResourceInterface is the interface that must be implemented by all Resource classes. - * - * @author Fabien Potencier - */ -interface ResourceInterface -{ - /** - * Returns a string representation of the Resource. - * - * @return string A string representation of the Resource - */ - function __toString(); - - /** - * Returns true if the resource has not been updated since the given timestamp. - * - * @param int $timestamp The last time the resource was loaded - * - * @return Boolean true if the resource has not been updated, false otherwise - */ - function isUptodate($timestamp); - - /** - * Returns the resource tied to this Resource. - * - * @return mixed The resource - */ - function getResource(); -} diff --git a/tests/Symfony/Tests/Component/Config/FileLocatorTest.php b/tests/Symfony/Tests/Component/Config/FileLocatorTest.php new file mode 100644 index 000000000000..641401250b19 --- /dev/null +++ b/tests/Symfony/Tests/Component/Config/FileLocatorTest.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\Config; + +use Symfony\Component\Config\FileLocator; + +class FileLocatorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getIsAbsolutePathTests + */ + public function testIsAbsolutePath($path) + { + $loader = new FileLocator(array()); + $r = new \ReflectionObject($loader); + $m = $r->getMethod('isAbsolutePath'); + $m->setAccessible(true); + + $this->assertTrue($m->invoke($loader, $path), '->isAbsolutePath() returns true for an absolute path'); + } + + public function getIsAbsolutePathTests() + { + return array( + array('/foo.xml'), + array('c:\\\\foo.xml'), + array('c:/foo.xml'), + array('\\server\\foo.xml'), + ); + } + + public function testLocate() + { + $loader = new FileLocator(array(__DIR__.'/Fixtures')); + + $this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'FileLocatorTest.php', $loader->locate('FileLocatorTest.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in the current path'); + + $this->assertEquals(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', $loader->locate('foo.xml', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor'); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testLocateThrowsAnExceptionIfTheFileDoesNotExists() + { + $loader = new FileLocator(array(__DIR__.'/Fixtures')); + + $loader->locate('foobar.xml', __DIR__); + } +} diff --git a/tests/Symfony/Tests/Component/Config/Fixtures/foo.xml b/tests/Symfony/Tests/Component/Config/Fixtures/foo.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/Symfony/Tests/Component/Config/Loader/DelegatingLoaderTest.php b/tests/Symfony/Tests/Component/Config/Loader/DelegatingLoaderTest.php new file mode 100644 index 000000000000..f6679920d007 --- /dev/null +++ b/tests/Symfony/Tests/Component/Config/Loader/DelegatingLoaderTest.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\Config\Loader; + +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\DelegatingLoader; +use Symfony\Component\Config\Loader\XmlFileLoader; +use Symfony\Component\Config\Loader\ClosureLoader; +use Symfony\Component\Config\RouteCollection; +use Symfony\Component\Config\Route; + +class DelegatingLoaderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers Symfony\Component\Config\Loader\DelegatingLoader::__construct + */ + public function testConstructor() + { + $loader = new DelegatingLoader($resolver = new LoaderResolver()); + $this->assertTrue(true, '__construct() takes a loader resolver as its first argument'); + } + + /** + * @covers Symfony\Component\Config\Loader\DelegatingLoader::getResolver + * @covers Symfony\Component\Config\Loader\DelegatingLoader::setResolver + */ + public function testGetSetResolver() + { + $resolver = new LoaderResolver(); + $loader = new DelegatingLoader($resolver); + $this->assertSame($resolver, $loader->getResolver(), '->getResolver() gets the resolver loader'); + $loader->setResolver($resolver = new LoaderResolver()); + $this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader'); + } + + /** + * @covers Symfony\Component\Config\Loader\DelegatingLoader::supports + */ + public function testSupports() + { + $loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); + $loader1->expects($this->once())->method('supports')->will($this->returnValue(true)); + $loader = new DelegatingLoader(new LoaderResolver(array($loader1))); + $this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable'); + + $loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); + $loader1->expects($this->once())->method('supports')->will($this->returnValue(false)); + $loader = new DelegatingLoader(new LoaderResolver(array($loader1))); + $this->assertFalse($loader->supports('foo.foo'), '->supports() returns false if the resource is not loadable'); + } + + /** + * @covers Symfony\Component\Config\Loader\DelegatingLoader::load + */ + public function testLoad() + { + $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); + $loader->expects($this->once())->method('supports')->will($this->returnValue(true)); + $loader->expects($this->once())->method('load'); + $resolver = new LoaderResolver(array($loader)); + $loader = new DelegatingLoader($resolver); + + $loader->load('foo'); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testLoadThrowsAnExceptionIfTheResourceCannotBeLoaded() + { + $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); + $loader->expects($this->once())->method('supports')->will($this->returnValue(false)); + $resolver = new LoaderResolver(array($loader)); + $loader = new DelegatingLoader($resolver); + + $loader->load('foo'); + } +} diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderResolverTest.php b/tests/Symfony/Tests/Component/Config/Loader/LoaderResolverTest.php similarity index 53% rename from tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderResolverTest.php rename to tests/Symfony/Tests/Component/Config/Loader/LoaderResolverTest.php index 4953551e0c10..a05a9e1f9e16 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderResolverTest.php +++ b/tests/Symfony/Tests/Component/Config/Loader/LoaderResolverTest.php @@ -9,47 +9,47 @@ * file that was distributed with this source code. */ -namespace Symfony\Tests\Component\DependencyInjection\Loader; +namespace Symfony\Tests\Component\Config\Loader; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\LoaderResolver; -use Symfony\Component\DependencyInjection\Loader\ClosureLoader; +use Symfony\Component\Config\Loader\LoaderResolver; class LoaderResolverTest extends \PHPUnit_Framework_TestCase { /** - * @covers Symfony\Component\DependencyInjection\Loader\LoaderResolver::__construct + * @covers Symfony\Component\Config\Loader\LoaderResolver::__construct */ public function testConstructor() { $resolver = new LoaderResolver(array( - $loader = new ClosureLoader(new ContainerBuilder()), + $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'), )); $this->assertEquals(array($loader), $resolver->getLoaders(), '__construct() takes an array of loaders as its first argument'); } /** - * @covers Symfony\Component\DependencyInjection\Loader\LoaderResolver::resolve + * @covers Symfony\Component\Config\Loader\LoaderResolver::resolve */ public function testResolve() { - $resolver = new LoaderResolver(array( - $loader = new ClosureLoader(new ContainerBuilder()), - )); - + $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); + $resolver = new LoaderResolver(array($loader)); $this->assertFalse($resolver->resolve('foo.foo'), '->resolve() returns false if no loader is able to load the resource'); + + $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); + $loader->expects($this->once())->method('supports')->will($this->returnValue(true)); + $resolver = new LoaderResolver(array($loader)); $this->assertEquals($loader, $resolver->resolve(function () {}), '->resolve() returns the loader for the given resource'); } /** - * @covers Symfony\Component\DependencyInjection\Loader\LoaderResolver::getLoaders - * @covers Symfony\Component\DependencyInjection\Loader\LoaderResolver::addLoader + * @covers Symfony\Component\Config\Loader\LoaderResolver::getLoaders + * @covers Symfony\Component\Config\Loader\LoaderResolver::addLoader */ public function testLoaders() { $resolver = new LoaderResolver(); - $resolver->addLoader($loader = new ClosureLoader(new ContainerBuilder())); + $resolver->addLoader($loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface')); $this->assertEquals(array($loader), $resolver->getLoaders(), 'addLoader() adds a loader'); } diff --git a/tests/Symfony/Tests/Component/Routing/Loader/LoaderTest.php b/tests/Symfony/Tests/Component/Config/Loader/LoaderTest.php similarity index 60% rename from tests/Symfony/Tests/Component/Routing/Loader/LoaderTest.php rename to tests/Symfony/Tests/Component/Config/Loader/LoaderTest.php index a9cc40435ebb..9c7458d246cf 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/LoaderTest.php +++ b/tests/Symfony/Tests/Component/Config/Loader/LoaderTest.php @@ -9,17 +9,16 @@ * file that was distributed with this source code. */ -namespace Symfony\Tests\Component\Routing\Loader; +namespace Symfony\Tests\Component\Config\Loader; -use Symfony\Component\Routing\Loader\LoaderResolver; -use Symfony\Component\Routing\Loader\Loader; -use Symfony\Component\Routing\Loader\XmlFileLoader; +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\Loader; class LoaderTest extends \PHPUnit_Framework_TestCase { /** - * @covers Symfony\Component\Routing\Loader\Loader::getResolver - * @covers Symfony\Component\Routing\Loader\Loader::setResolver + * @covers Symfony\Component\Config\Loader\Loader::getResolver + * @covers Symfony\Component\Config\Loader\Loader::setResolver */ public function testGetSetResolver() { @@ -30,19 +29,24 @@ public function testGetSetResolver() } /** - * @covers Symfony\Component\Routing\Loader\Loader::resolve + * @covers Symfony\Component\Config\Loader\Loader::resolve */ public function testResolve() { - $resolver = new LoaderResolver(array( - $ini = new XmlFileLoader($this->getMock('Symfony\Component\Routing\Loader\FileLocator')), - )); + $loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); + $loader1->expects($this->once())->method('supports')->will($this->returnValue(true)); + $resolver = new LoaderResolver(array($loader1)); $loader = new ProjectLoader1(); $loader->setResolver($resolver); - $this->assertSame($ini, $loader->resolve('foo.xml'), '->resolve() finds a loader'); $this->assertSame($loader, $loader->resolve('foo.foo'), '->resolve() finds a loader'); + $this->assertSame($loader1, $loader->resolve('foo.xml'), '->resolve() finds a loader'); + $loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); + $loader1->expects($this->once())->method('supports')->will($this->returnValue(false)); + $resolver = new LoaderResolver(array($loader1)); + $loader = new ProjectLoader1(); + $loader->setResolver($resolver); try { $loader->resolve(new \stdClass()); $this->fail('->resolve() throws an \InvalidArgumentException if the resource cannot be loaded'); diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Resource/FileResourceTest.php b/tests/Symfony/Tests/Component/Config/Resource/FileResourceTest.php similarity index 56% rename from tests/Symfony/Tests/Component/DependencyInjection/Resource/FileResourceTest.php rename to tests/Symfony/Tests/Component/Config/Resource/FileResourceTest.php index 947bcdc337e9..b4b39b9357d8 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Resource/FileResourceTest.php +++ b/tests/Symfony/Tests/Component/Config/Resource/FileResourceTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Tests\Component\DependencyInjection\Resource; +namespace Symfony\Tests\Component\Config\Resource; -use Symfony\Component\DependencyInjection\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; class FileResourceTest extends \PHPUnit_Framework_TestCase { @@ -31,7 +31,7 @@ protected function tearDown() } /** - * @covers Symfony\Component\DependencyInjection\Resource\FileResource::getResource + * @covers Symfony\Component\Config\Resource\FileResource::getResource */ public function testGetResource() { @@ -39,14 +39,14 @@ public function testGetResource() } /** - * @covers Symfony\Component\DependencyInjection\Resource\FileResource::isUptodate + * @covers Symfony\Component\Config\Resource\FileResource::isFresh */ - public function testIsUptodate() + public function testIsFresh() { - $this->assertTrue($this->resource->isUptodate(time() + 10), '->isUptodate() returns true if the resource has not changed'); - $this->assertFalse($this->resource->isUptodate(time() - 86400), '->isUptodate() returns false if the resource has been updated'); + $this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed'); + $this->assertFalse($this->resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated'); $resource = new FileResource('/____foo/foobar'.rand(1, 999999)); - $this->assertFalse($resource->isUptodate(time()), '->isUptodate() returns false if the resource does not exist'); + $this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist'); } } diff --git a/tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php index 4a14e4066436..e4c2d2619de2 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php @@ -18,7 +18,7 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Component\DependencyInjection\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; require_once __DIR__.'/Fixtures/includes/classes.php'; require_once __DIR__.'/Fixtures/includes/ProjectExtension.php'; diff --git a/tests/Symfony/Tests/Component/DependencyInjection/CrossCheckTest.php b/tests/Symfony/Tests/Component/DependencyInjection/CrossCheckTest.php index a6e73d8351f2..48279c8c2b87 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/CrossCheckTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/CrossCheckTest.php @@ -12,7 +12,7 @@ namespace Symfony\Tests\Component\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\Config\FileLocator; class CrossCheckTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/DelegatingLoaderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/DelegatingLoaderTest.php deleted file mode 100644 index 026b92935520..000000000000 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/DelegatingLoaderTest.php +++ /dev/null @@ -1,86 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Tests\Component\DependencyInjection\Loader; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\LoaderResolver; -use Symfony\Component\DependencyInjection\Loader\DelegatingLoader; -use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\DependencyInjection\Loader\ClosureLoader; -use Symfony\Component\DependencyInjection\Loader\FileLocator; - -class DelegatingLoaderTest extends \PHPUnit_Framework_TestCase -{ - /** - * @covers Symfony\Component\DependencyInjection\Loader\DelegatingLoader::__construct - */ - public function testConstructor() - { - $resolver = new LoaderResolver(); - $loader = new DelegatingLoader($resolver); - $this->assertTrue(true, '__construct() takes a loader resolver as its first argument'); - } - - /** - * @covers Symfony\Component\DependencyInjection\Loader\DelegatingLoader::getResolver - * @covers Symfony\Component\DependencyInjection\Loader\DelegatingLoader::setResolver - */ - public function testGetSetResolver() - { - $resolver = new LoaderResolver(); - $loader = new DelegatingLoader($resolver); - $this->assertSame($resolver, $loader->getResolver(), '->getResolver() gets the resolver loader'); - $loader->setResolver($resolver = new LoaderResolver()); - $this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader'); - } - - /** - * @covers Symfony\Component\DependencyInjection\Loader\DelegatingLoader::supports - */ - public function testSupports() - { - $container = new ContainerBuilder(); - $resolver = new LoaderResolver(array( - $ini = new IniFileLoader($container, new FileLocator(array())), - )); - $loader = new DelegatingLoader($resolver); - - $this->assertTrue($loader->supports('foo.ini'), '->supports() returns true if the resource is loadable'); - $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); - } - - /** - * @covers Symfony\Component\DependencyInjection\Loader\DelegatingLoader::load - */ - public function testLoad() - { - $container = new ContainerBuilder(); - $resolver = new LoaderResolver(array( - new ClosureLoader($container), - )); - $loader = new DelegatingLoader($resolver); - - $loader->load(function ($container) - { - $container->setParameter('foo', 'foo'); - }); - - $this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a resource using the loaders from the resolver'); - - try { - $loader->load('foo.foo'); - $this->fail('->load() throws an \InvalidArgumentException if the resource cannot be loaded'); - } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an \InvalidArgumentException if the resource cannot be loaded'); - } - } -} diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/FileLocatorTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/FileLocatorTest.php deleted file mode 100644 index 18c567bd6241..000000000000 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/FileLocatorTest.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Tests\Component\DependencyInjection\Loader; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\FileLocator; - -class FileLocatorTest extends \PHPUnit_Framework_TestCase -{ - /** - * @covers Symfony\Component\DependencyInjection\Loader\FileLocator::GetAbsolutePath - */ - public function testGetAbsolutePath() - { - $loader = new FileLocator(array(__DIR__.'/../Fixtures/containers')); - $this->assertEquals('/foo.xml', $loader->getAbsolutePath('/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path'); - $this->assertEquals('c:\\\\foo.xml', $loader->getAbsolutePath('c:\\\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path'); - $this->assertEquals('c:/foo.xml', $loader->getAbsolutePath('c:/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path'); - $this->assertEquals('\\server\\foo.xml', $loader->getAbsolutePath('\\server\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path'); - - $this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'FileLocatorTest.php', $loader->getAbsolutePath('FileLocatorTest.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in the current path'); - - $this->assertEquals(__DIR__.'/../Fixtures/containers'.DIRECTORY_SEPARATOR.'container10.php', $loader->getAbsolutePath('container10.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor'); - - $this->assertEquals('foo.xml', $loader->getAbsolutePath('foo.xml', __DIR__), '->getAbsolutePath() returns the path unmodified if it is unable to find it in the given paths'); - } -} diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/IniFileLoaderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/IniFileLoaderTest.php index ef45df5c3d06..df17e990e36a 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/IniFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/IniFileLoaderTest.php @@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\Config\FileLocator; class IniFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderTest.php deleted file mode 100644 index ec1f6d19507b..000000000000 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderTest.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Tests\Component\DependencyInjection\Loader; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\LoaderResolver; -use Symfony\Component\DependencyInjection\Loader\Loader; -use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\DependencyInjection\Loader\FileLocator; - -class LoaderTest extends \PHPUnit_Framework_TestCase -{ - /** - * @covers Symfony\Component\DependencyInjection\Loader\Loader::__construct - */ - public function testConstructor() - { - $loader = new ProjectLoader1(new ContainerBuilder()); - $this->assertTrue(true, '__construct() takes a container builder as its first argument'); - } - - /** - * @covers Symfony\Component\DependencyInjection\Loader\Loader::getResolver - * @covers Symfony\Component\DependencyInjection\Loader\Loader::setResolver - */ - public function testGetSetResolver() - { - $resolver = new LoaderResolver(); - $loader = new ProjectLoader1(new ContainerBuilder()); - $loader->setResolver($resolver); - $this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader'); - } - - /** - * @covers Symfony\Component\DependencyInjection\Loader\Loader::resolve - */ - public function testResolve() - { - $container = new ContainerBuilder(); - - $resolver = new LoaderResolver(array( - $ini = new IniFileLoader($container, new FileLocator(array())), - )); - $loader = new ProjectLoader1($container); - $loader->setResolver($resolver); - - $this->assertSame($ini, $loader->resolve('foo.ini'), '->resolve() finds a loader'); - $this->assertSame($loader, $loader->resolve('foo.foo'), '->resolve() finds a loader'); - - try { - $loader->resolve(new \stdClass()); - $this->fail('->resolve() throws an \InvalidArgumentException if the resource cannot be loaded'); - } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->resolve() throws an \InvalidArgumentException if the resource cannot be loaded'); - } - } -} - -class ProjectLoader1 extends Loader -{ - public function load($resource) - { - } - - public function supports($resource) - { - return is_string($resource) && 'foo' === pathinfo($resource, PATHINFO_EXTENSION); - } -} diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/PhpFileLoaderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/PhpFileLoaderTest.php index 54e0069801db..115aa0b463bc 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/PhpFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/PhpFileLoaderTest.php @@ -16,8 +16,8 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Loader\Loader; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\DependencyInjection\Loader\LoaderResolver; -use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\FileLocator; class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/XmlFileLoaderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/XmlFileLoaderTest.php index 0ba99e32b124..816969849aa7 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/XmlFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/XmlFileLoaderTest.php @@ -20,8 +20,8 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\DependencyInjection\Loader\LoaderResolver; -use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\FileLocator; class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php index 8b0756eb57cf..851039cbe3b8 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php @@ -18,8 +18,8 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\DependencyInjection\Loader\LoaderResolver; -use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\FileLocator; class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index 18542f50f7a3..7833e8b24f50 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -14,9 +14,9 @@ use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Bundle\Bundle; -use Symfony\Component\DependencyInjection\Loader\LoaderInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Config\Loader\LoaderInterface; class KernelTest extends \PHPUnit_Framework_TestCase { @@ -303,130 +303,6 @@ public function testSerialize() $this->assertEquals($expected, $kernel->serialize()); } - /** - * @expectedException \InvalidArgumentException - */ - public function testLocateResourceThrowsExceptionWhenNameIsNotValid() - { - $this->getKernelForInvalidLocateResource()->locateResource('foo'); - } - - /** - * @expectedException \RuntimeException - */ - public function testLocateResourceThrowsExceptionWhenNameIsUnsafe() - { - $this->getKernelForInvalidLocateResource()->locateResource('@foo/../bar'); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testLocateResourceThrowsExceptionWhenBundleDoesNotExist() - { - $this->getKernelForInvalidLocateResource()->locateResource('@foo/config/routing.xml'); - } - - public function testLocateResourceReturnsTheFirstThatMatches() - { - $kernel = $this->getKernel(); - $kernel - ->expects($this->once()) - ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) - ; - - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/foo.txt', $kernel->locateResource('@foo/foo.txt')); - } - - public function testLocateResourceReturnsTheFirstThatMatchesWithParent() - { - $parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1', null, 'ParentAABundle'); - $child = $this->getBundle(__DIR__.'/Fixtures/Bundle2', 'ParentAABundle', 'ChildAABundle'); - - $kernel = $this->getKernel(); - $kernel - ->expects($this->any()) - ->method('getBundle') - ->will($this->returnValue(array($child, $parent))) - ; - - $this->assertEquals(__DIR__.'/Fixtures/Bundle2/foo.txt', $kernel->locateResource('@foo/foo.txt')); - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/bar.txt', $kernel->locateResource('@foo/bar.txt')); - } - - public function testLocateResourceReturnsTheAllMatches() - { - $kernel = $this->getKernel(); - $kernel - ->expects($this->once()) - ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1'), $this->getBundle(__DIR__.'/Fixtures/Bundle2')))) - ; - - $this->assertEquals(array(__DIR__.'/Fixtures/Bundle1/foo.txt', __DIR__.'/Fixtures/Bundle2/foo.txt'), $kernel->locateResource('@foo/foo.txt', null, false)); - } - - public function testLocateResourceReturnsAllMatchesBis() - { - $kernel = $this->getKernel(); - $kernel - ->expects($this->once()) - ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1'), $this->getBundle(__DIR__.'/foobar')))) - ; - - $this->assertEquals(array(__DIR__.'/Fixtures/Bundle1/foo.txt'), $kernel->locateResource('@foo/foo.txt', null, false)); - } - - public function testLocateResourceIgnoresDirOnNonResource() - { - $kernel = $this->getKernel(); - $kernel - ->expects($this->once()) - ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) - ; - - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/foo.txt', $kernel->locateResource('@foo/foo.txt', __DIR__.'/Fixtures')); - } - - public function testLocateResourceReturnsTheDirOneForResources() - { - $kernel = $this->getKernel(); - - $this->assertEquals(__DIR__.'/Fixtures/foo/foo.txt', $kernel->locateResource('@foo/Resources/foo.txt', __DIR__.'/Fixtures')); - } - - public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes() - { - $kernel = $this->getKernel(); - $kernel - ->expects($this->once()) - ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) - ; - - $this->assertEquals(array(__DIR__.'/Fixtures/foo/foo.txt', __DIR__.'/Fixtures/Bundle1/Resources/foo.txt'), $kernel->locateResource('@foo/Resources/foo.txt', __DIR__.'/Fixtures', false)); - } - - public function testLocateResourceOnDirectories() - { - $kernel = $this->getKernel(); - - $this->assertEquals(__DIR__.'/Fixtures/foo/', $kernel->locateResource('@foo/Resources/', __DIR__.'/Fixtures')); - $this->assertEquals(__DIR__.'/Fixtures/foo/', $kernel->locateResource('@foo/Resources', __DIR__.'/Fixtures')); - - $kernel - ->expects($this->any()) - ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) - ; - - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/Resources/', $kernel->locateResource('@foo/Resources/')); - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/Resources/', $kernel->locateResource('@foo/Resources/')); - } - public function testInitializeBundles() { $parent = $this->getBundle(null, null, 'ParentABundle'); @@ -581,15 +457,6 @@ protected function getKernel() ->getMock() ; } - - protected function getKernelForInvalidLocateResource() - { - return $this - ->getMockBuilder('Symfony\Component\HttpKernel\Kernel') - ->disableOriginalConstructor() - ->getMockForAbstractClass() - ; - } } class KernelForTest extends Kernel diff --git a/tests/Symfony/Tests/Component/Routing/Loader/AnnotationClassLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/AnnotationClassLoaderTest.php index 0aec391cde73..dd5e2964464e 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/AnnotationClassLoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/AnnotationClassLoaderTest.php @@ -11,7 +11,7 @@ namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Routing\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\AnnotationClassLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/tests/Symfony/Tests/Component/Routing/Loader/AnnotationDirectoryLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/AnnotationDirectoryLoaderTest.php index 15a1f7b30e34..df476d54bb09 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/AnnotationDirectoryLoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/AnnotationDirectoryLoaderTest.php @@ -11,11 +11,11 @@ namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Routing\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Routing\Loader\FileLocator; +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\FileLocator; class AnnotationDirectoryLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/Routing/Loader/AnnotationFileLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/AnnotationFileLoaderTest.php index 49d1d9f7fa30..2efe084152a0 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/AnnotationFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/AnnotationFileLoaderTest.php @@ -11,7 +11,7 @@ namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Routing\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\AnnotationFileLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -27,7 +27,7 @@ public function testSupports() ->disableOriginalConstructor() ->getMockForAbstractClass(); - $loader = new AnnotationFileLoader($this->getMock('Symfony\Component\Routing\Loader\FileLocator'), $annotationClassLoader); + $loader = new AnnotationFileLoader($this->getMock('Symfony\Component\Config\FileLocator'), $annotationClassLoader); $fixture = __DIR__.'/../Fixtures/annotated.php'; diff --git a/tests/Symfony/Tests/Component/Routing/Loader/AnnotationGlobLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/AnnotationGlobLoaderTest.php index f242e7276869..182c01c2f9af 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/AnnotationGlobLoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/AnnotationGlobLoaderTest.php @@ -11,7 +11,7 @@ namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Routing\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\AnnotationGlobLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -27,7 +27,7 @@ public function testSupports() ->disableOriginalConstructor() ->getMockForAbstractClass(); - $loader = new AnnotationGlobLoader($this->getMock('Symfony\Component\Routing\Loader\FileLocator'), $annotationClassLoader); + $loader = new AnnotationGlobLoader($this->getMock('Symfony\Component\Config\FileLocator'), $annotationClassLoader); $this->assertTrue($loader->supports('*'), '->supports() returns true if the resource is loadable'); $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); diff --git a/tests/Symfony/Tests/Component/Routing/Loader/ClosureLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/ClosureLoaderTest.php index 8eee98ec98b6..8eb8cb1a721c 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/ClosureLoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/ClosureLoaderTest.php @@ -11,7 +11,7 @@ namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Routing\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\ClosureLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/tests/Symfony/Tests/Component/Routing/Loader/DelegatingLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/DelegatingLoaderTest.php deleted file mode 100644 index f97bbc1b878f..000000000000 --- a/tests/Symfony/Tests/Component/Routing/Loader/DelegatingLoaderTest.php +++ /dev/null @@ -1,89 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Tests\Component\Routing\Loader; - -use Symfony\Component\Routing\Loader\LoaderResolver; -use Symfony\Component\Routing\Loader\DelegatingLoader; -use Symfony\Component\Routing\Loader\XmlFileLoader; -use Symfony\Component\Routing\Loader\ClosureLoader; -use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Routing\Route; - -class DelegatingLoaderTest extends \PHPUnit_Framework_TestCase -{ - /** - * @covers Symfony\Component\Routing\Loader\DelegatingLoader::__construct - */ - public function testConstructor() - { - $resolver = new LoaderResolver(); - $loader = new DelegatingLoader($resolver); - $this->assertTrue(true, '__construct() takes a loader resolver as its first argument'); - } - - /** - * @covers Symfony\Component\Routing\Loader\DelegatingLoader::getResolver - * @covers Symfony\Component\Routing\Loader\DelegatingLoader::setResolver - */ - public function testGetSetResolver() - { - $resolver = new LoaderResolver(); - $loader = new DelegatingLoader($resolver); - $this->assertSame($resolver, $loader->getResolver(), '->getResolver() gets the resolver loader'); - $loader->setResolver($resolver = new LoaderResolver()); - $this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader'); - } - - /** - * @covers Symfony\Component\Routing\Loader\DelegatingLoader::supports - */ - public function testSupports() - { - $resolver = new LoaderResolver(array( - $ini = new XmlFileLoader($this->getMock('Symfony\Component\Routing\Loader\FileLocator')), - )); - $loader = new DelegatingLoader($resolver); - - $this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable'); - $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); - } - - /** - * @covers Symfony\Component\Routing\Loader\DelegatingLoader::load - */ - public function testLoad() - { - $resolver = new LoaderResolver(array( - new ClosureLoader(), - )); - $loader = new DelegatingLoader($resolver); - - $route = new Route('/'); - $routes = $loader->load(function () use ($route) - { - $routes = new RouteCollection(); - - $routes->add('foo', $route); - - return $routes; - }); - - $this->assertSame($route, $routes->get('foo'), '->load() loads a resource using the loaders from the resolver'); - - try { - $loader->load('foo.foo'); - $this->fail('->load() throws an \InvalidArgumentException if the resource cannot be loaded'); - } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an \InvalidArgumentException if the resource cannot be loaded'); - } - } -} diff --git a/tests/Symfony/Tests/Component/Routing/Loader/FileLocatorTest.php b/tests/Symfony/Tests/Component/Routing/Loader/FileLocatorTest.php deleted file mode 100644 index 655aadcdd7f4..000000000000 --- a/tests/Symfony/Tests/Component/Routing/Loader/FileLocatorTest.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Tests\Component\Routing\Loader; - -use Symfony\Component\Routing\Loader\FileLocator; - -class FileLocatorTest extends \PHPUnit_Framework_TestCase -{ - /** - * @covers Symfony\Component\Routing\Loader\FileLocator::GetAbsolutePath - * @covers Symfony\Component\Routing\Loader\FileLocator::isAbsolutePath - */ - public function testGetAbsolutePath() - { - $loader = new FileLocator(array(__DIR__.'/../Fixtures')); - $this->assertEquals('/foo.xml', $loader->getAbsolutePath('/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path'); - $this->assertEquals('c:\\\\foo.xml', $loader->getAbsolutePath('c:\\\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path'); - $this->assertEquals('c:/foo.xml', $loader->getAbsolutePath('c:/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path'); - $this->assertEquals('\\server\\foo.xml', $loader->getAbsolutePath('\\server\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path'); - - $this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'FileLocatorTest.php', $loader->getAbsolutePath('FileLocatorTest.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in the current path'); - - $this->assertEquals(__DIR__.'/../Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', $loader->getAbsolutePath('foo.xml', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor'); - - $this->assertEquals('foobar.xml', $loader->getAbsolutePath('foobar.xml', __DIR__), '->getAbsolutePath() returns the path unmodified if it is unable to find it in the given paths'); - } -} diff --git a/tests/Symfony/Tests/Component/Routing/Loader/LoaderResolverTest.php b/tests/Symfony/Tests/Component/Routing/Loader/LoaderResolverTest.php deleted file mode 100644 index fa44e984ab4c..000000000000 --- a/tests/Symfony/Tests/Component/Routing/Loader/LoaderResolverTest.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Tests\Component\Routing\Loader; - -use Symfony\Component\Routing\Loader\LoaderResolver; -use Symfony\Component\Routing\Loader\ClosureLoader; - -class LoaderResolverTest extends \PHPUnit_Framework_TestCase -{ - /** - * @covers Symfony\Component\Routing\Loader\LoaderResolver::__construct - */ - public function testConstructor() - { - $resolver = new LoaderResolver(array( - $loader = new ClosureLoader(), - )); - - $this->assertEquals(array($loader), $resolver->getLoaders(), '__construct() takes an array of loaders as its first argument'); - } - - /** - * @covers Symfony\Component\Routing\Loader\LoaderResolver::resolve - */ - public function testResolve() - { - $resolver = new LoaderResolver(array( - $loader = new ClosureLoader(), - )); - - $this->assertFalse($resolver->resolve('foo.foo'), '->resolve() returns false if no loader is able to load the resource'); - $this->assertEquals($loader, $resolver->resolve(function () {}), '->resolve() returns the loader for the given resource'); - } - - /** - * @covers Symfony\Component\Routing\Loader\LoaderResolver::getLoaders - * @covers Symfony\Component\Routing\Loader\LoaderResolver::addLoader - */ - public function testLoaders() - { - $resolver = new LoaderResolver(); - $resolver->addLoader($loader = new ClosureLoader()); - - $this->assertEquals(array($loader), $resolver->getLoaders(), 'addLoader() adds a loader'); - } -} diff --git a/tests/Symfony/Tests/Component/Routing/Loader/PhpFileLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/PhpFileLoaderTest.php index ba2f4b2c6061..8866c0404fe5 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/PhpFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/PhpFileLoaderTest.php @@ -11,7 +11,7 @@ namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Routing\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\PhpFileLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -23,7 +23,7 @@ class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase */ public function testSupports() { - $loader = new PhpFileLoader($this->getMock('Symfony\Component\Routing\Loader\FileLocator')); + $loader = new PhpFileLoader($this->getMock('Symfony\Component\Config\FileLocator')); $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable'); $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); diff --git a/tests/Symfony/Tests/Component/Routing/Loader/XmlFileLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/XmlFileLoaderTest.php index 55dfdde326b1..0a7670ebd026 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/XmlFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/XmlFileLoaderTest.php @@ -11,7 +11,7 @@ namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Routing\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\XmlFileLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -23,7 +23,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase */ public function testSupports() { - $loader = new XmlFileLoader($this->getMock('Symfony\Component\Routing\Loader\FileLocator')); + $loader = new XmlFileLoader($this->getMock('Symfony\Component\Config\FileLocator')); $this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable'); $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); diff --git a/tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php index 0bf758730c65..e636081de9dd 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php @@ -11,12 +11,12 @@ namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Routing\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\FileLocator; use Symfony\Component\Routing\Loader\YamlFileLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Routing\Resource\FileResource; -use Symfony\Component\Routing\Loader\FileLocator; +use Symfony\Component\Config\Resource\FileResource; class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase { @@ -25,7 +25,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase */ public function testSupports() { - $loader = new YamlFileLoader($this->getMock('Symfony\Component\Routing\Loader\FileLocator')); + $loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator')); $this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable'); $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); diff --git a/tests/Symfony/Tests/Component/Routing/Resource/FileResourceTest.php b/tests/Symfony/Tests/Component/Routing/Resource/FileResourceTest.php deleted file mode 100644 index 009ddf46ac1a..000000000000 --- a/tests/Symfony/Tests/Component/Routing/Resource/FileResourceTest.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Tests\Component\Routing\Resource; - -use Symfony\Component\Routing\Resource\FileResource; - -class FileResourceTest extends \PHPUnit_Framework_TestCase -{ - public function testGetResource() - { - $file = sys_get_temp_dir().'/tmp.xml'; - touch($file); - $resource = new FileResource($file); - $this->assertEquals(realpath($file), $resource->getResource(), '->getResource() returns the path to the resource'); - unlink($file); - } - - public function testIsUptodate() - { - $file = sys_get_temp_dir().'/tmp.xml'; - touch($file); - $resource = new FileResource($file); - $this->assertTrue($resource->isUptodate(time() + 10), '->isUptodate() returns true if the resource has not changed'); - $this->assertTrue(!$resource->isUptodate(time() - 86400), '->isUptodate() returns false if the resource has been updated'); - - $resource = new FileResource('/____foo/foobar'.rand(1, 999999)); - $this->assertTrue(!$resource->isUptodate(time()), '->isUptodate() returns false if the resource does not exist'); - } -} diff --git a/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php b/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php index 7371b76effdd..2c01bc19ac7c 100644 --- a/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php +++ b/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php @@ -13,7 +13,7 @@ use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; -use Symfony\Component\Routing\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; class RouteCollectionTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/Translation/Loader/CsvFileLoaderTest.php b/tests/Symfony/Tests/Component/Translation/Loader/CsvFileLoaderTest.php index fd7c6aa1a948..daadb4313722 100644 --- a/tests/Symfony/Tests/Component/Translation/Loader/CsvFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Translation/Loader/CsvFileLoaderTest.php @@ -12,7 +12,7 @@ namespace Symfony\Tests\Component\Translation\Loader; use Symfony\Component\Translation\Loader\CsvFileLoader; -use Symfony\Component\Translation\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; class CsvFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/Translation/Loader/PhpFileLoaderTest.php b/tests/Symfony/Tests/Component/Translation/Loader/PhpFileLoaderTest.php index b382472a27ee..1b0d7b764339 100644 --- a/tests/Symfony/Tests/Component/Translation/Loader/PhpFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Translation/Loader/PhpFileLoaderTest.php @@ -12,7 +12,7 @@ namespace Symfony\Tests\Component\Translation\Loader; use Symfony\Component\Translation\Loader\PhpFileLoader; -use Symfony\Component\Translation\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php b/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php index 2a39a2661ac2..b192de031438 100644 --- a/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php @@ -12,7 +12,7 @@ namespace Symfony\Tests\Component\Translation\Loader; use Symfony\Component\Translation\Loader\XliffFileLoader; -use Symfony\Component\Translation\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/Translation/Loader/YamlFileLoaderTest.php b/tests/Symfony/Tests/Component/Translation/Loader/YamlFileLoaderTest.php index 7f09c45b56a9..13d36254367d 100644 --- a/tests/Symfony/Tests/Component/Translation/Loader/YamlFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Translation/Loader/YamlFileLoaderTest.php @@ -12,7 +12,7 @@ namespace Symfony\Tests\Component\Translation\Loader; use Symfony\Component\Translation\Loader\YamlFileLoader; -use Symfony\Component\Translation\Resource\FileResource; +use Symfony\Component\Config\Resource\FileResource; class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/Translation/MessageCatalogTest.php b/tests/Symfony/Tests/Component/Translation/MessageCatalogTest.php index 182aad708ebd..e27f126c6aca 100644 --- a/tests/Symfony/Tests/Component/Translation/MessageCatalogTest.php +++ b/tests/Symfony/Tests/Component/Translation/MessageCatalogTest.php @@ -82,10 +82,10 @@ public function testReplace() public function testAddCatalogue() { - $r = $this->getMock('Symfony\Component\Translation\Resource\ResourceInterface'); + $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); - $r1 = $this->getMock('Symfony\Component\Translation\Resource\ResourceInterface'); + $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); @@ -104,10 +104,10 @@ public function testAddCatalogue() public function testAddFallbackCatalogue() { - $r = $this->getMock('Symfony\Component\Translation\Resource\ResourceInterface'); + $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); - $r1 = $this->getMock('Symfony\Component\Translation\Resource\ResourceInterface'); + $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); $catalogue = new MessageCatalogue('en_US', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); @@ -136,11 +136,11 @@ public function testAddCatalogueWhenLocaleIsNotTheSameAsTheCurrentOne() public function testGetAddResource() { $catalogue = new MessageCatalogue('en'); - $r = $this->getMock('Symfony\Component\Translation\Resource\ResourceInterface'); + $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); $catalogue->addResource($r); $catalogue->addResource($r); - $r1 = $this->getMock('Symfony\Component\Translation\Resource\ResourceInterface'); + $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); $catalogue->addResource($r1); diff --git a/tests/Symfony/Tests/Component/Translation/Resource/FileResourceTest.php b/tests/Symfony/Tests/Component/Translation/Resource/FileResourceTest.php deleted file mode 100644 index de194193ef1f..000000000000 --- a/tests/Symfony/Tests/Component/Translation/Resource/FileResourceTest.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Tests\Component\Translation\Resource; - -use Symfony\Component\Translation\Resource\FileResource; - -class FileResourceTest extends \PHPUnit_Framework_TestCase -{ - /** - * @expectedException InvalidArgumentException - */ - public function testConstructor() - { - $resource = new FileResource(__DIR__.'/../fixtures/foobar'); - } - - public function testMagicToString() - { - $resource = new FileResource(__DIR__.'/../fixtures/resources.php'); - - $this->assertEquals(realpath(__DIR__.'/../fixtures/resources.php'), (string) $resource); - } - - public function testGetResource() - { - $resource = new FileResource(__DIR__.'/../fixtures/resources.php'); - - $this->assertEquals(realpath(__DIR__.'/../fixtures/resources.php'), $resource->getResource()); - } - - public function testIsUptodate() - { - $r = __DIR__.'/../fixtures/resources.php'; - $resource = new FileResource($r); - - $this->assertFalse($resource->isUptodate(filemtime($r) - 100)); - $this->assertTrue($resource->isUptodate(filemtime($r) + 100)); - } -}