Esempio n. 1
0
 /**
  * @param string $templatePath
  * @param array $data
  *
  * @return string
  */
 public static function renderTemplate(string $templatePath, array $data = []) : string
 {
     if (substr($templatePath, 0, 1) != '/') {
         $templatePath = AbstractApp::getAppRoot() . '/' . $templatePath;
     }
     $phtml = new static($templatePath);
     $phtml->addDatas($data);
     return $phtml->render();
 }
Esempio n. 2
0
 /**
  * @return string
  */
 public function render()
 {
     if (!self::$renderer) {
         $loader = new Twig_Loader_Filesystem();
         $loader->prependPath('/');
         $twig = new Twig_Environment($loader, ['cache' => AbstractApp::getAppRoot() . '/cache/twig']);
         self::$renderer = $twig;
     }
     if (empty($this->templatePath)) {
         $this->setTemplatePath();
     }
     $template = self::$renderer->loadTemplate($this->templatePath . '.twig');
     return $template->render($this->getData());
 }
Esempio n. 3
0
 /**
  * @param string $name
  * @param string $rename
  * @param bool $appendLang
  *
  * @return bool
  */
 public function addFile(string $name, string $rename = null, bool $appendLang = true) : bool
 {
     if (substr($name, 0, 1) == '/') {
         $path = $name;
         if (is_null($rename)) {
             throw new \LogicException(sprintf("Missing rename parameter on '%s'", $name));
         }
         $name = $rename;
     } else {
         $path = AbstractApp::getAppRoot() . '/lang/' . $name;
     }
     if ($appendLang) {
         $path .= '.' . $this->locale . '.php';
     } else {
         $path .= '.php';
     }
     if (!file_exists($path)) {
         throw new \InvalidArgumentException(sprintf("Invalid locale files path '%s'", $name));
     }
     /* @noinspection PhpIncludeInspection */
     $data = (require $path);
     if (!is_array($data)) {
         throw new \LogicException(sprintf("Invalid locale files '%' format, must be a php array", $path));
     }
     $this->translations[$name] = $data;
     return true;
 }