Exemplo n.º 1
0
 /**
  * Constructor
  *
  * @param string $markup
  * @param array $tokens
  * @param LiquidFileSystem $file_system
  * @return AssignLiquidTag
  */
 public function __construct($markup, &$tokens, &$file_system)
 {
     $syntax_regexp = new LiquidRegexp('/(\\w+)\\s*=\\s*(' . LIQUID_QUOTED_FRAGMENT . '+)/');
     $filter_seperator_regexp = new LiquidRegexp('/' . LIQUID_FILTER_SEPARATOR . '\\s*(.*)/');
     $filter_split_regexp = new LiquidRegexp('/' . LIQUID_FILTER_SEPARATOR . '/');
     $filter_name_regexp = new LiquidRegexp('/\\s*(\\w+)/');
     $filter_argument_regexp = new LiquidRegexp('/(?:' . LIQUID_FILTER_ARGUMENT_SEPARATOR . '|' . LIQUID_ARGUMENT_SEPARATOR . ')\\s*(' . LIQUID_QUOTED_FRAGMENT . ')/');
     $this->filters = array();
     if ($filter_seperator_regexp->match($markup)) {
         $filters = $filter_split_regexp->split($filter_seperator_regexp->matches[1]);
         foreach ($filters as $filter) {
             $filter_name_regexp->match($filter);
             $filtername = $filter_name_regexp->matches[1];
             $filter_argument_regexp->match_all($filter);
             $matches = Liquid::array_flatten($filter_argument_regexp->matches[1]);
             array_push($this->filters, array($filtername, $matches));
         }
     }
     if ($syntax_regexp->match($markup)) {
         $this->_to = $syntax_regexp->matches[1];
         $this->_from = $syntax_regexp->matches[2];
     } else {
         throw new LiquidException("Syntax Error in 'assign' - Valid syntax: assign [var] = [source]");
     }
 }
 /**
  * Constructor
  *
  * @param string $markup
  * @return LiquidVariable
  */
 public function __construct($markup)
 {
     $this->markup = $markup;
     $quoted_fragment_regexp = new LiquidRegexp('/\\s*(' . LIQUID_QUOTED_FRAGMENT . ')/');
     $filter_seperator_regexp = new LiquidRegexp('/' . LIQUID_FILTER_SEPARATOR . '\\s*(.*)/');
     $filter_split_regexp = new LiquidRegexp('/' . LIQUID_FILTER_SEPARATOR . '/');
     $filter_name_regexp = new LiquidRegexp('/\\s*(\\w+)/');
     $filter_argument_regexp = new LiquidRegexp('/(?:' . LIQUID_FILTER_ARGUMENT_SEPARATOR . '|' . LIQUID_ARGUMENT_SEPARATOR . ')\\s*(' . LIQUID_QUOTED_FRAGMENT . ')/');
     $quoted_fragment_regexp->match($markup);
     //$this->_name = $quoted_fragment_regexp->matches[1];
     $this->_name = isset($quoted_fragment_regexp->matches[1]) ? $quoted_fragment_regexp->matches[1] : null;
     // harry
     if ($filter_seperator_regexp->match($markup)) {
         $filters = $filter_split_regexp->split($filter_seperator_regexp->matches[1]);
         foreach ($filters as $filter) {
             $filter_name_regexp->match($filter);
             $filtername = $filter_name_regexp->matches[1];
             $filter_argument_regexp->match_all($filter);
             //$matches = array_flatten($filter_argument_regexp->matches[1]);
             $matches = Liquid::array_flatten($filter_argument_regexp->matches[1]);
             $this->filters[] = array($filtername, $matches);
         }
     } else {
         $this->filters = array();
     }
 }
 /**
  * Render the tag
  *
  * @param LiquidContext $context
  */
 public function render(&$context)
 {
     $context->push();
     $logicalRegex = new LiquidRegexp('/\\s+(and|or)\\s+/');
     $conditionalRegex = new LiquidRegexp('/(' . LIQUID_QUOTED_FRAGMENT . ')\\s*([=!<>a-z_]+)?\\s*(' . LIQUID_QUOTED_FRAGMENT . ')?/');
     $result = '';
     foreach ($this->_blocks as $i => $block) {
         if ($block[0] == 'else') {
             $result = $this->render_all($block[2], $context);
             break;
         }
         if ($block[0] == 'if' || $block[0] == 'elsif') {
             /* Extract logical operators */
             $logicalRegex->match($block[1]);
             $logicalOperators = $logicalRegex->matches;
             array_shift($logicalOperators);
             /* Extract individual conditions */
             $temp = $logicalRegex->split($block[1]);
             $conditions = array();
             foreach ($temp as $condition) {
                 if ($conditionalRegex->match($condition)) {
                     $left = isset($conditionalRegex->matches[1]) ? $conditionalRegex->matches[1] : null;
                     $operator = isset($conditionalRegex->matches[2]) ? $conditionalRegex->matches[2] : null;
                     $right = isset($conditionalRegex->matches[3]) ? $conditionalRegex->matches[3] : null;
                     array_push($conditions, array('left' => $left, 'operator' => $operator, 'right' => $right));
                 } else {
                     throw new LiquidException("Syntax Error in tag 'if' - Valid syntax: if [condition]");
                 }
             }
             if (count($logicalOperators)) {
                 /* If statement contains and/or */
                 $display = true;
                 foreach ($logicalOperators as $k => $logicalOperator) {
                     if ($logicalOperator == 'and') {
                         $display = $this->interpret_condition($conditions[$k]['left'], $conditions[$k]['right'], $conditions[$k]['operator'], $context) && $this->interpret_condition($conditions[$k + 1]['left'], $conditions[$k + 1]['right'], $conditions[$k + 1]['operator'], $context);
                     } else {
                         $display = $this->interpret_condition($conditions[$k]['left'], $conditions[$k]['right'], $conditions[$k]['operator'], $context) || $this->interpret_condition($conditions[$k + 1]['left'], $conditions[$k + 1]['right'], $conditions[$k + 1]['operator'], $context);
                     }
                 }
             } else {
                 /* If statement is a single condition */
                 $display = $this->interpret_condition($conditions[0]['left'], $conditions[0]['right'], $conditions[0]['operator'], $context);
             }
             if ($display) {
                 $result = $this->render_all($block[2], $context);
                 break;
             }
         }
     }
     $context->pop();
     return $result;
 }
Exemplo n.º 4
0
 /**
  * Constructor
  *
  * @param string $markup
  * @return LiquidVariable
  */
 function LiquidVariable($markup)
 {
     $this->markup = $markup;
     $quoted_fragment_regexp = new LiquidRegexp('/\\s*(' . LIQUID_QUOTED_FRAGMENT . ')/');
     $filter_seperator_regexp = new LiquidRegexp('/' . LIQUID_FILTER_SEPERATOR . '\\s*(.*)/');
     $filter_split_regexp = new LiquidRegexp('/' . LIQUID_FILTER_SEPERATOR . '/');
     $filter_name_regexp = new LiquidRegexp('/\\s*(\\w+)/');
     $filter_argument_regexp = new LiquidRegexp('/(?:' . LIQUID_FILTER_ARGUMENT_SEPERATOR . '|' . LIQUID_ARGUMENT_SPERATOR . ')\\s*(' . LIQUID_QUOTED_FRAGMENT . ')/');
     $quoted_fragment_regexp->match($markup);
     $this->name = $quoted_fragment_regexp->matches[1];
     if ($filter_seperator_regexp->match($markup)) {
         $filters = $filter_split_regexp->split($filter_seperator_regexp->matches[1]);
         foreach ($filters as $filter) {
             $filter_name_regexp->match($filter);
             $filtername = $filter_name_regexp->matches[1];
             $filter_argument_regexp->match_all($filter);
             $matches = array_flatten($filter_argument_regexp->matches[1]);
             $this->filters[] = array($filtername, $matches);
         }
     } else {
         $this->filters = array();
     }
 }