/** * Set the name of the math constant. * * @param string $name The name of the math constant. * @throws InvalidArgumentException If $name is not a valid QTI math constant name. */ public function setName($name) { if (in_array($name, MathEnumeration::asArray())) { $this->name = $name; } else { $msg = "{$name} is not a valid QTI Math constant."; throw new InvalidArgumentException($msg); } }
/** * Unmarshall a DOMElement object corresponding to a QTI mathConstant element. * * @param \DOMElement $element A DOMElement object. * @return \qtism\data\QtiComponent A MathConstant object. * @throws \UnmarshallingException If the mandatory attribute 'name' is missing. */ protected function unmarshall(DOMElement $element) { if (($name = static::getDOMElementAttributeAs($element, 'name')) !== null) { if (($cst = MathEnumeration::getConstantByName($name)) !== false) { $object = new MathConstant($cst); return $object; } else { $msg = "'{$name}' is not a valid value for the attribute 'name' from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'name' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }