diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index cf68a33756..ce135fa81f 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -18,7 +18,7 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\Yaml\Yaml; +use Symfony\Component\Yaml\Parser as YamlParser; /** * YamlFileLoader loads YAML files service definitions. @@ -29,6 +29,8 @@ use Symfony\Component\Yaml\Yaml; */ class YamlFileLoader extends FileLoader { + private $yamlParser; + /** * Loads a Yaml file. * @@ -243,7 +245,19 @@ class YamlFileLoader extends FileLoader */ protected function loadFile($file) { - return $this->validate(Yaml::parse($file), $file); + if (!stream_is_local($file)) { + throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file)); + } + + if (!file_exists($file)) { + throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file)); + } + + if (null === $this->yamlParser) { + $this->yamlParser = new YamlParser(); + } + + return $this->validate($this->yamlParser->parse(file_get_contents($file)), $file); } /** diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index a3cf2f1c00..9deea7fe4f 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -14,7 +14,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\Yaml\Yaml; +use Symfony\Component\Yaml\Parser as YamlParser; use Symfony\Component\Config\Loader\FileLoader; /** @@ -30,6 +30,7 @@ class YamlFileLoader extends FileLoader private static $availableKeys = array( 'resource', 'type', 'prefix', 'pattern', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options', ); + private $yamlParser; /** * Loads a Yaml file. @@ -47,7 +48,19 @@ class YamlFileLoader extends FileLoader { $path = $this->locator->locate($file); - $config = Yaml::parse($path); + if (!stream_is_local($path)) { + throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path)); + } + + if (!file_exists($path)) { + throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path)); + } + + if (null === $this->yamlParser) { + $this->yamlParser = new YamlParser(); + } + + $config = $this->yamlParser->parse(file_get_contents($path)); $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); diff --git a/src/Symfony/Component/Translation/Loader/YamlFileLoader.php b/src/Symfony/Component/Translation/Loader/YamlFileLoader.php index 232ee2bca3..66ab2ba529 100644 --- a/src/Symfony/Component/Translation/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/YamlFileLoader.php @@ -14,7 +14,7 @@ namespace Symfony\Component\Translation\Loader; use Symfony\Component\Translation\Exception\InvalidResourceException; use Symfony\Component\Translation\Exception\NotFoundResourceException; use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\Yaml\Yaml; +use Symfony\Component\Yaml\Parser as YamlParser; use Symfony\Component\Yaml\Exception\ParseException; /** @@ -26,6 +26,8 @@ use Symfony\Component\Yaml\Exception\ParseException; */ class YamlFileLoader extends ArrayLoader implements LoaderInterface { + private $yamlParser; + /** * {@inheritdoc} * @@ -41,8 +43,12 @@ class YamlFileLoader extends ArrayLoader implements LoaderInterface throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); } + if (null === $this->yamlParser) { + $this->yamlParser = new YamlParser(); + } + try { - $messages = Yaml::parse($resource); + $messages = $this->yamlParser->parse(file_get_contents($resource)); } catch (ParseException $e) { throw new InvalidResourceException('Error parsing YAML.', 0, $e); } diff --git a/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php index 57fe2a55f8..9b3757d522 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php @@ -12,10 +12,12 @@ namespace Symfony\Component\Validator\Mapping\Loader; use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Component\Yaml\Yaml; +use Symfony\Component\Yaml\Parser as YamlParser; class YamlFileLoader extends FileLoader { + private $yamlParser; + /** * An array of YAML class descriptions * @@ -29,7 +31,19 @@ class YamlFileLoader extends FileLoader public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { - $this->classes = Yaml::parse($this->file); + if (!stream_is_local($this->file)) { + throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $this->file)); + } + + if (!file_exists($this->file)) { + throw new \InvalidArgumentException(sprintf('File "%s" not found.', $this->file)); + } + + if (null === $this->yamlParser) { + $this->yamlParser = new YamlParser(); + } + + $this->classes = $this->yamlParser->parse(file_get_contents($this->file)); // empty file if (null === $this->classes) {