* @package taoQTI */ class ExpressionParserFactory { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- // --- OPERATIONS --- /** * Short description of method build * * @access public * @author Joel Bout, * @param SimpleXMLElement data * @return oat\taoQtiItem\model\qti\expression\Expression */ public static function build(SimpleXMLElement $data) { $returnValue = null; $expression = null; $expressionName = $data->getName(); //retrieve the expression attributes $attributes = []; foreach ($data->attributes() as $key => $value) { $attributes[$key] = (string)$value; } // Create expression function of its type (If specialization has been done for the expression type) $expressionClass = 'oat\\taoQtiItem\\model\\qti\\expression\\' . ucfirst($expressionName); if (class_exists($expressionClass)) { $expression = new $expressionClass($expressionName, $attributes); } else { $expression = new CommonExpression($expressionName, $attributes); } // If the expression has a value $expressionValue = (string) trim($data); if ($expressionValue != '') { $expression->setValue($expressionValue); } // All sub-expressions of an expression are embedded by this expression $subExpressions = []; foreach ($data->children() as $subExpressionNode) { $subExpressions[] = self::build($subExpressionNode); } $expression->setSubExpressions($subExpressions); $returnValue = $expression; return $returnValue; } }