Example #1
0
 public static function build($buffer)
 {
     $xml = new DOMDocument('1.0', 'UTF-8');
     $xml->formatOutput = true;
     $xml->registerNodeClass('\\DOMElement', '\\AfriCC\\EPP\\DOM\\DOMElement');
     $xml->loadXML($buffer);
     $xpath = new DOMXPath($xml);
     foreach (ObjectSpec::$specs as $prefix => $spec) {
         $xpath->registerNamespace($prefix, $spec['xmlns']);
     }
     $nodes = $xml->getElementsByTagNameNS(ObjectSpec::xmlns('epp'), 'epp');
     if ($nodes === null || $nodes->length !== 1) {
         return $buffer;
     }
     if (!$nodes->item(0)->hasChildNodes()) {
         return $buffer;
     }
     foreach ($nodes->item(0)->childNodes as $node) {
         // ignore non-nodes
         if ($node->nodeType !== XML_ELEMENT_NODE) {
             continue;
         }
         // ok now we can create an object according to the response-frame
         $frame_type = strtolower($node->localName);
         if ($frame_type === 'response') {
             // check if it is a message queue
             $results = $xpath->query('//epp:epp/epp:response/epp:msgQ');
             if ($results->length > 0) {
                 return new \AfriCC\EPP\Frame\Response\MessageQueue($xml);
             }
             return new Response($xml);
         }
     }
     return $buffer;
 }
Example #2
0
 protected function createNodes($path)
 {
     $path_parts = explode('/', $path);
     $node_path = null;
     for ($i = 0, $limit = count($path_parts); $i < $limit; ++$i) {
         $attr_name = $attr_value = null;
         // if no namespace given, use root-namespace
         if (strpos($path_parts[$i], ':') === false) {
             $node_ns = 'epp';
             $node_name = $path_parts[$i];
             $path_parts[$i] = $node_ns . ':' . $node_name;
         } else {
             list($node_ns, $node_name) = explode(':', $path_parts[$i], 2);
         }
         // check for node-array
         if (substr($node_name, -2) === '[]') {
             $node_name = substr($node_name, 0, -2);
             // get next key
             $next_key = -1;
             foreach (array_keys($this->nodes) as $each) {
                 if (preg_match('/' . preg_quote($node_ns . ':' . $node_name, '/') . '\\[(\\d+)\\]$/', $each, $matches)) {
                     if ($matches[1] > $next_key) {
                         $next_key = (int) $matches[1];
                     }
                 }
             }
             ++$next_key;
             $path_parts[$i] = sprintf('%s:%s[%d]', $node_ns, $node_name, $next_key);
         }
         // direct node-array access
         if (preg_match('/^(.*)\\[(\\d+)\\]$/', $node_name, $matches)) {
             $node_name = $matches[1];
         } elseif (preg_match('/^(.*)\\[@([a-z0-9]+)=\'([a-z0-9]+)\'\\]$/i', $node_name, $matches)) {
             $node_name = $matches[1];
             $attr_name = $matches[2];
             $attr_value = $matches[3];
         }
         $node_path = implode('/', array_slice($path_parts, 0, $i + 1));
         if (isset($this->nodes[$node_path])) {
             continue;
         }
         // resolve node namespace
         $node_xmlns = ObjectSpec::xmlns($node_ns);
         if ($node_xmlns === false) {
             throw new Exception(sprintf('unknown namespace: %s', $node_ns));
         }
         // create node (but don't explicitely define root-node)
         if ($node_ns === 'epp') {
             $this->nodes[$node_path] = $this->createElementNS($node_xmlns, $node_name);
         } else {
             $this->nodes[$node_path] = $this->createElementNS($node_xmlns, $node_ns . ':' . $node_name);
         }
         // set attribute
         if ($attr_name !== null && $attr_value !== null) {
             $this->nodes[$node_path]->setAttribute($attr_name, $attr_value);
         }
         // now append node to parent
         if ($i === 0) {
             $parent = $this;
         } else {
             $parent = $this->nodes[implode('/', array_slice($path_parts, 0, $i))];
         }
         $parent->appendChild($this->nodes[$node_path]);
     }
     return $node_path;
 }