annotate vendor/symfony/translation/Loader/YamlFileLoader.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\Translation\Loader;
Chris@0 13
Chris@0 14 use Symfony\Component\Translation\Exception\InvalidResourceException;
Chris@0 15 use Symfony\Component\Translation\Exception\LogicException;
Chris@17 16 use Symfony\Component\Yaml\Exception\ParseException;
Chris@0 17 use Symfony\Component\Yaml\Parser as YamlParser;
Chris@0 18
Chris@0 19 /**
Chris@0 20 * YamlFileLoader loads translations from Yaml files.
Chris@0 21 *
Chris@0 22 * @author Fabien Potencier <fabien@symfony.com>
Chris@0 23 */
Chris@0 24 class YamlFileLoader extends FileLoader
Chris@0 25 {
Chris@0 26 private $yamlParser;
Chris@0 27
Chris@0 28 /**
Chris@0 29 * {@inheritdoc}
Chris@0 30 */
Chris@0 31 protected function loadResource($resource)
Chris@0 32 {
Chris@0 33 if (null === $this->yamlParser) {
Chris@0 34 if (!class_exists('Symfony\Component\Yaml\Parser')) {
Chris@0 35 throw new LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
Chris@0 36 }
Chris@0 37
Chris@0 38 $this->yamlParser = new YamlParser();
Chris@0 39 }
Chris@0 40
Chris@14 41 $prevErrorHandler = set_error_handler(function ($level, $message, $script, $line) use ($resource, &$prevErrorHandler) {
Chris@14 42 $message = E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$resource.'"$0', $message) : $message;
Chris@14 43
Chris@14 44 return $prevErrorHandler ? $prevErrorHandler($level, $message, $script, $line) : false;
Chris@14 45 });
Chris@14 46
Chris@0 47 try {
Chris@14 48 $messages = $this->yamlParser->parseFile($resource);
Chris@0 49 } catch (ParseException $e) {
Chris@0 50 throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
Chris@14 51 } finally {
Chris@14 52 restore_error_handler();
Chris@0 53 }
Chris@0 54
Chris@0 55 return $messages;
Chris@0 56 }
Chris@0 57 }