Exemplo n.º 1
0
 public function read($path, $locale)
 {
     $fileName = $this->resolve($path, $locale);
     if (!file_exists($fileName)) {
         throw FileNotFoundException::create($fileName);
     }
     if (!is_file($fileName)) {
         throw FileNotFoundException::create($fileName);
     }
     $data = json_decode(file_get_contents($fileName), true);
     if (null === $data) {
         throw InvalidJsonException::create($fileName, self::getLastJsonError());
     }
     return $data;
 }
Exemplo n.º 2
0
 public function read($path, $locale)
 {
     $locale = (string) $locale;
     $locales = array();
     if ('' !== $locale) {
         $locales[] = $locale;
         if (false !== strpos($locale, '_')) {
             // en_US -> en
             list($parent) = explode('_', $locale, 2);
             $locales[] = $parent;
         }
     }
     $locales[] = ReaderInterface::ROOT_LOCALE;
     $files = array();
     foreach ($locales as $locale) {
         try {
             return $this->reader->read($path, $locale);
         } catch (FileNotFoundException $e) {
             $files[] = $this->reader->resolve($path, $locale);
         }
     }
     throw FileNotFoundException::create($files);
 }