Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Translation\Loader; Chris@0: Chris@0: use Symfony\Component\Translation\Exception\InvalidResourceException; Chris@0: use Symfony\Component\Translation\Exception\LogicException; Chris@0: use Symfony\Component\Yaml\Parser as YamlParser; Chris@0: use Symfony\Component\Yaml\Exception\ParseException; Chris@0: Chris@0: /** Chris@0: * YamlFileLoader loads translations from Yaml files. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class YamlFileLoader extends FileLoader Chris@0: { Chris@0: private $yamlParser; Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function loadResource($resource) Chris@0: { Chris@0: if (null === $this->yamlParser) { Chris@0: if (!class_exists('Symfony\Component\Yaml\Parser')) { Chris@0: throw new LogicException('Loading translations from the YAML format requires the Symfony Yaml component.'); Chris@0: } Chris@0: Chris@0: $this->yamlParser = new YamlParser(); Chris@0: } Chris@0: Chris@0: try { Chris@0: $messages = $this->yamlParser->parse(file_get_contents($resource)); Chris@0: } catch (ParseException $e) { Chris@0: throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e); Chris@0: } Chris@0: Chris@0: return $messages; Chris@0: } Chris@0: }