Exemplo n.º 1
0
 public function contentAccessors()
 {
     $content = '"This is interesting", Tom\'s friend said. "It\'s > 4 but < 2!"';
     $n = new Node('node');
     $n->setContent($content);
     $this->assertEquals($content, $n->getContent());
 }
Exemplo n.º 2
0
 protected function applyArgs(Node $node)
 {
     if ($node instanceof TextNode) {
         $node->setContent($this->interpolate($node->getContent()));
     } else {
         if ($node instanceof Element) {
             foreach ($node->getAttributes() as $attr => $value) {
                 $node->setAttribute($attr, $this->interpolate($value));
             }
         }
     }
     foreach ($node->getChildren() as $child) {
         $this->applyArgs($child);
     }
 }
Exemplo n.º 3
0
 /**
  * Get content in iso-8859-1 encoding (the default).
  *
  * @param   string encoding
  * @param   var namespaces
  * @return  var data
  */
 public function getContent($encoding = NULL, $namespaces = NULL)
 {
     $ret = parent::getContent();
     @(list($ns, $t) = explode(':', @$this->getAttribute($namespaces[XMLNS_XSI] . ':type')));
     switch (strtolower($t)) {
         case 'base64':
         case 'base64binary':
             return new SOAPBase64Binary($ret, $encoded = TRUE);
             break;
         case 'hexbinary':
             return new SOAPHexBinary($ret, $encoded = TRUE);
             break;
         case 'boolean':
             return 0 == strncasecmp('true', $ret, 4) || 0 == strncasecmp('1', $ret, 1) ? TRUE : FALSE;
         case 'long':
         case 'int':
             $t = 'integer';
             break;
         case 'decimal':
         case 'float':
         case 'double':
             $t = 'double';
             break;
         case 'date':
         case 'datetime':
             // ISO 8601: http://www.w3.org/TR/xmlschema-2/#ISO8601 http://www.w3.org/TR/xmlschema-2/#dateTime
             return new Date($ret);
             break;
         default:
             $t = 'string';
     }
     // Decode if necessary
     switch (strtolower($encoding)) {
         case 'utf-8':
             $ret = iconv('utf-8', xp::ENCODING, $ret);
             break;
     }
     // Set type
     settype($ret, $t);
     return $ret;
 }
Exemplo n.º 4
0
 /**
  * Insere Determinado Elemento na Árvore
  * @param Node $node Elemento para Inserção
  * @return Node Próprio Objeto para Encadeamento
  * @throws InvalidArgumentException Conteúdo do Nó Idêntico
  */
 public function insert(Node $node)
 {
     /* Conteúdo Idêntico */
     if ($node->getContent() == $this->getContent()) {
         $content = $node->getContent();
         throw new InvalidArgumentException("Conteúdo Inválido: Valores Idênticos '{$content}'");
     }
     $local = NULL;
     if ($node->getContent() < $this->getContent()) {
         $local = $this->getLeft();
         if ($local === NULL) {
             /* Esquerdo Vazio */
             $this->setLeft($node);
             return $this;
         }
     }
     if ($node->getContent() > $this->getContent()) {
         $local = $this->getRight();
         if ($local === NULL) {
             /* Direito Vazio */
             $this->setRight($node);
             return $this;
         }
     }
     /* Inserção de Subárvore */
     $local->insert($node);
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Recursively deserialize data for the given node.
  *
  * @param   xml.Node node
  * @return  var
  * @throws  lang.IllegalArgumentException if the data cannot be deserialized
  * @throws  lang.ClassNotFoundException in case a XP object's class could not be loaded
  * @throws  xml.XMLFormatException
  */
 protected function _unmarshall(Node $node)
 {
     // value without type is supposed to be string (XML-RPC specs)
     if ('value' == $node->getName() && !isset($node->children[0])) {
         return (string) $node->getContent();
     }
     if (!isset($node->children[0])) {
         throw new XMLFormatException('Tried to access nonexistant node.');
     }
     // Simple form: If no subnode indicating the type exists, the type
     // is string, e.g. <value>Test</value>
     if (!$node->hasChildren()) {
         return (string) $node->getContent();
     }
     // Long form - with subnode, the type is derived from the node's name,
     // e.g. <value><string>Test</string></value>.
     $c = $node->nodeAt(0);
     switch ($c->getName()) {
         case 'struct':
             $ret = array();
             foreach ($c->getChildren() as $child) {
                 $data = array();
                 $data[$child->nodeAt(0)->getName()] = $child->nodeAt(0);
                 $data[$child->nodeAt(1)->getName()] = $child->nodeAt(1);
                 $ret[$data['name']->getContent()] = $this->_unmarshall($data['value']);
                 unset($data);
             }
             if (!isset($ret['__xp_class'])) {
                 return $ret;
             }
             // Check whether this is a XP object. If so, load the class and
             // create an instance without invoking the constructor.
             $fields = XPClass::forName($ret['__xp_class'])->getFields();
             $cname = array_search($ret['__xp_class'], xp::$cn, TRUE);
             $s = '';
             $n = 0;
             foreach ($fields as $field) {
                 if (!isset($ret[$field->getName()])) {
                     continue;
                 }
                 $m = $field->getModifiers();
                 if ($m & MODIFIER_STATIC) {
                     continue;
                 } else {
                     if ($m & MODIFIER_PUBLIC) {
                         $name = $field->getName();
                     } else {
                         if ($m & MODIFIER_PROTECTED) {
                             $name = "*" . $field->getName();
                         } else {
                             if ($m & MODIFIER_PRIVATE) {
                                 $name = "" . array_search($field->getDeclaringClass()->getName(), xp::$cn, TRUE) . "" . $field->getName();
                             }
                         }
                     }
                 }
                 $s .= 's:' . strlen($name) . ':"' . $name . '";' . serialize($ret[$field->getName()]);
                 $n++;
             }
             return unserialize('O:' . strlen($cname) . ':"' . $cname . '":' . $n . ':{' . $s . '}');
         case 'array':
             $ret = array();
             foreach ($c->nodeAt(0)->getChildren() as $child) {
                 $ret[] = $this->_unmarshall($child);
             }
             return $ret;
         case 'int':
         case 'i4':
             return (int) $c->getContent();
         case 'double':
             return (double) $c->getContent();
         case 'boolean':
             return (bool) $c->getContent();
         case 'string':
             return (string) $c->getContent();
         case 'dateTime.iso8601':
             return Date::fromString($c->getContent());
         case 'nil':
             return NULL;
         case 'base64':
             return new Bytes(base64_decode($c->getContent()));
         default:
             throw new IllegalArgumentException('Could not decode node as its type is not supported: ' . $c->getName());
     }
 }