コード例 #1
0
ファイル: Engine.php プロジェクト: prcharom/w-pps-reality
 /**
  * Compiles template to PHP code.
  * @return string
  */
 public function compile($name)
 {
     foreach ($this->onCompile ?: array() as $cb) {
         call_user_func(Helpers::checkCallback($cb), $this);
     }
     $this->onCompile = array();
     $source = $this->getLoader()->getContent($name);
     try {
         $tokens = $this->getParser()->setContentType($this->contentType)->parse($source);
         $code = $this->getCompiler()->setContentType($this->contentType)->compile($tokens);
         if (preg_match('#^\\S{5,100}\\z#', $name)) {
             $code = "<?php\n// source: {$name}\n?>" . $code;
         }
     } catch (\Exception $e) {
         $e = $e instanceof CompileException ? $e : new CompileException("Thrown exception '{$e->getMessage()}'", NULL, $e);
         throw $e->setSource($source, $this->getCompiler()->getLine(), $name);
     }
     $code = Helpers::optimizePhp($code);
     return $code;
 }
コード例 #2
0
ファイル: Engine.php プロジェクト: nette/latte
 /**
  * Compiles template to PHP code.
  * @return string
  */
 public function compile($name)
 {
     foreach ($this->onCompile ?: [] as $cb) {
         call_user_func(Helpers::checkCallback($cb), $this);
     }
     $this->onCompile = [];
     $source = $this->getLoader()->getContent($name);
     try {
         $tokens = $this->getParser()->setContentType($this->contentType)->parse($source);
         $code = $this->getCompiler()->setContentType($this->contentType)->compile($tokens, $this->getTemplateClass($name));
     } catch (\Exception $e) {
         if (!$e instanceof CompileException) {
             $e = new CompileException("Thrown exception '{$e->getMessage()}'", NULL, $e);
         }
         $line = isset($tokens) ? $this->getCompiler()->getLine() : $this->getParser()->getLine();
         throw $e->setSource($source, $line, $name);
     }
     if (!preg_match('#\\n|\\?#', $name)) {
         $code = "<?php\n// source: {$name}\n?>" . $code;
     }
     $code = PhpHelpers::reformatCode($code);
     return $code;
 }
コード例 #3
0
ファイル: Engine.php プロジェクト: sallyx/latte
 /**
  * Call a run-time filter.
  * @param  string  filter name
  * @param  array   arguments
  * @return mixed
  */
 public function invokeFilter($name, array $args)
 {
     $lname = strtolower($name);
     if (!isset($this->filters[$lname])) {
         $args2 = $args;
         array_unshift($args2, $lname);
         foreach ($this->filters[NULL] as $filter) {
             $res = call_user_func_array(Helpers::checkCallback($filter), $args2);
             if ($res !== NULL) {
                 return $res;
             } elseif (isset($this->filters[$lname])) {
                 return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args);
             }
         }
         $hint = ($t = Helpers::getSuggestion(array_keys($this->filters), $name)) ? ", did you mean '{$t}'?" : '.';
         throw new \LogicException("Filter '{$name}' is not defined{$hint}");
     }
     return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args);
 }
コード例 #4
0
ファイル: Engine.php プロジェクト: novasky/latte
 /**
  * Call a run-time filter.
  * @param  string  filter name
  * @param  array   arguments
  * @return mixed
  */
 public function invokeFilter($name, array $args)
 {
     $lname = strtolower($name);
     if (!isset($this->filters[$lname])) {
         $args2 = $args;
         array_unshift($args2, $lname);
         foreach ($this->filters[NULL] as $filter) {
             $res = call_user_func_array(Helpers::checkCallback($filter), $args2);
             if ($res !== NULL) {
                 return $res;
             } elseif (isset($this->filters[$lname])) {
                 return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args);
             }
         }
         throw new \LogicException("Filter '{$name}' is not defined.");
     }
     return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args);
 }
コード例 #5
0
ファイル: Template.php プロジェクト: prcharom/w-pps-reality
 /**
  * Call a template run-time filter. Do not call directly.
  * @param  string  filter name
  * @param  array   arguments
  * @return mixed
  */
 public function __call($name, $args)
 {
     $lname = strtolower($name);
     if (!isset($this->filters[$lname])) {
         $args2 = $args;
         array_unshift($args2, $lname);
         foreach ($this->filters[NULL] as $filter) {
             $res = call_user_func_array(Helpers::checkCallback($filter), $args2);
             if ($res !== NULL) {
                 return $res;
             } elseif (isset($this->filters[$lname])) {
                 return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args);
             }
         }
         return parent::__call($name, $args);
     }
     return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args);
 }