diff --git a/src/Symfony/Component/Config/FileLocator.php b/src/Symfony/Component/Config/FileLocator.php index 0da2ad636667..71bb5ab0ba30 100644 --- a/src/Symfony/Component/Config/FileLocator.php +++ b/src/Symfony/Component/Config/FileLocator.php @@ -31,18 +31,14 @@ public function __construct($paths = array()) } /** - * Returns a full path for a given file name. - * - * @param mixed $name The file name to locate - * @param string $currentPath The current path - * @param bool $first Whether to return the first occurrence or an array of filenames - * - * @return string|array The full path to the file|An array of file paths - * - * @throws \InvalidArgumentException When file is not found + * {@inheritdoc} */ public function locate($name, $currentPath = null, $first = true) { + if ('' == $name) { + throw new \InvalidArgumentException('An empty file name is not valid to be located.'); + } + if ($this->isAbsolutePath($name)) { if (!file_exists($name)) { throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name)); @@ -84,10 +80,10 @@ public function locate($name, $currentPath = null, $first = true) */ private function isAbsolutePath($file) { - if ($file[0] == '/' || $file[0] == '\\' + if ($file[0] === '/' || $file[0] === '\\' || (strlen($file) > 3 && ctype_alpha($file[0]) - && $file[1] == ':' - && ($file[2] == '\\' || $file[2] == '/') + && $file[1] === ':' + && ($file[2] === '\\' || $file[2] === '/') ) || null !== parse_url($file, PHP_URL_SCHEME) ) { diff --git a/src/Symfony/Component/Config/FileLocatorInterface.php b/src/Symfony/Component/Config/FileLocatorInterface.php index 4287e3d1d0d3..66057982db89 100644 --- a/src/Symfony/Component/Config/FileLocatorInterface.php +++ b/src/Symfony/Component/Config/FileLocatorInterface.php @@ -19,11 +19,11 @@ interface FileLocatorInterface /** * Returns a full path for a given file name. * - * @param mixed $name The file name to locate - * @param string $currentPath The current path - * @param bool $first Whether to return the first occurrence or an array of filenames + * @param string $name The file name to locate + * @param string|null $currentPath The current path + * @param bool $first Whether to return the first occurrence or an array of filenames * - * @return string|array The full path to the file|An array of file paths + * @return string|array The full path to the file or an array of file paths * * @throws \InvalidArgumentException When file is not found */ diff --git a/src/Symfony/Component/Config/Loader/DelegatingLoader.php b/src/Symfony/Component/Config/Loader/DelegatingLoader.php index fa81311422e3..3097878bf0bf 100644 --- a/src/Symfony/Component/Config/Loader/DelegatingLoader.php +++ b/src/Symfony/Component/Config/Loader/DelegatingLoader.php @@ -34,14 +34,7 @@ public function __construct(LoaderResolverInterface $resolver) } /** - * Loads a resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return mixed - * - * @throws FileLoaderLoadException if no loader is found. + * {@inheritdoc} */ public function load($resource, $type = null) { diff --git a/src/Symfony/Component/Config/Loader/FileLoader.php b/src/Symfony/Component/Config/Loader/FileLoader.php index 981d16f92bac..b76390bcbb51 100644 --- a/src/Symfony/Component/Config/Loader/FileLoader.php +++ b/src/Symfony/Component/Config/Loader/FileLoader.php @@ -22,8 +22,14 @@ */ abstract class FileLoader extends Loader { + /** + * @var array + */ protected static $loading = array(); + /** + * @var FileLocatorInterface + */ protected $locator; private $currentDir; @@ -38,11 +44,21 @@ public function __construct(FileLocatorInterface $locator) $this->locator = $locator; } + /** + * Sets the current directory. + * + * @param string $dir + */ public function setCurrentDir($dir) { $this->currentDir = $dir; } + /** + * Returns the file locator used by this loader. + * + * @return FileLocatorInterface + */ public function getLocator() { return $this->locator; @@ -51,10 +67,10 @@ public function getLocator() /** * Imports a resource. * - * @param mixed $resource A Resource - * @param string $type The resource type - * @param bool $ignoreErrors Whether to ignore import errors or not - * @param string $sourceResource The original resource importing the new resource + * @param mixed $resource A Resource + * @param string|null $type The resource type or null if unknown + * @param bool $ignoreErrors Whether to ignore import errors or not + * @param string|null $sourceResource The original resource importing the new resource * * @return mixed * diff --git a/src/Symfony/Component/Config/Loader/Loader.php b/src/Symfony/Component/Config/Loader/Loader.php index 705a6a78e956..de4e127386d8 100644 --- a/src/Symfony/Component/Config/Loader/Loader.php +++ b/src/Symfony/Component/Config/Loader/Loader.php @@ -23,9 +23,7 @@ abstract class Loader implements LoaderInterface protected $resolver; /** - * Gets the loader resolver. - * - * @return LoaderResolverInterface A LoaderResolverInterface instance + * {@inheritdoc} */ public function getResolver() { @@ -33,9 +31,7 @@ public function getResolver() } /** - * Sets the loader resolver. - * - * @param LoaderResolverInterface $resolver A LoaderResolverInterface instance + * {@inheritdoc} */ public function setResolver(LoaderResolverInterface $resolver) { @@ -45,8 +41,8 @@ public function setResolver(LoaderResolverInterface $resolver) /** * Imports a resource. * - * @param mixed $resource A Resource - * @param string $type The resource type + * @param mixed $resource A resource + * @param string|null $type The resource type or null if unknown * * @return mixed */ @@ -58,12 +54,12 @@ public function import($resource, $type = null) /** * Finds a loader able to load an imported resource. * - * @param mixed $resource A Resource - * @param string $type The resource type + * @param mixed $resource A resource + * @param string|null $type The resource type or null if unknown * * @return LoaderInterface A LoaderInterface instance * - * @throws FileLoaderLoadException if no loader is found + * @throws FileLoaderLoadException If no loader is found */ public function resolve($resource, $type = null) { diff --git a/src/Symfony/Component/Config/Loader/LoaderInterface.php b/src/Symfony/Component/Config/Loader/LoaderInterface.php index 52d5981e8ea6..dd0a85a6b08c 100644 --- a/src/Symfony/Component/Config/Loader/LoaderInterface.php +++ b/src/Symfony/Component/Config/Loader/LoaderInterface.php @@ -21,18 +21,20 @@ interface LoaderInterface /** * Loads a resource. * - * @param mixed $resource The resource - * @param string $type The resource type + * @param mixed $resource The resource + * @param string|null $type The resource type or null if unknown + * + * @throws \Exception If something went wrong */ public function load($resource, $type = null); /** - * Returns true if this class supports the given resource. + * Returns whether this class supports the given resource. * - * @param mixed $resource A resource - * @param string $type The resource type + * @param mixed $resource A resource + * @param string|null $type The resource type or null if unknown * - * @return bool true if this class supports the given resource, false otherwise + * @return bool True if this class supports the given resource, false otherwise */ public function supports($resource, $type = null); diff --git a/src/Symfony/Component/Config/Loader/LoaderResolver.php b/src/Symfony/Component/Config/Loader/LoaderResolver.php index 2340fe07f886..e547e8a1d34a 100644 --- a/src/Symfony/Component/Config/Loader/LoaderResolver.php +++ b/src/Symfony/Component/Config/Loader/LoaderResolver.php @@ -40,12 +40,7 @@ public function __construct(array $loaders = array()) } /** - * Returns a loader able to load the resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return LoaderInterface|false A LoaderInterface instance + * {@inheritdoc} */ public function resolve($resource, $type = null) { diff --git a/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php b/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php index 57d878152ab5..40f1a1a63f29 100644 --- a/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php +++ b/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php @@ -21,10 +21,10 @@ interface LoaderResolverInterface /** * Returns a loader able to load the resource. * - * @param mixed $resource A resource - * @param string $type The resource type + * @param mixed $resource A resource + * @param string|null $type The resource type or null if unknown * - * @return LoaderInterface A LoaderInterface instance + * @return LoaderInterface|false The loader or false if none is able to load the resource */ public function resolve($resource, $type = null); } diff --git a/src/Symfony/Component/Config/Resource/DirectoryResource.php b/src/Symfony/Component/Config/Resource/DirectoryResource.php index a9e4d7614391..f15b81a311c9 100644 --- a/src/Symfony/Component/Config/Resource/DirectoryResource.php +++ b/src/Symfony/Component/Config/Resource/DirectoryResource.php @@ -24,8 +24,8 @@ class DirectoryResource implements ResourceInterface, \Serializable /** * Constructor. * - * @param string $resource The file path to the resource - * @param string $pattern A pattern to restrict monitored files + * @param string $resource The file path to the resource + * @param string|null $pattern A pattern to restrict monitored files */ public function __construct($resource, $pattern = null) { @@ -34,9 +34,7 @@ public function __construct($resource, $pattern = null) } /** - * Returns a string representation of the Resource. - * - * @return string A string representation of the Resource + * {@inheritdoc} */ public function __toString() { @@ -44,26 +42,25 @@ public function __toString() } /** - * Returns the resource tied to this Resource. - * - * @return mixed The resource + * {@inheritdoc} */ public function getResource() { return $this->resource; } + /** + * Returns the pattern to restrict monitored files + * + * @return string|null + */ public function getPattern() { return $this->pattern; } /** - * Returns true if the resource has not been updated since the given timestamp. - * - * @param int $timestamp The last time the resource was loaded - * - * @return bool true if the resource has not been updated, false otherwise + * {@inheritdoc} */ public function isFresh($timestamp) { diff --git a/src/Symfony/Component/Config/Resource/FileResource.php b/src/Symfony/Component/Config/Resource/FileResource.php index 5cb4bc7078ef..b828e7d37f66 100644 --- a/src/Symfony/Component/Config/Resource/FileResource.php +++ b/src/Symfony/Component/Config/Resource/FileResource.php @@ -20,6 +20,9 @@ */ class FileResource implements ResourceInterface, \Serializable { + /** + * @var string|false + */ private $resource; /** @@ -33,9 +36,7 @@ public function __construct($resource) } /** - * Returns a string representation of the Resource. - * - * @return string A string representation of the Resource + * {@inheritdoc} */ public function __toString() { @@ -43,9 +44,7 @@ public function __toString() } /** - * Returns the resource tied to this Resource. - * - * @return mixed The resource + * {@inheritdoc} */ public function getResource() { @@ -53,15 +52,11 @@ public function getResource() } /** - * Returns true if the resource has not been updated since the given timestamp. - * - * @param int $timestamp The last time the resource was loaded - * - * @return bool true if the resource has not been updated, false otherwise + * {@inheritdoc} */ public function isFresh($timestamp) { - if (!file_exists($this->resource)) { + if (false === $this->resource || !file_exists($this->resource)) { return false; } diff --git a/src/Symfony/Component/Config/Resource/ResourceInterface.php b/src/Symfony/Component/Config/Resource/ResourceInterface.php index c0ea9ed7b46d..db03d127a401 100644 --- a/src/Symfony/Component/Config/Resource/ResourceInterface.php +++ b/src/Symfony/Component/Config/Resource/ResourceInterface.php @@ -28,14 +28,14 @@ public 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 + * @param int $timestamp The last time the resource was loaded * - * @return bool true if the resource has not been updated, false otherwise + * @return bool True if the resource has not been updated, false otherwise */ public function isFresh($timestamp); /** - * Returns the resource tied to this Resource. + * Returns the tied resource. * * @return mixed The resource */ diff --git a/src/Symfony/Component/Config/Tests/FileLocatorTest.php b/src/Symfony/Component/Config/Tests/FileLocatorTest.php index 8e8f442f5e6a..d479f2569f1f 100644 --- a/src/Symfony/Component/Config/Tests/FileLocatorTest.php +++ b/src/Symfony/Component/Config/Tests/FileLocatorTest.php @@ -87,6 +87,7 @@ public function testLocate() /** * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The file "foobar.xml" does not exist */ public function testLocateThrowsAnExceptionIfTheFileDoesNotExists() { @@ -104,4 +105,15 @@ public function testLocateThrowsAnExceptionIfTheFileDoesNotExistsInAbsolutePath( $loader->locate(__DIR__.'/Fixtures/foobar.xml', __DIR__); } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage An empty file name is not valid to be located. + */ + public function testLocateEmpty() + { + $loader = new FileLocator(array(__DIR__.'/Fixtures')); + + $loader->locate(null, __DIR__); + } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php b/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php index 30cbe0ebaf99..a5b4e5ad240e 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php @@ -36,23 +36,15 @@ public function __construct(ContainerBuilder $container) } /** - * Loads a Closure. - * - * @param \Closure $closure The resource - * @param string $type The resource type + * {@inheritdoc} */ - public function load($closure, $type = null) + public function load($resource, $type = null) { - call_user_func($closure, $this->container); + call_user_func($resource, $this->container); } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php index ad437b5138d4..d71eecf74156 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php @@ -27,8 +27,8 @@ abstract class FileLoader extends BaseFileLoader /** * Constructor. * - * @param ContainerBuilder $container A ContainerBuilder instance - * @param FileLocatorInterface $locator A FileLocator instance + * @param ContainerBuilder $container A ContainerBuilder instance + * @param FileLocatorInterface $locator A FileLocator instance */ public function __construct(ContainerBuilder $container, FileLocatorInterface $locator) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php index 189eaa5fde15..16ddf87f8511 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php @@ -22,22 +22,17 @@ class IniFileLoader extends FileLoader { /** - * Loads a resource. - * - * @param mixed $file The resource - * @param string $type The resource type - * - * @throws InvalidArgumentException When ini file is not valid + * {@inheritdoc} */ - public function load($file, $type = null) + public function load($resource, $type = null) { - $path = $this->locator->locate($file); + $path = $this->locator->locate($resource); $this->container->addResource(new FileResource($path)); $result = parse_ini_file($path, true); if (false === $result || array() === $result) { - throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $file)); + throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $resource)); } if (isset($result['parameters']) && is_array($result['parameters'])) { @@ -48,12 +43,7 @@ public function load($file, $type = null) } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php index f3139ad70a82..08c1d9af4f65 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php @@ -24,18 +24,15 @@ class PhpFileLoader extends FileLoader { /** - * Loads a PHP file. - * - * @param mixed $file The resource - * @param string $type The resource type + * {@inheritdoc} */ - public function load($file, $type = null) + public function load($resource, $type = null) { // the container and loader variables are exposed to the included file below $container = $this->container; $loader = $this; - $path = $this->locator->locate($file); + $path = $this->locator->locate($resource); $this->setCurrentDir(dirname($path)); $this->container->addResource(new FileResource($path)); @@ -43,12 +40,7 @@ public function load($file, $type = null) } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 4147a403cdac..24104fd2ccdd 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -30,14 +30,11 @@ class XmlFileLoader extends FileLoader { /** - * Loads an XML file. - * - * @param mixed $file The resource - * @param string $type The resource type + * {@inheritdoc} */ - public function load($file, $type = null) + public function load($resource, $type = null) { - $path = $this->locator->locate($file); + $path = $this->locator->locate($resource); $xml = $this->parseFile($path); $xml->registerXPathNamespace('container', 'http://symfony.com/schema/dic/services'); @@ -61,12 +58,7 @@ public function load($file, $type = null) } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 8fee1bfefadc..a96cc39c06ac 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -32,14 +32,11 @@ class YamlFileLoader extends FileLoader private $yamlParser; /** - * Loads a Yaml file. - * - * @param mixed $file The resource - * @param string $type The resource type + * {@inheritdoc} */ - public function load($file, $type = null) + public function load($resource, $type = null) { - $path = $this->locator->locate($file); + $path = $this->locator->locate($resource); $content = $this->loadFile($path); @@ -56,7 +53,7 @@ public function load($file, $type = null) // parameters if (isset($content['parameters'])) { if (!is_array($content['parameters'])) { - throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $file)); + throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $resource)); } foreach ($content['parameters'] as $key => $value) { @@ -68,16 +65,11 @@ public function load($file, $type = null) $this->loadFromExtensions($content); // services - $this->parseDefinitions($content, $file); + $this->parseDefinitions($content, $resource); } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/HttpKernel/Config/FileLocator.php b/src/Symfony/Component/HttpKernel/Config/FileLocator.php index 47b543c15eeb..169c9ad6e502 100644 --- a/src/Symfony/Component/HttpKernel/Config/FileLocator.php +++ b/src/Symfony/Component/HttpKernel/Config/FileLocator.php @@ -47,7 +47,7 @@ public function __construct(KernelInterface $kernel, $path = null, array $paths */ public function locate($file, $currentPath = null, $first = true) { - if ('@' === $file[0]) { + if (isset($file[0]) && '@' === $file[0]) { return $this->kernel->locateResource($file, $this->path, $first); }