Ejemplo n.º 1
0
 public function usableInLoad()
 {
     $dom = new \DOMDocument();
     $this->assertTrue($dom->load(Streams::readableUri(new MemoryInputStream(trim('
   <?xml version="1.0" encoding="utf-8"?>
   <root>
     <child>übercoder</child>
   </root>
 ')))));
     $this->assertEquals('übercoder', $dom->getElementsByTagName('child')->item(0)->nodeValue);
 }
Ejemplo n.º 2
0
 /**
  * Returns a DOM object for this response's contents. Lazy/Cached.
  *
  * @return  php.DOMDocument
  */
 public function getDom()
 {
     if (null === $this->dom) {
         $this->dom = new \DOMDocument();
         // HHVM blocks all external resources by default, and the .ini setting
         // "hhvm.libxml.ext_entity_whitelist" cannot be set via ini_set().
         if (defined('HHVM_VERSION')) {
             @$this->dom->loadHTML(Streams::readAll($this->response->getInputStream()));
         } else {
             @$this->dom->loadHTMLFile(Streams::readableUri($this->response->getInputStream()));
         }
     }
     return $this->dom;
 }
Ejemplo n.º 3
0
 /** @param io.streams.InputStream */
 private function read($stream)
 {
     $this->stream = $stream;
     if ($this instanceof UriReader && !self::$GD_USERSTREAMS_BUG) {
         $this->reader = function ($reader, $stream) {
             return $reader->readImageFromUri(Streams::readableUri($stream));
         };
     } else {
         $this->reader = function ($reader, $stream) {
             $bytes = '';
             while ($stream->available() > 0) {
                 $bytes .= $stream->read();
             }
             $stream->close();
             return $reader->readImageFromString($bytes);
         };
     }
 }
Ejemplo n.º 4
0
 /**
  * Unmarshal XML to an object
  *
  * @param   xml.parser.InputSource source
  * @param   string classname
  * @param   [:var] inject
  * @return  lang.Object
  * @throws  lang.ClassNotFoundException
  * @throws  xml.XMLFormatException
  * @throws  lang.reflect.TargetInvocationException
  * @throws  lang.IllegalArgumentException
  */
 public function unmarshalFrom(InputSource $input, $classname, $inject = [])
 {
     libxml_clear_errors();
     $doc = new \DOMDocument();
     if (!$doc->load(Streams::readableUri($input->getStream()))) {
         $e = libxml_get_last_error();
         throw new XMLFormatException(trim($e->message), $e->code, $input->getSource(), $e->line, $e->column);
     }
     $xpath = new XPath($doc);
     // Class factory based on tag name, reference to a static method which is called with
     // the class name and returns an XPClass instance.
     $class = \lang\XPClass::forName($classname);
     if ($class->hasAnnotation('xmlmapping', 'factory')) {
         if ($class->hasAnnotation('xmlmapping', 'pass')) {
             $factoryArgs = [];
             foreach ($class->getAnnotation('xmlmapping', 'pass') as $pass) {
                 $factoryArgs[] = self::contentOf($xpath->query($pass, $doc->documentElement));
             }
         } else {
             $factoryArgs = [$doc->documentElement->nodeName];
         }
         $class = $class->getMethod($class->getAnnotation('xmlmapping', 'factory'))->invoke(null, $factoryArgs);
     }
     return self::recurse($xpath, $doc->documentElement, $class, $inject);
 }
Ejemplo n.º 5
0
 public function is_file()
 {
     $this->assertTrue(is_file(Streams::readableUri(new MemoryInputStream('Hello'))));
 }