Пример #1
0
 /**
  * Template parser
  *
  * @param string $view raw template
  * @param mixed  $path path for inheritance
  *
  * @return string
  */
 public function parse($view, $path = null)
 {
     foreach (self::$rules as $rx => $call) {
         $view = preg_replace_callback($rx, $call, $view);
     }
     $inherit = new Inherit($this->ant);
     $view = $inherit->extend($view, $path);
     $view = preg_replace_callback('/@skip.+?@endskip/ms', '\\Ant\\Parser::skip', $view);
     $view = preg_replace_callback('/@php.+?@endphp/ms', '\\Ant\\Parser::skip', $view);
     $view = preg_replace_callback('/{{--.*?--}}/ms', '\\Ant\\Parser::comment', $view);
     $view = preg_replace_callback('/(\\x5c)?{{{.+?}}}/ms', '\\Ant\\Parser::variable', $view);
     $view = preg_replace_callback('/(\\x5c)?{{.+?}}/ms', '\\Ant\\Parser::escape', $view);
     $view = preg_replace_callback('/\\B@(import|widget).+/', '\\Ant\\Parser::import', $view);
     $view = preg_replace_callback('/\\B@(css|js).+/', '\\Ant\\Parser::shortcut', $view);
     $view = preg_replace_callback('/[\\s\\t]+@(case|default)/', '\\Ant\\Parser::caseSpace', $view);
     $view = preg_replace_callback('/\\B@(forelse|foreach|for|while|switch|case|default|if|elseif|else|unless|each)([ \\t]*)(\\( ( (?>[^()]+) | (?3) )* \\))?/x', '\\Ant\\Parser::control', $view);
     $view = preg_replace_callback('/\\B@(empty|break|continue|endforeach|endforelse|endfor|endwhile|endswitch|endif|endunless)/', '\\Ant\\Parser::endControl', $view);
     $view = preg_replace('/\\B::/', '$this->ant->', $view);
     if (self::$skips) {
         $view = str_replace(array_keys(self::$skips), array_values(self::$skips), $view);
         self::$skips = array();
     }
     $view = str_replace(array('@php', '@endphp', '@skip', '@endskip'), array('<?php', '?>', '', ''), $view);
     return $view;
 }
Пример #2
0
 public static function extend($view, $path)
 {
     $chain = self::resolveChain($view, $path);
     $view = array_shift($chain);
     foreach ($chain as $item) {
         $injects = array();
         preg_match_all('/@inject.*?@(rewrite|append|prepend)/ms', $item, $injects);
         $map = array();
         if (isset($injects[0])) {
             foreach ($injects[0] as $k => $s) {
                 $m = array();
                 preg_match('/@inject.+?\\)/', $s, $m);
                 $name = trim(str_replace(array('@inject', '(', ')', '"', '\''), '', $m[0]));
                 $map[] = array($name, trim(self::clear($s)), $injects[1][$k]);
             }
         }
         foreach ($map as $key => $value) {
             $view = preg_replace_callback('/@block\\s*?\\(\\s*?(\'|")' . $value[0] . '(\'|")\\s*?\\).*?@endblock/ms', function ($e) use($value) {
                 switch ($value[2]) {
                     case 'prepend':
                         return '@block(\'' . $value[0] . '\')' . $value[1] . Inherit::clear($e[0]) . '@endblock';
                         break;
                     case 'append':
                         return '@block(\'' . $value[0] . '\')' . Inherit::clear($e[0]) . $value[1] . '@endblock';
                         break;
                     case 'rewrite':
                         return '@block(\'' . $value[0] . '\')' . $value[1] . '@endblock';
                         break;
                 }
             }, $view);
         }
     }
     return self::clear($view);
 }
Пример #3
0
 function actionRemoveInheritance($parent, $child, $to)
 {
     $m = Inherit::model()->findByPk(array('parent' => $parent, 'child' => $child));
     if ($m != null) {
         $m->delete();
     }
     $this->redirect(array('view', 'id' => $to));
 }