public function testCreateProcessorNoProcessor() { $expression = $this->createComponentFromXml(' <sum> <baseValue baseType="integer">1</baseValue> <baseValue baseType="integer">1</baseValue> </sum>'); $factory = new ExpressionProcessorFactory(); $this->setExpectedException('\\RuntimeException'); $processor = $factory->createProcessor($expression); }
/** * Process the current Expression object according to the current * execution context. * * @throws ExpressionProcessingException|OperatorProcessingException If an error occurs during the Expression processing. */ public function process() { $expression = $this->getComponent(); // Reset trail and marker arrays. $this->trail = array(); $this->marker = array(); $this->pushTrail($expression); while (count($this->getTrail()) > 0) { $expression = $this->popTrail(); if ($this->isMarked($expression) === false && $expression instanceof Operator) { // This is an operator, first pass. Repush for a second pass. $this->mark($expression); $this->pushTrail($expression); $this->pushTrail($expression->getExpressions()); } else { if ($this->isMarked($expression)) { // Operator, second pass. Process it. $popCount = count($expression->getExpressions()); $operands = $this->operands->pop($popCount); $processor = $this->operatorProcessorFactory->createProcessor($expression, $operands); $processor->setState($this->getContext()); $result = $processor->process(); // trace the processing of the operator. $qtiName = $expression->getQtiClassName(); $trace = "Operator '{$qtiName}' processed."; $this->traceOperator($processor, $result); if ($expression !== $this->getComponent()) { $this->operands->push($result); } } else { // Simple expression, process it. $processor = $this->expressionProcessorFactory->createProcessor($expression); $processor->setState($this->getContext()); $result = $processor->process(); $this->operands->push($result); // trace the processing of the expression. $qtiName = $expression->getQtiClassName(); $trace = "Expression '{$qtiName}' processed."; $this->traceExpression($processor, $result); } } } return $result; }
/** * Create a new OperatorProcessorFactory object. * */ public function __construct() { parent::__construct(); }