Esempio n. 1
0
 /**
  * @param string $message
  * @param null $locale
  *
  * @return string
  *
  * @throws TranslationEmptyLocaleException
  * @throws TranslationFileNotFoundException
  */
 public function translate($message, $locale)
 {
     if ($locale === null) {
         throw new TranslationEmptyLocaleException(sprintf('translation locale can\'t be empty'));
     }
     $message = (string) $message;
     $locale = strtolower($locale);
     $translationFile = "{$this->getTranslationDir()}/messages.{$locale}.ini";
     if (!file_exists($translationFile)) {
         throw new TranslationFileNotFoundException(sprintf('translation file "%s" not found', $translationFile));
     }
     if (!isset($this->translations[$locale])) {
         $this->translations[$locale] = $this->fileLoader->load($translationFile);
     }
     $trans = $this->translations[$locale];
     return !empty($trans->{$message}) ? $trans->{$message} : $message;
 }
Esempio n. 2
0
 /**
  * Load configuration file
  *
  * @param string $configFile The config file
  *
  * @throws ResourceKeyNotFoundException
  */
 public function loadConfig($configFile)
 {
     if (false !== $this->configLoaded) {
         return;
     }
     $this->configLoaded = true;
     $this->configRealPath = dirname($configFile);
     $this->resources = $this->fileLoader->load($configFile);
     // Application
     if (!isset($this->resources->{self::APPLICATION_SECTION})) {
         throw new ResourceKeyNotFoundException(sprintf('section key "[%s]" not declared in resources', self::APPLICATION_SECTION));
     }
     // Cache directory
     if (!isset($this->resources->{self::APPLICATION_SECTION}->{self::CACHE_KEY})) {
         throw new ResourceKeyNotFoundException(sprintf('key "%s" not declared in resources [%s] section', self::CACHE_KEY, self::APPLICATION_SECTION));
     }
     $this->cacheDir = $this->configRealPath . DIRECTORY_SEPARATOR . $this->resources->{self::APPLICATION_SECTION}->{self::CACHE_KEY};
     // Logs directory
     if (!isset($this->resources->{self::APPLICATION_SECTION}->{self::LOGS_KEY})) {
         throw new ResourceKeyNotFoundException(sprintf('key "%s" not declared in resources [%s] section', self::LOGS_KEY, self::APPLICATION_SECTION));
     }
     $this->logsDir = $this->configRealPath . DIRECTORY_SEPARATOR . $this->resources->{self::APPLICATION_SECTION}->{self::LOGS_KEY};
     // Transation directory
     if (!isset($this->resources->{self::APPLICATION_SECTION}->{self::TRANSLATION_KEY})) {
         throw new ResourceKeyNotFoundException(sprintf('resource key "%s" not declared in resources [%s] section', self::TRANSLATION_KEY, self::APPLICATION_SECTION));
     }
     $this->translationDir = $this->configRealPath . DIRECTORY_SEPARATOR . $this->resources->{self::APPLICATION_SECTION}->{self::TRANSLATION_KEY};
     // Routes file
     if (!isset($this->resources->{self::APPLICATION_SECTION}->{self::ROUTING_KEY})) {
         throw new ResourceKeyNotFoundException(sprintf('key "%s" not declared in resources [%s] section', self::ROUTING_KEY, self::APPLICATION_SECTION));
     }
     $routesFile = $this->configRealPath . DIRECTORY_SEPARATOR . $this->resources->{self::APPLICATION_SECTION}->{self::ROUTING_KEY};
     $this->routes = $this->fileLoader->load($routesFile);
     // Filters file
     if (!isset($this->resources->{self::APPLICATION_SECTION}->{self::FILTERS_KEY})) {
         throw new ResourceKeyNotFoundException(sprintf('key "%s" not declared in resources [%s] section', self::FILTERS_KEY, self::APPLICATION_SECTION));
     }
     $filtersFile = $this->configRealPath . DIRECTORY_SEPARATOR . $this->resources->{self::APPLICATION_SECTION}->{self::FILTERS_KEY};
     $this->filters = $this->fileLoader->load($filtersFile);
     // Template directory
     if (!isset($this->resources->{self::APPLICATION_SECTION}->{self::TEMPLATE_KEY})) {
         throw new ResourceKeyNotFoundException(sprintf('key "%s" not declared in resources [%s] section', self::TEMPLATE_KEY, self::APPLICATION_SECTION));
     }
     $this->templateDir = $this->configRealPath . DIRECTORY_SEPARATOR . $this->resources->{self::APPLICATION_SECTION}->{self::TEMPLATE_KEY};
     // Default Locale
     if (!isset($this->resources->{self::APPLICATION_SECTION}->{self::LOCALE_KEY})) {
         throw new ResourceKeyNotFoundException(sprintf('resource key "%s" not declared in resources [%s] section', self::LOCALE_KEY, self::APPLICATION_SECTION));
     }
     $this->defaultLocale = $this->resources->{self::APPLICATION_SECTION}->{self::LOCALE_KEY};
 }
Esempio n. 3
0
 protected function setUp()
 {
     $this->fileLoader = FileLoader::getInstance();
 }
Esempio n. 4
0
 protected function setUp()
 {
     $this->fileLoader = FileLoader::getInstance();
     $this->translator = new Translator($this->fileLoader);
 }