Example #1
0
 /**
  * @param ViewElement $viewElement
  * @param integer $arity
  * @param array $arguments
  */
 public function evaluate(ViewElementTag $viewElement, $arity, $arguments)
 {
     if ($arity != 3) {
         throw new FunctionCallException('if', 'Expected 3 arguments, ' . $arity . ' received.', $viewElement->getCurrentFile()->getFilename(), $viewElement->getLineNumber());
     }
     return $arguments[0] ? $arguments[1] : $arguments[2];
 }
Example #2
0
 /**
  * @param ViewElement $viewElement
  */
 public function evaluate(ViewElementTag $viewElement)
 {
     if ($this->function === null) {
         //Instantiate the Function handler:
         /** @var FunctionFactory[] $factories */
         $factories = $viewElement->getView()->getFunctionFactories();
         if (null != $factories && is_array($factories)) {
             foreach ($factories as $factory) {
                 if (null !== ($this->function = $factory->lookup($this->name))) {
                     break;
                 }
             }
         }
         if ($this->function == null) {
             $logger = LoggerFactory::getLogger(__CLASS__);
             $message = 'Undeclared function: ' . $this->name;
             $logger->error($message);
             throw new FunctionNotFoundException($this->name);
         }
     }
     $arguments = array();
     if ($this->operands) {
         foreach ($this->operands as $operandToken) {
             $arguments[] = $operandToken->evaluate($viewElement);
         }
     }
     return $this->function->evaluate($viewElement, $this->arity, $arguments);
 }
Example #3
0
 /**
  * @param {@link ViewElement} $viewElement
  * @param integer $arity
  * @param array $arguments
  */
 public function evaluate(ViewElementTag $viewElement, $arity, $arguments)
 {
     /**
      * @var Iteration
      */
     $iteration = $viewElement->getIteration();
     return $iteration->getPosition();
 }
Example #4
0
 /**
  * Function's arguments:
  *  string to escape
  * 
  * @param ViewElement $viewElement
  * @param integer $arity
  * @param array $arguments
  */
 public function evaluate(ViewElementTag $viewElement, $arity, $arguments)
 {
     if ($arity != 1) {
         throw new FunctionCallException('htmlentities', 'Expects exactly 1 argument.', $viewElement->getCurrentFile()->getFilename(), $viewElement->getLineNumber());
     }
     $string = $arguments[0];
     return htmlentities($string);
 }
Example #5
0
 /**
  * Function's arguments:
  *  timestamp, format [, locale]
  * 
  * @param ViewElement $viewElement
  * @param integer $arity
  * @param array $arguments
  */
 public function evaluate(ViewElementTag $viewElement, $arity, $arguments)
 {
     if ($arity <= 1) {
         throw new FunctionCallException('substr', 'Too few arguments.', $viewElement->getCurrentFile()->getFilename(), $viewElement->getLineNumber());
     }
     $string = $arguments[0];
     $start = $arguments[1];
     if (3 <= $arity) {
         $length = $arguments[2];
         return substr($string, $start, $length);
     } else {
         return substr($string, $start);
     }
 }
Example #6
0
 public function getViewLine()
 {
     return $this->viewElement->getLineNumber();
 }
Example #7
0
 /**
  * @param ViewElement $viewElement
  * @param integer $arity
  * @param array $arguments
  */
 public function evaluate(ViewElementTag $viewElement, $arity, $arguments)
 {
     $iteration = $viewElement->getIteration();
     return $iteration->last();
 }
Example #8
0
 private function openTagHandler($xmlParser, $tagName, $attributes)
 {
     if ($this->firstOpening) {
         $this->firstOpening = false;
         $positionOfFirstTag = xml_get_current_byte_index($xmlParser);
         $this->firstTagOffset = strpos($this->source, "<{$tagName}") - $positionOfFirstTag;
         //Position the namespace:
         $matches = null;
         foreach ($attributes as $attrName => $attrValue) {
             if (preg_match('/figdice/', $attrValue) && preg_match('/xmlns:(.+)/', $attrName, $matches)) {
                 $this->figNamespace = $matches[1] . ':';
                 break;
             }
         }
     }
     $lineNumber = xml_get_current_line_number($xmlParser);
     if ($this->parentViewElement) {
         $view =& $this->parentViewElement->view;
     } else {
         $view =& $this;
     }
     if ($tagName == $this->figNamespace . TagFigAttr::TAGNAME) {
         $newElement = new TagFigAttr($view, $tagName, $lineNumber);
     } else {
         $newElement = new ViewElementTag($view, $tagName, $lineNumber);
     }
     $newElement->setCurrentFile($this->file);
     $newElement->setAttributes($attributes);
     if ($this->rootNode === null && $this->parentViewElement) {
         $this->rootNode =& $this->parentViewElement;
         $this->stack[] =& $this->parentViewElement;
     }
     if ($this->rootNode) {
         /** @var ViewElementTag $parentElement */
         $parentElement =& $this->stack[count($this->stack) - 1];
         $newElement->parent =& $parentElement;
         //Since the new element has a parent, then the parent is not autoclose.
         $newElement->parent->autoclose = false;
         $parentElement->appendChild($newElement);
     } else {
         //If there no root node yet, then this new element is actually
         //the root element for the view.
         $this->rootNode =& $newElement;
     }
     $this->stack[] =& $newElement;
 }
Example #9
0
 /**
  * @param ViewElement $viewElement
  * @param integer $arity
  * @param array $arguments
  */
 public function evaluate(ViewElementTag $viewElement, $arity, $arguments)
 {
     $iteration = $viewElement->getIteration();
     $position = $iteration->getPosition();
     return $position % 2 == 0;
 }
Example #10
0
 private function openTagHandler($xmlParser, $tagName, $attributes)
 {
     if ($this->firstOpening) {
         $this->firstOpening = false;
         //Position the namespace:
         $matches = null;
         foreach ($attributes as $attrName => $attrValue) {
             if (preg_match('/figdice/', $attrValue) && preg_match('/xmlns:(.+)/', $attrName, $matches)) {
                 $this->figNamespace = $matches[1] . ':';
                 break;
             }
         }
         // Remove the fig xmlns directive from the list of attributes of the opening root tag
         // (as it should not be rendered)
         unset($attributes['xmlns:' . substr($this->figNamespace, 0, strlen($this->figNamespace) - 1)]);
     }
     $lineNumber = xml_get_current_line_number($xmlParser);
     if ($this->parentViewElement) {
         $view =& $this->parentViewElement->view;
     } else {
         $view =& $this;
     }
     if ($tagName == $this->figNamespace . TagFigAttr::TAGNAME) {
         $newElement = new TagFigAttr($view, $tagName, $lineNumber);
     } else {
         $newElement = new ViewElementTag($view, $tagName, $lineNumber);
     }
     $newElement->setCurrentFile($this->file);
     $newElement->setAttributes($attributes);
     if ($this->rootNode === null && $this->parentViewElement) {
         $this->rootNode =& $this->parentViewElement;
         $this->stack[] =& $this->parentViewElement;
     }
     if ($this->rootNode) {
         /** @var ViewElementTag $parentElement */
         $parentElement =& $this->stack[count($this->stack) - 1];
         $newElement->parent =& $parentElement;
         //Since the new element has a parent, then the parent is not autoclose.
         $newElement->parent->autoclose = false;
         $parentElement->appendChild($newElement);
     } else {
         //If there no root node yet, then this new element is actually
         //the root element for the view.
         $this->rootNode =& $newElement;
     }
     $this->stack[] =& $newElement;
 }