diff --git a/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php b/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php index d1589399f8..a0b5dce60d 100644 --- a/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php @@ -15,7 +15,7 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\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 21930f6d07..bd787f0424 100755 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php @@ -14,12 +14,12 @@ namespace Symfony\Bundle\DoctrineBundle\DependencyInjection; 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\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\Resource\FileResource; use Symfony\Bundle\DoctrineAbstractBundle\DependencyInjection\AbstractDoctrineExtension; -use Symfony\Component\Config\Loader\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 117cd3b006..d6405ca1f8 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\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\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 9e43aa88fc..3843831300 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/XmlDoctrineExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/XmlDoctrineExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\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 a649e6b5da..547479a6cc 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/YamlDoctrineExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/YamlDoctrineExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\FileLocator; class YamlDoctrineExtensionTest extends AbstractDoctrineExtensionTest { diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php index 1e9dffdc4c..3a1911f1a3 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php @@ -13,12 +13,12 @@ namespace Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection; 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\Config\Resource\FileResource; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Resource\FileResource; 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 e61b1f43c0..2321cf5a73 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\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 63d0a2bfab..32e12073a6 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\FileLocator; class YamlMongoDBExtensionTest extends AbstractMongoDBExtensionTest { diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index a1f7e77dc0..4331c10cbf 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\Parameter; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Configuration\Processor; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Resource\FileResource; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\Config\Loader\FileLocator; /** * FrameworkExtension. diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index bbd363184b..65ff4e29b0 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\Component\HttpKernel\Config\Loader\FileLocator - Symfony\Component\Config\Loader\LoaderResolver + Symfony\Bundle\FrameworkBundle\Routing\FileLocator + Symfony\Component\Routing\Loader\LoaderResolver Symfony\Component\Routing\Loader\XmlFileLoader Symfony\Component\Routing\Loader\YamlFileLoader Symfony\Component\Routing\Loader\PhpFileLoader diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php index 2721286478..3194c4085b 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\Config\Loader\DelegatingLoader as BaseDelegatingLoader; -use Symfony\Component\Config\Loader\LoaderResolverInterface; +use Symfony\Component\Routing\Loader\DelegatingLoader as BaseDelegatingLoader; +use Symfony\Component\Routing\Loader\LoaderResolverInterface; use Symfony\Component\HttpKernel\Log\LoggerInterface; /** diff --git a/src/Symfony/Component/HttpKernel/Config/Loader/FileLocator.php b/src/Symfony/Bundle/FrameworkBundle/Routing/FileLocator.php similarity index 90% rename from src/Symfony/Component/HttpKernel/Config/Loader/FileLocator.php rename to src/Symfony/Bundle/FrameworkBundle/Routing/FileLocator.php index b37801c2c8..9b620b9e1c 100644 --- a/src/Symfony/Component/HttpKernel/Config/Loader/FileLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/FileLocator.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\Config\Loader; +namespace Symfony\Bundle\FrameworkBundle\Routing; -use Symfony\Component\Config\Loader\FileLocator as BaseFileLocator; +use Symfony\Component\Routing\Loader\FileLocator as BaseFileLocator; use Symfony\Component\HttpKernel\KernelInterface; /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/LazyLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/LazyLoader.php index cb6d1536a2..b3632108e0 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\Config\Loader\LoaderInterface; +use Symfony\Component\Routing\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Routing\Loader\LoaderResolver as BaseLoaderResolver; /** * LazyLoader facilitate lazy loading of loader services. @@ -78,7 +78,7 @@ class LazyLoader implements LoaderInterface * * @param LoaderResolver $resolver A LoaderResolver instance */ - public function setResolver(LoaderResolver $resolver) + public function setResolver(BaseLoaderResolver $resolver) { $this->container->get($this->service)->setResolver($resolver); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php index 37aecfe7ab..649f63b401 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\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 144cc6c5d4..975d8fba1d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\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 15fa8ce2ad..278d7d058e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\FileLocator; class YamlFrameworkExtensionTest extends FrameworkExtensionTest { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php index 7498a4ea7d..f6afcbdbf2 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/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 6031e1d3f5..561bf55747 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\DefinitionDecorator; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\DependencyInjection\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\Loader\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 bcd05b2fe5..931dd72fbf 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpSecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpSecurityExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\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 2a4d4387f7..2b0605280e 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlSecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlSecurityExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\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 a48333e784..bc45a9c19a 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlSecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlSecurityExtensionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\FileLocator; class YamlSecurityExtensionTest extends SecurityExtensionTest { diff --git a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php index 49f525e87e..c70c6daab2 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php @@ -13,9 +13,9 @@ namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection; 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\Loader\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 60a1aa4110..297edc616d 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -15,7 +15,7 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\FileLocator; /** * TwigExtension. diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index 2c777dbc84..d50fb1409c 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -13,11 +13,11 @@ namespace Symfony\Bundle\WebProfilerBundle\DependencyInjection; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\Config\Loader\FileLocator; /** * WebProfilerExtension. diff --git a/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php b/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php index 654bd5d546..8c12c00536 100644 --- a/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php +++ b/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php @@ -13,8 +13,8 @@ namespace Symfony\Bundle\ZendBundle\DependencyInjection; 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\Loader\FileLocator; /** * ZendExtension is an extension for the Zend Framework libraries. diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index dd1a4f0df3..008ef416c2 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -17,8 +17,8 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\DependencyInjection\InterfaceInjector; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\Config\Resource\ResourceInterface; +use Symfony\Component\DependencyInjection\Resource\FileResource; +use Symfony\Component\DependencyInjection\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 aa64dadc77..31cf0ec5f3 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php @@ -11,9 +11,6 @@ namespace Symfony\Component\DependencyInjection\Loader; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\Config\Loader\Loader; - /** * ClosureLoader loads service definitions from a PHP closure. * @@ -23,18 +20,6 @@ use Symfony\Component\Config\Loader\Loader; */ class ClosureLoader extends Loader { - protected $container; - - /** - * Constructor. - * - * @param ContainerBuilder $container A ContainerBuilder instance - */ - public function __construct(ContainerBuilder $container) - { - $this->container = $container; - } - /** * Loads a Closure. * diff --git a/src/Symfony/Component/Config/Loader/DelegatingLoader.php b/src/Symfony/Component/DependencyInjection/Loader/DelegatingLoader.php similarity index 97% rename from src/Symfony/Component/Config/Loader/DelegatingLoader.php rename to src/Symfony/Component/DependencyInjection/Loader/DelegatingLoader.php index ed153c5778..cbbf92e37d 100644 --- a/src/Symfony/Component/Config/Loader/DelegatingLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/DelegatingLoader.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Config\Loader; +namespace Symfony\Component\DependencyInjection\Loader; /** * DelegatingLoader delegates loading to other loaders using a loader resolver. diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php index 588628f6d5..bd0226a719 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php @@ -12,17 +12,16 @@ namespace Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\Config\Loader\FileLoader as BaseFileLoader; -use Symfony\Component\Config\Loader\FileLocator; /** * FileLoader is the abstract class used by all built-in loaders that are file based. * * @author Fabien Potencier */ -abstract class FileLoader extends BaseFileLoader +abstract class FileLoader extends Loader { - protected $container; + protected $locator; + protected $currentDir; /** * Constructor. @@ -31,8 +30,35 @@ abstract class FileLoader extends BaseFileLoader */ public function __construct(ContainerBuilder $container, FileLocator $locator) { - $this->container = $container; + $this->locator = $locator; - parent::__construct($locator); + 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->getAbsolutePath($resource, $this->currentDir); + } + + $loader->load($resource); + } catch (\Exception $e) { + if (!$ignoreErrors) { + throw $e; + } + } } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLocator.php b/src/Symfony/Component/DependencyInjection/Loader/FileLocator.php new file mode 100644 index 0000000000..a3a2616751 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Loader/FileLocator.php @@ -0,0 +1,101 @@ + + * + * 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 c6fca36d7a..7dddd1c63f 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\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\Resource\FileResource; /** * IniFileLoader loads parameters from INI files. diff --git a/src/Symfony/Component/Config/Loader/Loader.php b/src/Symfony/Component/DependencyInjection/Loader/Loader.php similarity index 83% rename from src/Symfony/Component/Config/Loader/Loader.php rename to src/Symfony/Component/DependencyInjection/Loader/Loader.php index 1253fd166b..07c79e12fd 100644 --- a/src/Symfony/Component/Config/Loader/Loader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Loader.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Config\Loader; +namespace Symfony\Component\DependencyInjection\Loader; + +use Symfony\Component\DependencyInjection\ContainerBuilder; /** * Loader is the abstract class used by all built-in loaders. @@ -18,8 +20,19 @@ namespace Symfony\Component\Config\Loader; */ 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. * diff --git a/src/Symfony/Component/DependencyInjection/Loader/LoaderInterface.php b/src/Symfony/Component/DependencyInjection/Loader/LoaderInterface.php new file mode 100644 index 0000000000..3353a008b8 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Loader/LoaderInterface.php @@ -0,0 +1,85 @@ + + * + * 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/Config/Loader/LoaderResolver.php b/src/Symfony/Component/DependencyInjection/Loader/LoaderResolver.php similarity index 87% rename from src/Symfony/Component/Config/Loader/LoaderResolver.php rename to src/Symfony/Component/DependencyInjection/Loader/LoaderResolver.php index c627c15e7f..fe29bafdac 100644 --- a/src/Symfony/Component/Config/Loader/LoaderResolver.php +++ b/src/Symfony/Component/DependencyInjection/Loader/LoaderResolver.php @@ -9,13 +9,14 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Config\Loader; +namespace Symfony\Component\DependencyInjection\Loader; /** * LoaderResolver selects a loader for a given resource. * - * 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. + * 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. * * @author Fabien Potencier */ diff --git a/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php b/src/Symfony/Component/DependencyInjection/Loader/LoaderResolverInterface.php similarity index 92% rename from src/Symfony/Component/Config/Loader/LoaderResolverInterface.php rename to src/Symfony/Component/DependencyInjection/Loader/LoaderResolverInterface.php index 727942e219..af36f3059d 100644 --- a/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php +++ b/src/Symfony/Component/DependencyInjection/Loader/LoaderResolverInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Config\Loader; +namespace Symfony\Component\DependencyInjection\Loader; /** * LoaderResolverInterface selects a loader for a given resource. diff --git a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php index ac1685ab81..34ed56f86e 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\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\Resource\FileResource; /** * PhpFileLoader loads service definitions from a PHP file. diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 43a35f4103..03420f00e3 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\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\SimpleXMLElement; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\Resource\FileResource; /** * XmlFileLoader loads XML files service definitions. diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index b23a3ededa..f57701803c 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\InterfaceInjector; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\Resource\FileResource; use Symfony\Component\Yaml\Yaml; /** diff --git a/src/Symfony/Component/DependencyInjection/Resource/FileResource.php b/src/Symfony/Component/DependencyInjection/Resource/FileResource.php new file mode 100644 index 0000000000..6ed6ddf513 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Resource/FileResource.php @@ -0,0 +1,68 @@ + + * + * 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 new file mode 100644 index 0000000000..e03a66835a --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Resource/ResourceInterface.php @@ -0,0 +1,43 @@ + + * + * 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/Component/HttpKernel/DependencyInjection/Loader/FileLocator.php b/src/Symfony/Component/HttpKernel/DependencyInjection/Loader/FileLocator.php new file mode 100644 index 0000000000..d2a3616aac --- /dev/null +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/Loader/FileLocator.php @@ -0,0 +1,50 @@ + + * + * 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 fdd4cab772..a31cc064b9 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -15,6 +15,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface; 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; @@ -23,9 +26,7 @@ use Symfony\Component\DependencyInjection\Loader\ClosureLoader; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface; -use Symfony\Component\HttpKernel\Config\Loader\FileLocator; -use Symfony\Component\Config\Loader\LoaderResolver; -use Symfony\Component\Config\Loader\DelegatingLoader; +use Symfony\Component\HttpKernel\DependencyInjection\Loader\FileLocator; /** * The Kernel is the heart of the Symfony system. diff --git a/src/Symfony/Component/HttpKernel/KernelInterface.php b/src/Symfony/Component/HttpKernel/KernelInterface.php index 59d8f78b23..7ca1928dd4 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/bootstrap.php b/src/Symfony/Component/HttpKernel/bootstrap.php index 1001f1ea76..378fe0655f 100644 --- a/src/Symfony/Component/HttpKernel/bootstrap.php +++ b/src/Symfony/Component/HttpKernel/bootstrap.php @@ -438,9 +438,9 @@ class HttpKernel implements HttpKernelInterface 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(); @@ -469,6 +469,7 @@ 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; diff --git a/src/Symfony/Component/HttpKernel/bootstrap_cache.php b/src/Symfony/Component/HttpKernel/bootstrap_cache.php index 99b5ac55bd..c68c7fdfff 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(); @@ -33,6 +33,7 @@ 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; diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 1f3d7c5683..3ba559d41f 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -13,11 +13,10 @@ namespace Symfony\Component\Routing\Loader; use Doctrine\Common\Annotations\AnnotationReader; use Symfony\Component\Routing\Annotation\Route as RouteAnnotation; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Routing\Loader\LoaderResolver; +use Symfony\Component\Routing\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/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index 2c4e60256e..e812459f59 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -12,9 +12,7 @@ namespace Symfony\Component\Routing\Loader; use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\Config\Loader\FileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\Routing\Resource\FileResource; /** * AnnotationFileLoader loads routing information from annotations set diff --git a/src/Symfony/Component/Routing/Loader/ClosureLoader.php b/src/Symfony/Component/Routing/Loader/ClosureLoader.php index c00ace1a96..e86470b242 100644 --- a/src/Symfony/Component/Routing/Loader/ClosureLoader.php +++ b/src/Symfony/Component/Routing/Loader/ClosureLoader.php @@ -11,8 +11,6 @@ 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/DelegatingLoader.php b/src/Symfony/Component/Routing/Loader/DelegatingLoader.php new file mode 100644 index 0000000000..998f570088 --- /dev/null +++ b/src/Symfony/Component/Routing/Loader/DelegatingLoader.php @@ -0,0 +1,80 @@ + + * + * 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; + +/** + * DelegatingLoader delegates route 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 + * @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'))); + } + + return $loader->load($resource, $type); + } + + /** + * Returns true if this class supports the given 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, $type = null) + { + foreach ($this->resolver->getLoaders() as $loader) { + if ($loader->supports($resource, $type)) { + return true; + } + } + + return false; + } +} diff --git a/src/Symfony/Component/Config/Loader/FileLoader.php b/src/Symfony/Component/Routing/Loader/FileLoader.php similarity index 54% rename from src/Symfony/Component/Config/Loader/FileLoader.php rename to src/Symfony/Component/Routing/Loader/FileLoader.php index c62b359605..c9362e7f45 100644 --- a/src/Symfony/Component/Config/Loader/FileLoader.php +++ b/src/Symfony/Component/Routing/Loader/FileLoader.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Config\Loader; +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. @@ -21,9 +23,6 @@ abstract class FileLoader extends Loader protected $locator; protected $currentDir; - /** - * Constructor. - */ public function __construct(FileLocator $locator) { $this->locator = $locator; @@ -35,24 +34,21 @@ abstract class FileLoader extends Loader } /** - * Adds definitions and parameters from a resource. + * Adds routes from a resource. * - * @param mixed $resource A Resource + * @param mixed $resource A Resource + * @param string $type The resource type + * + * @return RouteCollection A RouteCollection instance */ - public function import($resource, $ignoreErrors = false) + public function import($resource, $type = null) { - try { - $loader = $this->resolve($resource); + $loader = $this->resolve($resource, $type); - if ($loader instanceof FileLoader && null !== $this->currentDir) { - $resource = $this->locator->getAbsolutePath($resource, $this->currentDir); - } - - $loader->load($resource); - } catch (\Exception $e) { - if (!$ignoreErrors) { - throw $e; - } + if ($loader instanceof FileLoader && null !== $this->currentDir) { + $resource = $this->locator->getAbsolutePath($resource, $this->currentDir); } + + return $loader->load($resource, $type); } } diff --git a/src/Symfony/Component/Config/Loader/FileLocator.php b/src/Symfony/Component/Routing/Loader/FileLocator.php similarity index 98% rename from src/Symfony/Component/Config/Loader/FileLocator.php rename to src/Symfony/Component/Routing/Loader/FileLocator.php index 61f91dbe83..17ce70fa0a 100644 --- a/src/Symfony/Component/Config/Loader/FileLocator.php +++ b/src/Symfony/Component/Routing/Loader/FileLocator.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Config\Loader; +namespace Symfony\Component\Routing\Loader; /** * FileLocator uses an array of pre-defined paths to find files. diff --git a/src/Symfony/Component/Routing/Loader/Loader.php b/src/Symfony/Component/Routing/Loader/Loader.php new file mode 100644 index 0000000000..a46116aa9f --- /dev/null +++ b/src/Symfony/Component/Routing/Loader/Loader.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Routing\Loader; + +/** + * Loader is the abstract class used by all built-in loaders. + * + * @author Fabien Potencier + */ +abstract class Loader implements LoaderInterface +{ + protected $resolver; + + /** + * 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 routes 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); + } + + /** + * Finds a loader able to load an imported resource + * + * @param mixed $resource A Resource + * @param string $type The resource type + * + * @return LoaderInterface A LoaderInterface instance + * + * @throws \InvalidArgumentException if no loader is found + */ + public function resolve($resource, $type = null) + { + $loader = false; + if ($this->supports($resource, $type)) { + $loader = $this; + } elseif (null !== $this->resolver) { + $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'))); + } + + return $loader; + } +} diff --git a/src/Symfony/Component/Config/Loader/LoaderInterface.php b/src/Symfony/Component/Routing/Loader/LoaderInterface.php similarity index 59% rename from src/Symfony/Component/Config/Loader/LoaderInterface.php rename to src/Symfony/Component/Routing/Loader/LoaderInterface.php index f327ab6845..a9de96640f 100644 --- a/src/Symfony/Component/Config/Loader/LoaderInterface.php +++ b/src/Symfony/Component/Routing/Loader/LoaderInterface.php @@ -9,10 +9,12 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Config\Loader; +namespace Symfony\Component\Routing\Loader; + +use Symfony\Component\Routing\Loader\LoaderResolver; /** - * LoaderInterface is the interface implemented by all loader classes. + * LoaderInterface is the interface that all loader classes must implement. * * @author Fabien Potencier */ @@ -21,18 +23,22 @@ interface LoaderInterface /** * Loads a resource. * - * @param mixed $resource The resource + * @param mixed $resource A resource + * @param string $type The resource type + * + * @return RouteCollection A RouteCollection instance */ - function load($resource); + function load($resource, $type = null); /** * 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 + * @return Boolean True if this class supports the given resource, false otherwise */ - function supports($resource); + function supports($resource, $type = null); /** * Gets the loader resolver. diff --git a/src/Symfony/Component/Routing/Loader/LoaderResolver.php b/src/Symfony/Component/Routing/Loader/LoaderResolver.php new file mode 100644 index 0000000000..1411e9882a --- /dev/null +++ b/src/Symfony/Component/Routing/Loader/LoaderResolver.php @@ -0,0 +1,75 @@ + + * + * 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 new file mode 100644 index 0000000000..dea15ca47e --- /dev/null +++ b/src/Symfony/Component/Routing/Loader/LoaderResolverInterface.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\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 906a79fda7..3be9000d9c 100644 --- a/src/Symfony/Component/Routing/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/PhpFileLoader.php @@ -11,8 +11,7 @@ namespace Symfony\Component\Routing\Loader; -use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\Config\Loader\FileLoader; +use Symfony\Component\Routing\Resource\FileResource; /** * 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 a33e02b802..7370939446 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -13,8 +13,7 @@ namespace Symfony\Component\Routing\Loader; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; -use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\Config\Loader\FileLoader; +use Symfony\Component\Routing\Resource\FileResource; /** * XmlFileLoader loads XML routing files. diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index 477c8219ee..6898c7ae7c 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -13,9 +13,8 @@ namespace Symfony\Component\Routing\Loader; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Routing\Resource\FileResource; use Symfony\Component\Yaml\Yaml; -use Symfony\Component\Config\Loader\FileLoader; /** * YamlFileLoader loads Yaml routing files. diff --git a/src/Symfony/Component/Config/Resource/FileResource.php b/src/Symfony/Component/Routing/Resource/FileResource.php similarity index 97% rename from src/Symfony/Component/Config/Resource/FileResource.php rename to src/Symfony/Component/Routing/Resource/FileResource.php index 93520eeb57..1f57d8f1d9 100644 --- a/src/Symfony/Component/Config/Resource/FileResource.php +++ b/src/Symfony/Component/Routing/Resource/FileResource.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Config\Resource; +namespace Symfony\Component\Routing\Resource; /** * FileResource represents a resource stored on the filesystem. diff --git a/src/Symfony/Component/Config/Resource/ResourceInterface.php b/src/Symfony/Component/Routing/Resource/ResourceInterface.php similarity index 95% rename from src/Symfony/Component/Config/Resource/ResourceInterface.php rename to src/Symfony/Component/Routing/Resource/ResourceInterface.php index b10b7bdddb..d55ce4d8ff 100644 --- a/src/Symfony/Component/Config/Resource/ResourceInterface.php +++ b/src/Symfony/Component/Routing/Resource/ResourceInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Config\Resource; +namespace Symfony\Component\Routing\Resource; /** * ResourceInterface is the interface that must be implemented by all Resource classes. diff --git a/src/Symfony/Component/Routing/RouteCollection.php b/src/Symfony/Component/Routing/RouteCollection.php index e54766f8d1..98d5793862 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\Config\Resource\ResourceInterface; +use Symfony\Component\Routing\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 b4f0be8855..cc90ee8dc1 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Routing; -use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\Routing\Loader\LoaderInterface; /** * The Router class is an example of the integration of all pieces of the diff --git a/src/Symfony/Component/Translation/Loader/CsvFileLoader.php b/src/Symfony/Component/Translation/Loader/CsvFileLoader.php index efa2e466fa..666cebd3a3 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\Config\Resource\FileResource; +use Symfony\Component\Translation\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 ff60acb538..01c9f00239 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\Config\Resource\FileResource; +use Symfony\Component\Translation\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 c46f1a7399..afd8762e68 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\Config\Resource\FileResource; +use Symfony\Component\Translation\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 9eecff5146..248b293fa2 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\Config\Resource\FileResource; +use Symfony\Component\Translation\Resource\FileResource; use Symfony\Component\Yaml\Yaml; /** diff --git a/src/Symfony/Component/Translation/MessageCatalogue.php b/src/Symfony/Component/Translation/MessageCatalogue.php index 9c69c32b7a..6b7d321052 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\Config\Resource\ResourceInterface; +use Symfony\Component\Translation\Resource\ResourceInterface; /** * MessageCatalogue. diff --git a/src/Symfony/Component/Translation/MessageCatalogueInterface.php b/src/Symfony/Component/Translation/MessageCatalogueInterface.php index 56e4ec44cd..85d6e1f631 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\Config\Resource\ResourceInterface; +use Symfony\Component\Translation\Resource\ResourceInterface; /** * MessageCatalogueInterface. diff --git a/src/Symfony/Component/Translation/Resource/FileResource.php b/src/Symfony/Component/Translation/Resource/FileResource.php new file mode 100644 index 0000000000..fbe60ab401 --- /dev/null +++ b/src/Symfony/Component/Translation/Resource/FileResource.php @@ -0,0 +1,60 @@ + + * + * 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 new file mode 100644 index 0000000000..11d876bac9 --- /dev/null +++ b/src/Symfony/Component/Translation/Resource/ResourceInterface.php @@ -0,0 +1,43 @@ + + * + * 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/Fixtures/foo.xml b/tests/Symfony/Tests/Component/Config/Fixtures/foo.xml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/Symfony/Tests/Component/Config/Loader/DelegatingLoaderTest.php b/tests/Symfony/Tests/Component/Config/Loader/DelegatingLoaderTest.php deleted file mode 100644 index f6679920d0..0000000000 --- a/tests/Symfony/Tests/Component/Config/Loader/DelegatingLoaderTest.php +++ /dev/null @@ -1,87 +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\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/ContainerBuilderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php index e4c2d2619d..4a14e40664 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\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\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 8ce4210722..a6e73d8351 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\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\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 new file mode 100644 index 0000000000..026b929355 --- /dev/null +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/DelegatingLoaderTest.php @@ -0,0 +1,86 @@ + + * + * 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 new file mode 100644 index 0000000000..18c567bd62 --- /dev/null +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/FileLocatorTest.php @@ -0,0 +1,36 @@ + + * + * 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 f5b7299288..ef45df5c3d 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/IniFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/IniFileLoaderTest.php @@ -13,7 +13,7 @@ namespace Symfony\Tests\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\FileLocator; class IniFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/Config/Loader/LoaderResolverTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderResolverTest.php similarity index 53% rename from tests/Symfony/Tests/Component/Config/Loader/LoaderResolverTest.php rename to tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderResolverTest.php index a05a9e1f9e..4953551e0c 100644 --- a/tests/Symfony/Tests/Component/Config/Loader/LoaderResolverTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderResolverTest.php @@ -9,47 +9,47 @@ * file that was distributed with this source code. */ -namespace Symfony\Tests\Component\Config\Loader; +namespace Symfony\Tests\Component\DependencyInjection\Loader; -use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\LoaderResolver; +use Symfony\Component\DependencyInjection\Loader\ClosureLoader; class LoaderResolverTest extends \PHPUnit_Framework_TestCase { /** - * @covers Symfony\Component\Config\Loader\LoaderResolver::__construct + * @covers Symfony\Component\DependencyInjection\Loader\LoaderResolver::__construct */ public function testConstructor() { $resolver = new LoaderResolver(array( - $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'), + $loader = new ClosureLoader(new ContainerBuilder()), )); $this->assertEquals(array($loader), $resolver->getLoaders(), '__construct() takes an array of loaders as its first argument'); } /** - * @covers Symfony\Component\Config\Loader\LoaderResolver::resolve + * @covers Symfony\Component\DependencyInjection\Loader\LoaderResolver::resolve */ public function testResolve() { - $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'); + $resolver = new LoaderResolver(array( + $loader = new ClosureLoader(new ContainerBuilder()), + )); - $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); - $loader->expects($this->once())->method('supports')->will($this->returnValue(true)); - $resolver = new LoaderResolver(array($loader)); + $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\Config\Loader\LoaderResolver::getLoaders - * @covers Symfony\Component\Config\Loader\LoaderResolver::addLoader + * @covers Symfony\Component\DependencyInjection\Loader\LoaderResolver::getLoaders + * @covers Symfony\Component\DependencyInjection\Loader\LoaderResolver::addLoader */ public function testLoaders() { $resolver = new LoaderResolver(); - $resolver->addLoader($loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface')); + $resolver->addLoader($loader = new ClosureLoader(new ContainerBuilder())); $this->assertEquals(array($loader), $resolver->getLoaders(), 'addLoader() adds a loader'); } diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderTest.php new file mode 100644 index 0000000000..ec1f6d1950 --- /dev/null +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/LoaderTest.php @@ -0,0 +1,78 @@ + + * + * 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 321948f913..54e0069801 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\Reference; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Loader\Loader; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\Config\Loader\LoaderResolver; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\LoaderResolver; +use Symfony\Component\DependencyInjection\Loader\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 cf959395d1..0ba99e32b1 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\Loader; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\Config\Loader\LoaderResolver; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\LoaderResolver; +use Symfony\Component\DependencyInjection\Loader\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 099127f55e..8b0756eb57 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\Loader; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\Config\Loader\LoaderResolver; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\DependencyInjection\Loader\LoaderResolver; +use Symfony\Component\DependencyInjection\Loader\FileLocator; class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Symfony/Tests/Component/Config/Resource/FileResourceTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Resource/FileResourceTest.php similarity index 81% rename from tests/Symfony/Tests/Component/Config/Resource/FileResourceTest.php rename to tests/Symfony/Tests/Component/DependencyInjection/Resource/FileResourceTest.php index 3b382886df..947bcdc337 100644 --- a/tests/Symfony/Tests/Component/Config/Resource/FileResourceTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Resource/FileResourceTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Tests\Component\Config\Resource; +namespace Symfony\Tests\Component\DependencyInjection\Resource; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\Resource\FileResource; class FileResourceTest extends \PHPUnit_Framework_TestCase { @@ -31,7 +31,7 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase } /** - * @covers Symfony\Component\Config\Resource\FileResource::getResource + * @covers Symfony\Component\DependencyInjection\Resource\FileResource::getResource */ public function testGetResource() { @@ -39,7 +39,7 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase } /** - * @covers Symfony\Component\Config\Resource\FileResource::isUptodate + * @covers Symfony\Component\DependencyInjection\Resource\FileResource::isUptodate */ public function testIsUptodate() { diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index f82974c782..18542f50f7 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -14,9 +14,9 @@ namespace Symfony\Tests\Component\HttpKernel; 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 { diff --git a/tests/Symfony/Tests/Component/Routing/Loader/AnnotationClassLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/AnnotationClassLoaderTest.php index dd5e296446..0aec391cde 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\Config\Loader\LoaderResolver; +use Symfony\Component\Routing\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 aa46677fc9..15a1f7b30e 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\Config\Loader\LoaderResolver; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\Routing\Loader\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 9325ed0e48..49d1d9f7fa 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\Config\Loader\LoaderResolver; +use Symfony\Component\Routing\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\AnnotationFileLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -27,7 +27,7 @@ class AnnotationFileLoaderTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMockForAbstractClass(); - $loader = new AnnotationFileLoader($this->getMock('Symfony\Component\Config\Loader\FileLocator'), $annotationClassLoader); + $loader = new AnnotationFileLoader($this->getMock('Symfony\Component\Routing\Loader\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 e30a132199..f242e72768 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\Config\Loader\LoaderResolver; +use Symfony\Component\Routing\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\AnnotationGlobLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -27,7 +27,7 @@ class AnnotationGlobLoaderTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMockForAbstractClass(); - $loader = new AnnotationGlobLoader($this->getMock('Symfony\Component\Config\Loader\FileLocator'), $annotationClassLoader); + $loader = new AnnotationGlobLoader($this->getMock('Symfony\Component\Routing\Loader\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 8eb8cb1a72..8eee98ec98 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\Config\Loader\LoaderResolver; +use Symfony\Component\Routing\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 new file mode 100644 index 0000000000..f97bbc1b87 --- /dev/null +++ b/tests/Symfony/Tests/Component/Routing/Loader/DelegatingLoaderTest.php @@ -0,0 +1,89 @@ + + * + * 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/Config/Loader/FileLocatorTest.php b/tests/Symfony/Tests/Component/Routing/Loader/FileLocatorTest.php similarity index 88% rename from tests/Symfony/Tests/Component/Config/Loader/FileLocatorTest.php rename to tests/Symfony/Tests/Component/Routing/Loader/FileLocatorTest.php index 126b1d8809..655aadcdd7 100644 --- a/tests/Symfony/Tests/Component/Config/Loader/FileLocatorTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/FileLocatorTest.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Symfony\Tests\Component\Config\Loader; +namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\Routing\Loader\FileLocator; class FileLocatorTest extends \PHPUnit_Framework_TestCase { /** - * @covers Symfony\Component\Config\Loader\FileLocator::GetAbsolutePath - * @covers Symfony\Component\Config\Loader\FileLocator::isAbsolutePath + * @covers Symfony\Component\Routing\Loader\FileLocator::GetAbsolutePath + * @covers Symfony\Component\Routing\Loader\FileLocator::isAbsolutePath */ public function testGetAbsolutePath() { diff --git a/tests/Symfony/Tests/Component/Routing/Loader/LoaderResolverTest.php b/tests/Symfony/Tests/Component/Routing/Loader/LoaderResolverTest.php new file mode 100644 index 0000000000..fa44e984ab --- /dev/null +++ b/tests/Symfony/Tests/Component/Routing/Loader/LoaderResolverTest.php @@ -0,0 +1,55 @@ + + * + * 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/Config/Loader/LoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/LoaderTest.php similarity index 60% rename from tests/Symfony/Tests/Component/Config/Loader/LoaderTest.php rename to tests/Symfony/Tests/Component/Routing/Loader/LoaderTest.php index 9c7458d246..a9cc40435e 100644 --- a/tests/Symfony/Tests/Component/Config/Loader/LoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/LoaderTest.php @@ -9,16 +9,17 @@ * file that was distributed with this source code. */ -namespace Symfony\Tests\Component\Config\Loader; +namespace Symfony\Tests\Component\Routing\Loader; -use Symfony\Component\Config\Loader\LoaderResolver; -use Symfony\Component\Config\Loader\Loader; +use Symfony\Component\Routing\Loader\LoaderResolver; +use Symfony\Component\Routing\Loader\Loader; +use Symfony\Component\Routing\Loader\XmlFileLoader; class LoaderTest extends \PHPUnit_Framework_TestCase { /** - * @covers Symfony\Component\Config\Loader\Loader::getResolver - * @covers Symfony\Component\Config\Loader\Loader::setResolver + * @covers Symfony\Component\Routing\Loader\Loader::getResolver + * @covers Symfony\Component\Routing\Loader\Loader::setResolver */ public function testGetSetResolver() { @@ -29,24 +30,19 @@ class LoaderTest extends \PHPUnit_Framework_TestCase } /** - * @covers Symfony\Component\Config\Loader\Loader::resolve + * @covers Symfony\Component\Routing\Loader\Loader::resolve */ public function testResolve() { - $loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); - $loader1->expects($this->once())->method('supports')->will($this->returnValue(true)); - $resolver = new LoaderResolver(array($loader1)); + $resolver = new LoaderResolver(array( + $ini = new XmlFileLoader($this->getMock('Symfony\Component\Routing\Loader\FileLocator')), + )); $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/Routing/Loader/PhpFileLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/PhpFileLoaderTest.php index f4b43e84e5..ba2f4b2c60 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\Config\Loader\LoaderResolver; +use Symfony\Component\Routing\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\Config\Loader\FileLocator')); + $loader = new PhpFileLoader($this->getMock('Symfony\Component\Routing\Loader\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 22603cd53b..55dfdde326 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\Config\Loader\LoaderResolver; +use Symfony\Component\Routing\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\Config\Loader\FileLocator')); + $loader = new XmlFileLoader($this->getMock('Symfony\Component\Routing\Loader\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 9aa6e1d3ae..0bf758730c 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\Config\Loader\LoaderResolver; -use Symfony\Component\Config\Loader\FileLocator; +use Symfony\Component\Routing\Loader\LoaderResolver; use Symfony\Component\Routing\Loader\YamlFileLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Routing\Resource\FileResource; +use Symfony\Component\Routing\Loader\FileLocator; 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\Config\Loader\FileLocator')); + $loader = new YamlFileLoader($this->getMock('Symfony\Component\Routing\Loader\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 new file mode 100644 index 0000000000..009ddf46ac --- /dev/null +++ b/tests/Symfony/Tests/Component/Routing/Resource/FileResourceTest.php @@ -0,0 +1,38 @@ + + * + * 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 2c01bc19ac..7371b76eff 100644 --- a/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php +++ b/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php @@ -13,7 +13,7 @@ namespace Symfony\Tests\Component\Routing; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; -use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Routing\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 daadb43137..fd7c6aa1a9 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\Config\Resource\FileResource; +use Symfony\Component\Translation\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 1b0d7b7643..b382472a27 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\Config\Resource\FileResource; +use Symfony\Component\Translation\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 b192de0314..2a39a2661a 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\Config\Resource\FileResource; +use Symfony\Component\Translation\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 13d3625436..7f09c45b56 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\Config\Resource\FileResource; +use Symfony\Component\Translation\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 e27f126c6a..182aad708e 100644 --- a/tests/Symfony/Tests/Component/Translation/MessageCatalogTest.php +++ b/tests/Symfony/Tests/Component/Translation/MessageCatalogTest.php @@ -82,10 +82,10 @@ class MessageCatalogueTest extends \PHPUnit_Framework_TestCase public function testAddCatalogue() { - $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r = $this->getMock('Symfony\Component\Translation\Resource\ResourceInterface'); $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); - $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r1 = $this->getMock('Symfony\Component\Translation\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 @@ class MessageCatalogueTest extends \PHPUnit_Framework_TestCase public function testAddFallbackCatalogue() { - $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r = $this->getMock('Symfony\Component\Translation\Resource\ResourceInterface'); $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); - $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r1 = $this->getMock('Symfony\Component\Translation\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 @@ class MessageCatalogueTest extends \PHPUnit_Framework_TestCase public function testGetAddResource() { $catalogue = new MessageCatalogue('en'); - $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r = $this->getMock('Symfony\Component\Translation\Resource\ResourceInterface'); $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); $catalogue->addResource($r); $catalogue->addResource($r); - $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r1 = $this->getMock('Symfony\Component\Translation\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 new file mode 100644 index 0000000000..de194193ef --- /dev/null +++ b/tests/Symfony/Tests/Component/Translation/Resource/FileResourceTest.php @@ -0,0 +1,48 @@ + + * + * 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)); + } +}