예제 #1
0
 private function loadLanguageCatalog($languageCode, $languageCatalog)
 {
     if (preg_match('/^[a-z][a-z]$/', $languageCode) == 0) {
         throw new \InvalidArgumentException(sprintf('%s: Language code must be a valid ISO 639-1 language code', get_class($this)), 1322150170);
     }
     if (preg_match('/^[a-z_A-Z0-9]+$/', $languageCatalog) == 0) {
         throw new \InvalidArgumentException(sprintf("%s: Language catalog name can contain only alphanumeric or `_` characters. It was `%s`.", get_class($this), $languageCatalog), 1322150265);
     }
     $filePath = call_user_func($this->catalogResolver, $languageCode, $languageCatalog);
     $L = array();
     $tmp = $this->getLog()->getLevel();
     $this->getLog()->setLevel($tmp & ~E_WARNING);
     $included = $this->phpWrapper->phpInclude($filePath, array('L' => &$L));
     $this->getLog()->setLevel($tmp);
     if ($included) {
         NETHGUI_DEBUG && $this->getLog()->notice(sprintf('%s: Loaded language catalog `%s` [%s].', get_class($this), $languageCatalog, $languageCode));
     } else {
         NETHGUI_DEBUG && $this->getLog()->warning(sprintf('%s: Missing language catalog `%s` [%s].', get_class($this), $languageCatalog, $languageCode));
     }
     $this->catalogs[$languageCode][$languageCatalog] =& $L;
 }
예제 #2
0
 /**
  * Renders a view passing $viewState as view parameters.
  *
  * @param string|callable $view Full view name that follows class naming convention or function callback
  * @param array $viewState Array of view parameters.
  * @return string
  */
 protected function renderView($template, $viewState)
 {
     if ($template === FALSE) {
         $viewOutput = '';
     } elseif (is_callable($template)) {
         // Rendered by callback function
         $viewOutput = (string) call_user_func_array($template, $viewState);
     } elseif (is_string($template)) {
         $absoluteViewPath = call_user_func($this->getTemplateResolver(), $template);
         if (!$absoluteViewPath) {
             $this->getLog()->warning("Unable to load `{$template}`.");
             return '';
         }
         // Rendered by PHP script
         ob_start();
         $this->phpWrapper->phpInclude($absoluteViewPath, $viewState);
         $viewOutput = ob_get_contents();
         ob_end_clean();
     } else {
         throw new \UnexpectedValueException(sprintf("%s: wrong template type `%s`.", get_class($this), is_object($template) ? get_class($template) : gettype($template)), 1324479415);
     }
     return $viewOutput;
 }
예제 #3
0
 public function phpInclude($filePath, $vars)
 {
     switch ($filePath) {
         case 'Nethgui\\Language\\xy\\Nethgui_Basic':
             $vars['L']['SYM_UNTRANSLATED'] = 'SYM_TRANSLATED1';
             break;
         case 'Nethgui\\Language\\xy\\Nethgui_ModuleCatalog':
             $vars['L']['SYM_INTERPOLATE1'] = 'SYM_TRANSLATED3 ${0} ${1} ${2}';
             $vars['L']['SYM_INTERPOLATE2'] = 'SYM_TRANSLATED4 ${:x} ${:y} ${:z}';
             break;
         case 'Nethgui\\Language\\en\\Nethgui_ModuleCatalog':
             $vars['L']['SYM_ENGLISH_FALLBACK'] = 'SYM_TRANSLATED2';
             break;
         case 'Nethgui\\Language\\xy\\Nethgui_ParentCatalog1':
             $vars['L']['FROM_PARENT_CATALOG1'] = 'SYM_TRANSLATED7a';
             break;
         case 'Nethgui\\Language\\xy\\Nethgui_ParentCatalog2':
             $vars['L']['FROM_PARENT_CATALOG2'] = 'SYM_TRANSLATED7b';
             break;
         default:
             return parent::phpInclude($filePath, $vars);
     }
     return TRUE;
 }