php Symfony-Component-Translation-Loader-ArrayLoader类(方法)实例源码

下面列出了php Symfony-Component-Translation-Loader-ArrayLoader 类(方法)源码代码实例,从而了解它的用法。

作者:sasede    项目:extra-tools-bundl   
/**
  *
  * {@inheritDoc} @see ArrayLoader::load()
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $messages = array();
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($resource, $domain);
     $messages = $this->parse($resource);
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:Dren-    项目:mobi   
/**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $messages = array();
     try {
         $file = new \SplFileObject($resource, 'rb');
     } catch (\RuntimeException $e) {
         throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
     }
     $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
     $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     foreach ($file as $data) {
         if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === count($data)) {
             $messages[$data[0]] = $data[1];
         }
     }
     $catalogue = parent::load($messages, $locale, $domain);
     if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
         $catalogue->addResource(new FileResource($resource));
     }
     return $catalogue;
 }

作者:nickaggarwa    项目:sample-symfony   
/**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $messages = (require $resource);
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:Dren-    项目:mobi   
/**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     if (!class_exists('Symfony\\Component\\Yaml\\Parser')) {
         throw new \LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
     }
     if (null === $this->yamlParser) {
         $this->yamlParser = new YamlParser();
     }
     try {
         $messages = $this->yamlParser->parse(file_get_contents($resource));
     } catch (ParseException $e) {
         throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
     }
     // empty file
     if (null === $messages) {
         $messages = array();
     }
     // not an array
     if (!is_array($messages)) {
         throw new InvalidResourceException(sprintf('The file "%s" must contain a YAML array.', $resource));
     }
     $catalogue = parent::load($messages, $locale, $domain);
     if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
         $catalogue->addResource(new FileResource($resource));
     }
     return $catalogue;
 }

作者:robertowes    项目:CuteFlow-V   
/**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $messages = array();
     try {
         $file = new \SplFileObject($resource, 'rb');
     } catch (\RuntimeException $e) {
         throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
     }
     $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
     $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     foreach ($file as $data) {
         if (substr($data[0], 0, 1) === '#') {
             continue;
         }
         if (!isset($data[1])) {
             continue;
         }
         if (count($data) == 2) {
             $messages[$data[0]] = $data[1];
         } else {
             continue;
         }
     }
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:tomasstrejce    项目:Translatio   
/**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     try {
         $messages = Neon\Neon::decode(file_get_contents($resource));
     } catch (Nette\Utils\NeonException $e) {
         throw new InvalidResourceException(sprintf("Error parsing Neon: %s", $e->getMessage()), 0, $e);
     } catch (Nette\Neon\Exception $e) {
         throw new InvalidResourceException(sprintf("Error parsing Neon: %s", $e->getMessage()), 0, $e);
     }
     if (empty($messages)) {
         $messages = array();
     }
     if (!is_array($messages)) {
         throw new InvalidResourceException(sprintf('The file "%s" must contain a Neon array.', $resource));
     }
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:tahermarko    项目:Transpor   
/**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     if (null === $this->yamlParser) {
         $this->yamlParser = new YamlParser();
     }
     try {
         $messages = $this->yamlParser->parse(file_get_contents($resource));
     } catch (ParseException $e) {
         throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
     }
     // empty file
     if (null === $messages) {
         $messages = array();
     }
     // not an array
     if (!is_array($messages)) {
         throw new InvalidResourceException(sprintf('The file "%s" must contain a YAML array.', $resource));
     }
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:Gregwa    项目:symfon   
/**
     * {@inheritdoc}
     */
    public function load($resource, $locale, $domain = 'messages')
    {
        $messages = array();
        $file = @fopen($resource, 'rb');
        if (!$file) {
            throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
        }

        while (($data = fgetcsv($file, 0, ';')) !== false) {
            if (substr($data[0], 0, 1) === '#') {
                continue;
            }

            if (!isset($data[1])) {
                continue;
            }

            if (count($data) == 2) {
                $messages[$data[0]] = $data[1];
            } else {
                 continue;
            }
        }

        $catalogue = parent::load($messages, $locale, $domain);
        $catalogue->addResource(new FileResource($resource));

        return $catalogue;
    }

作者:selmanoun    项目:blue-line   
/**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $dataCatalogue = new DataCatalogue();
     $dataCatalogue->load($resource, 'json', $locale);
     $messages = $dataCatalogue->getMessages();
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:unkerro    项目:Budabo   
/**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
     }
     $messages = (require $resource);
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:vvva    项目:spira   
/**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     return parent::load(require $resource, $locale, $domain);
 }

作者:laubosslin    项目:la   
/**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!is_file($resource)) {
         throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
     }
     $messages = parse_ini_file($resource, true);
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:NikoNic    项目:EventsBerr   
/**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $messages = parse_ini_file($resource, true);
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:EnmanuelCod    项目:backend-larave   
/**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $messages = (require $resource);
     $catalogue = parent::load($messages, $locale, $domain);
     if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
         $catalogue->addResource(new FileResource($resource));
     }
     return $catalogue;
 }

作者:neokenso    项目:symfon   
public function load($resource, $locale, $domain = 'messages')
 {
     $messages = $this->parse($resource);
     // empty file
     if (null === $messages) {
         $messages = array();
     }
     // not an array
     if (!is_array($messages)) {
         throw new \InvalidArgumentException(sprintf('The file "%s" must contain a valid mo file.', $resource));
     }
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:devtur    项目:silex-localization-bundl   
public function load($resource, $locale, $domain = 'messages')
 {
     $contents = file_get_contents($resource);
     $messages = array();
     if ($contents !== '') {
         $messages = json_decode($contents, 1);
         if (json_last_error() !== JSON_ERROR_NONE) {
             throw new \InvalidArgumentException(sprintf('The file "%s" cannot be JSON-decoded: %s.', $resource, json_last_error_msg()));
         }
     }
     if (!is_array($messages)) {
         throw new \InvalidArgumentException(sprintf('The file "%s" must contain a JSON array.', $resource));
     }
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:kchhainaron    项目:chantuch   
/**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $messages = json_decode(file_get_contents($resource), true);
     if (0 < ($errorCode = json_last_error())) {
         throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode)));
     }
     if (null === $messages) {
         $messages = array();
     }
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }

作者:jacobjj    项目:PageKit-framewor   
public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $messages = $this->parse($resource);
     // empty file
     if (null === $messages) {
         $messages = [];
     }
     // not an array
     if (!is_array($messages)) {
         throw new InvalidResourceException(sprintf('The file "%s" must contain a valid po file.', $resource));
     }
     return parent::load($messages, $locale, $domain);
 }

作者:ngitimfoy    项目:Nyari-AppPH   
public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $messages = $this->parse($resource);
     // empty file
     if (null === $messages) {
         $messages = array();
     }
     // not an array
     if (!is_array($messages)) {
         throw new InvalidResourceException(sprintf('The file "%s" must contain a valid mo file.', $resource));
     }
     $catalogue = parent::load($messages, $locale, $domain);
     if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
         $catalogue->addResource(new FileResource($resource));
     }
     return $catalogue;
 }

作者:dongilber    项目:mauti   
/**
  * Load the translation into the catalogue.
  *
  * @param $catalogue
  * @param $locale
  * @param $file
  */
 private function loadTranslations($catalogue, $locale, $file)
 {
     $iniFile = $file->getRealpath();
     $messages = parse_ini_file($iniFile, true);
     $domain = substr($file->getFilename(), 0, -4);
     $thisCatalogue = parent::load($messages, $locale, $domain);
     $catalogue->addCatalogue($thisCatalogue);
 }


问题


面经


文章

微信
公众号

扫码关注公众号