private function lexExpr($expression)
 {
     $lexer = new Lexer($expression);
     if (null == $this->viewElement) {
         $viewElement = $this->prepareViewElement();
     } else {
         $viewElement = $this->viewElement;
     }
     // Make sure that the passed expression is successfully parsed,
     // before asserting stuff on its evaluation.
     $parseResult = $lexer->parse($viewElement);
     $this->assertTrue($parseResult, 'parsed expression: ' . $lexer->getExpression());
     return $lexer->evaluate($viewElement);
 }
示例#2
0
 private function lexExpr($expression, array $data = null)
 {
     $lexer = new Lexer($expression);
     // A Lexer object needs to live inside a View,
     // and be bound to a ViewElementTag instance.
     // They both need to be bound to a File object,
     // which must respond to the getCurrentFile method.
     $view = $this->getMock('\\figdice\\View');
     $viewFile = $this->getMock('\\figdice\\classes\\File', null, array('PHPUnit'));
     $viewElement = $this->getMock('\\figdice\\classes\\ViewElementTag', array('getCurrentFile'), array(&$view, 'testtag', 12));
     $viewElement->expects($this->any())->method('getCurrentFile')->will($this->returnValue($viewFile));
     // Make sure that the passed expression is successfully parsed,
     // before asserting stuff on its evaluation.
     $parseResult = $lexer->parse($viewElement);
     $this->assertTrue($parseResult, 'parsed expression: ' . $lexer->getExpression());
     // Mock the mounting of root data universe into the view
     $view->expects($this->any())->method('fetchData')->will($this->returnValue($data));
     return $lexer->evaluate($viewElement);
 }
 private function lexExpr($expression)
 {
     $lexer = new Lexer($expression);
     // A Lexer object needs to live inside a View,
     // and be bound to a ViewElementTag instance.
     // They both need to be bound to a File object,
     // which must respond to the getCurrentFile method.
     // In this test, we need a real View object, because
     // it embeds a real NativeFunctionFactory instance.
     $view = $this->view;
     $viewFile = $this->getMock('\\figdice\\classes\\File', null, array('PHPUnit'));
     $viewElement = $this->getMock('\\figdice\\classes\\ViewElementTag', array('getCurrentFile'), array(&$view, 'testtag', 12));
     $viewElement->expects($this->any())->method('getCurrentFile')->will($this->returnValue($viewFile));
     // Make sure that the passed expression is successfully parsed,
     // before asserting stuff on its evaluation.
     $parseResult = $lexer->parse($viewElement);
     $this->assertTrue($parseResult, 'parsed expression: ' . $lexer->getExpression());
     return $lexer->evaluate($viewElement);
 }
示例#4
0
 /**
  * Evaluate the XPath-like expression
  * on the data object associated to the view.
  *
  * @access private
  * @param string $expression
  * @return string
  */
 public function evaluate($expression)
 {
     if (is_numeric($expression)) {
         $expression = (string) $expression;
     }
     if (!isset($this->view->lexers[$expression])) {
         $lexer = new Lexer($expression);
         $this->view->lexers[$expression] =& $lexer;
         $lexer->parse($this);
     } else {
         $lexer =& $this->view->lexers[$expression];
     }
     $result = $lexer->evaluate($this);
     return $result;
 }
示例#5
0
 /**
  * @param Lexer $lexer
  * @param string $message
  */
 protected function throwErrorWithMessage($lexer, $message)
 {
     $message = get_class($this) . ': file: ' . $lexer->getViewFile()->getFilename() . '(' . $lexer->getViewLine() . '): ' . $message . ' in expression: ' . $lexer->getExpression();
     if (!$this->logger) {
         $this->logger = LoggerFactory::getLogger(get_class($this));
     }
     $this->logger->error($message);
     throw new LexerUnexpectedCharException($message, $lexer->getViewFile()->getFilename(), $lexer->getViewLine());
 }