config; } public function setConfig($configFiles) { if (is_array($configFiles)) { $this->config = $configFiles; } else { throw new InvalidArgumentException('config files should be an array'); } } public function addModule($id, $paths) { if (is_string($paths)) { $paths = [$paths]; } if (is_array($paths)) { $this->modules[$id] = $paths; } else { throw new InvalidArgumentException('modue paths should be an array'); } } public function setModules($paths) { if (is_array($paths)) { $this->modules = $paths; } else { throw new InvalidArgumentException('modue paths should be an array'); } } public function getModules() { return $this->modules; } /** * Serialize an associative array of pci properties into a pci xml * * @param array $properties * @param string $ns * @return string */ private function serializePortableProperties($properties, $ns = '', $nsUri = '', $name = null, $element = null) { $document = null; $result = ''; if ($element === null) { $document = new \DomDocument(); $element = $ns ? $document->createElementNS($nsUri, $ns . ':properties') : $document->createElement('properties'); $document->appendChild($element); } else { $newElement = $ns ? $element->ownerDocument->createElementNS($nsUri, $ns . ':properties') : $element->ownerDocument->createElement('properties'); $element->appendChild($newElement); $element = $newElement; } if ($name !== null) { $element->setAttribute('key', $name); } foreach ($properties as $name => $value) { if (is_array($value)) { $this->serializePortableProperties($value, $ns, $nsUri, $name, $element); } else { $entryElement = $ns ? $element->ownerDocument->createElementNS($nsUri, $ns . ':property') : $element->ownerDocument->createElement('property'); $entryElement->setAttribute('key', $name); $entryElement->appendChild(new \DOMText($value)); $element->appendChild($entryElement); } } if ($document !== null) { foreach ($document->childNodes as $node) { $result .= $document->saveXML($node); } } return $result; } /** * Parse a pci properties dom node into an associative array * * @param DOMElement $propertiesNode * @param string $ns * @return array */ private function extractProperties(DOMElement $propertiesNode, $ns = '') { $properties = []; $ns = $ns ? trim($ns, ':') . ':' : ''; foreach ($propertiesNode->childNodes as $prop) { if ($prop instanceof DOMElement) { switch ($prop->tagName) { case $ns . 'entry'://OAT PCI uses entry as property node case $ns . 'property'://IMS PCI uses entry as property node $key = $prop->getAttribute('key'); $properties[$key] = $prop->nodeValue; break; case $ns . 'properties': $key = $prop->getAttribute('key'); $properties[$key] = $this->extractProperties($prop, $ns); break; } } } return $properties; } /** * Set the namespace used by this custom interaction * @param QtiNamespace $xmlns */ public function setNamespace(QtiNamespace $xmlns) { $this->ns = $xmlns; } /** * Get the namespace used by this custom interaction * @return QtiNamespace */ public function getNamespace() { return $this->ns; } }