Exemplo n.º 1
1
 /**
  * Build a response object
  *
  * @param \GuzzleHttp\Psr7\Response $response
  * @return Activity[]
  */
 public function map(Response $response)
 {
     // Pares XML
     $reader = new Reader();
     $reader->xml($response->getBody());
     $parse = $reader->parse();
     $return = [];
     foreach ($parse['value'] as $value) {
         $return[] = new Activity($value['attributes'], $value['value']);
     }
     return $return;
 }
Exemplo n.º 2
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $elems = $reader->parseInnerTree();
     $obj = new self();
     $obj->properties = self::traverse($elems);
     return $obj;
 }
Exemplo n.º 3
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $self = new self();
     $reader->pushContext();
     $reader->elementMap['{DAV:}prop'] = 'Sabre\\Xml\\Element\\Elements';
     $elems = KeyValue::xmlDeserialize($reader);
     $reader->popContext();
     $required = ['{DAV:}sync-token', '{DAV:}prop'];
     foreach ($required as $elem) {
         if (!array_key_exists($elem, $elems)) {
             throw new BadRequest('The ' . $elem . ' element in the {DAV:}sync-collection report is required');
         }
     }
     $self->properties = $elems['{DAV:}prop'];
     $self->syncToken = $elems['{DAV:}sync-token'];
     if (isset($elems['{DAV:}limit'])) {
         $nresults = null;
         foreach ($elems['{DAV:}limit'] as $child) {
             if ($child['name'] === '{DAV:}nresults') {
                 $nresults = (int) $child['value'];
             }
         }
         $self->limit = $nresults;
     }
     if (isset($elems['{DAV:}sync-level'])) {
         $value = $elems['{DAV:}sync-level'];
         if ($value === 'infinity') {
             $value = \Sabre\DAV\Server::DEPTH_INFINITY;
         }
         $self->syncLevel = $value;
     }
     return $self;
 }
Exemplo n.º 4
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $result = ['name' => null, 'is-not-defined' => false, 'param-filters' => [], 'text-match' => null, 'time-range' => false];
     $att = $reader->parseAttributes();
     $result['name'] = $att['name'];
     $elems = $reader->parseInnerTree();
     if (is_array($elems)) {
         foreach ($elems as $elem) {
             switch ($elem['name']) {
                 case '{' . Plugin::NS_CALDAV . '}param-filter':
                     $result['param-filters'][] = $elem['value'];
                     break;
                 case '{' . Plugin::NS_CALDAV . '}is-not-defined':
                     $result['is-not-defined'] = true;
                     break;
                 case '{' . Plugin::NS_CALDAV . '}time-range':
                     $result['time-range'] = ['start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null, 'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null];
                     if ($result['time-range']['start'] && $result['time-range']['end'] && $result['time-range']['end'] <= $result['time-range']['start']) {
                         throw new BadRequest('The end-date must be larger than the start-date');
                     }
                     break;
                 case '{' . Plugin::NS_CALDAV . '}text-match':
                     $result['text-match'] = ['negate-condition' => isset($elem['attributes']['negate-condition']) && $elem['attributes']['negate-condition'] === 'yes', 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;ascii-casemap', 'value' => $elem['value']];
                     break;
             }
         }
     }
     return $result;
 }
Exemplo n.º 5
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $result = ['name' => null, 'test' => 'anyof', 'is-not-defined' => false, 'param-filters' => [], 'text-matches' => []];
     $att = $reader->parseAttributes();
     $result['name'] = $att['name'];
     if (isset($att['test']) && $att['test'] === 'allof') {
         $result['test'] = 'allof';
     }
     $elems = $reader->parseInnerTree();
     if (is_array($elems)) {
         foreach ($elems as $elem) {
             switch ($elem['name']) {
                 case '{' . Plugin::NS_CARDDAV . '}param-filter':
                     $result['param-filters'][] = $elem['value'];
                     break;
                 case '{' . Plugin::NS_CARDDAV . '}is-not-defined':
                     $result['is-not-defined'] = true;
                     break;
                 case '{' . Plugin::NS_CARDDAV . '}text-match':
                     $matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains';
                     if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) {
                         throw new BadRequest('Unknown match-type: ' . $matchType);
                     }
                     $result['text-matches'][] = ['negate-condition' => isset($elem['attributes']['negate-condition']) && $elem['attributes']['negate-condition'] === 'yes', 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap', 'value' => $elem['value'], 'match-type' => $matchType];
                     break;
             }
         }
     }
     return $result;
 }
Exemplo n.º 6
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $timeRange = '{' . Plugin::NS_CALDAV . '}time-range';
     $start = null;
     $end = null;
     foreach ((array) $reader->parseInnerTree([]) as $elem) {
         if ($elem['name'] !== $timeRange) {
             continue;
         }
         $start = empty($elem['attributes']['start']) ?: $elem['attributes']['start'];
         $end = empty($elem['attributes']['end']) ?: $elem['attributes']['end'];
     }
     if (!$start && !$end) {
         throw new BadRequest('The freebusy report must have a time-range element');
     }
     if ($start) {
         $start = DateTimeParser::parseDateTime($start);
     }
     if ($end) {
         $end = DateTimeParser::parseDateTime($end);
     }
     $result = new self();
     $result->start = $start;
     $result->end = $end;
     return $result;
 }
Exemplo n.º 7
0
 function parse($xml, array $elementMap = [])
 {
     $reader = new Reader();
     $reader->elementMap = array_merge($this->elementMap, $elementMap);
     $reader->xml($xml);
     return $reader->parse();
 }
Exemplo n.º 8
0
    function testDeserialize()
    {
        $input = <<<BLA
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns">
  <listThingy>
    <elem1 />
    <elem2 />
    <elem3 />
    <elem4 attr="val" />
    <elem5>content</elem5>
    <elem6><subnode /></elem6>
  </listThingy>
  <listThingy />
  <otherThing>
    <elem1 />
    <elem2 />
    <elem3 />
  </otherThing>
</root>
BLA;
        $reader = new Reader();
        $reader->elementMap = ['{http://sabredav.org/ns}listThingy' => 'Sabre\\Xml\\Element\\Elements'];
        $reader->xml($input);
        $output = $reader->parse();
        $this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}listThingy', 'value' => ['{http://sabredav.org/ns}elem1', '{http://sabredav.org/ns}elem2', '{http://sabredav.org/ns}elem3', '{http://sabredav.org/ns}elem4', '{http://sabredav.org/ns}elem5', '{http://sabredav.org/ns}elem6'], 'attributes' => []], ['name' => '{http://sabredav.org/ns}listThingy', 'value' => [], 'attributes' => []], ['name' => '{http://sabredav.org/ns}otherThing', 'value' => [['name' => '{http://sabredav.org/ns}elem1', 'value' => null, 'attributes' => []], ['name' => '{http://sabredav.org/ns}elem2', 'value' => null, 'attributes' => []], ['name' => '{http://sabredav.org/ns}elem3', 'value' => null, 'attributes' => []]], 'attributes' => []]], 'attributes' => []], $output);
    }
Exemplo n.º 9
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $result = ['name' => null, 'is-not-defined' => false, 'comp-filters' => [], 'prop-filters' => [], 'time-range' => false];
     $att = $reader->parseAttributes();
     $result['name'] = $att['name'];
     $elems = $reader->parseInnerTree();
     if (is_array($elems)) {
         foreach ($elems as $elem) {
             switch ($elem['name']) {
                 case '{' . Plugin::NS_CALDAV . '}comp-filter':
                     $result['comp-filters'][] = $elem['value'];
                     break;
                 case '{' . Plugin::NS_CALDAV . '}prop-filter':
                     $result['prop-filters'][] = $elem['value'];
                     break;
                 case '{' . Plugin::NS_CALDAV . '}is-not-defined':
                     $result['is-not-defined'] = true;
                     break;
                 case '{' . Plugin::NS_CALDAV . '}time-range':
                     if ($result['name'] === 'VCALENDAR') {
                         throw new BadRequest('You cannot add time-range filters on the VCALENDAR component');
                     }
                     $result['time-range'] = ['start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null, 'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null];
                     if ($result['time-range']['start'] && $result['time-range']['end'] && $result['time-range']['end'] <= $result['time-range']['start']) {
                         throw new BadRequest('The end-date must be larger than the start-date');
                     }
                     break;
             }
         }
     }
     return $result;
 }
Exemplo n.º 10
0
 public function read($path)
 {
     parent::read($path);
     $reader = new Reader();
     $reader->xml($this->contents);
     $this->parsed = $reader->parse();
     return $this;
 }
 function parse($xml)
 {
     $reader = new Reader();
     $reader->elementMap['{DAV:}root'] = 'Sabre\\DAVACL\\Xml\\Property\\CurrentUserPrivilegeSet';
     $reader->xml($xml);
     $result = $reader->parse();
     return $result['value'];
 }
 public function testParseReturnsArray()
 {
     $rw = new Realworks();
     $xmlString = file_get_contents('example.xml');
     $reader = new XML\Reader();
     $reader->xml($xmlString);
     $output = $reader->parse();
     $objects = $rw->parse($output);
     $this->assertInternalType('array', $objects);
 }
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     if (!$reader->isEmptyElement) {
         throw new BadRequest('The {DAV:}principal-search-property-set element must be empty');
     }
     // The element is actually empty, so there's not much to do.
     $reader->next();
     $self = new self();
     return $self;
 }
Exemplo n.º 14
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $tags = [];
     foreach ($reader->parseInnerTree() as $elem) {
         if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
             $tags[] = $elem['value'];
         }
     }
     return new self($tags);
 }
Exemplo n.º 15
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $shareTypes = [];
     foreach ($reader->parseInnerTree() as $elem) {
         if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') {
             $shareTypes[] = (int) $elem['value'];
         }
     }
     return new self($shareTypes);
 }
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $reader->pushContext();
     $reader->elementMap['{DAV:}prop'] = 'Sabre\\Xml\\Deserializer\\enum';
     $elems = Deserializer\keyValue($reader, 'DAV:');
     $reader->popContext();
     $report = new self();
     if (!empty($elems['prop'])) {
         $report->properties = $elems['prop'];
     }
     return $report;
 }
Exemplo n.º 17
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * Important note 2: You are responsible for advancing the reader to the
  * next element. Not doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseSubTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param XML\Reader $reader
  * @return mixed
  */
 public static function deserializeXml(XML\Reader $reader)
 {
     $reader->next();
     $count = 1;
     while ($count) {
         $reader->read();
         if ($reader->nodeType === $reader::END_ELEMENT) {
             $count--;
         }
     }
     $reader->read();
 }
Exemplo n.º 18
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * Important note 2: You are responsible for advancing the reader to the
  * next element. Not doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseSubTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Xml\Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Xml\Reader $reader)
 {
     $reader->next();
     $count = 1;
     while ($count) {
         $reader->read();
         if ($reader->nodeType === $reader::END_ELEMENT) {
             $count--;
         }
     }
     $reader->read();
 }
Exemplo n.º 19
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $elems = $reader->parseInnerTree(['{DAV:}sharee' => 'Sabre\\DAV\\Xml\\Element\\Sharee', '{DAV:}share-access' => 'Sabre\\DAV\\Xml\\Property\\ShareAccess', '{DAV:}prop' => 'Sabre\\Xml\\Deserializer\\keyValue']);
     $sharees = [];
     foreach ($elems as $elem) {
         if ($elem['name'] !== '{DAV:}sharee') {
             continue;
         }
         $sharees[] = $elem['value'];
     }
     return new self($sharees);
 }
Exemplo n.º 20
0
 protected function read($xmlFile)
 {
     $xml_contents = file_get_contents($xmlFile);
     $reader = new Reader();
     $reader->xml($xml_contents);
     $tree = $reader->parse();
     foreach ($tree['value'] as $node) {
         $key = $node['attributes']['name'];
         $value = $node['value'];
         $this->patterns[$key] = $value;
     }
 }
Exemplo n.º 21
0
    /**
     * @expectedException \LogicException
     */
    function testDeserialize()
    {
        $input = <<<BLA
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns">
 <blabla />
</root>
BLA;
        $reader = new Reader();
        $reader->elementMap = ['{http://sabredav.org/ns}blabla' => 'Sabre\\Xml\\Element\\Cdata'];
        $reader->xml($input);
        $output = $reader->parse();
    }
Exemplo n.º 22
0
    /**
     * @dataProvider xmlProvider
     */
    function testDeserialize($input, $expected)
    {
        $input = <<<BLA
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns">
   <fragment>{$input}</fragment>
</root>
BLA;
        $reader = new Reader();
        $reader->elementMap = ['{http://sabredav.org/ns}fragment' => 'Sabre\\Xml\\Element\\XmlFragment'];
        $reader->xml($input);
        $output = $reader->parse();
        $this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}fragment', 'value' => new XmlFragment($expected), 'attributes' => []]], 'attributes' => []], $output);
    }
Exemplo n.º 23
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $self = new self();
     $elementMap = $reader->elementMap;
     $elementMap['{DAV:}prop'] = 'Sabre\\DAV\\Xml\\Element\\Prop';
     $elementMap['{DAV:}set'] = 'Sabre\\Xml\\Element\\KeyValue';
     $elems = $reader->parseInnerTree($elementMap);
     foreach ($elems as $elem) {
         if ($elem['name'] === '{DAV:}set') {
             $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']);
         }
     }
     return $self;
 }
Exemplo n.º 24
0
    function testDeserialize()
    {
        $input = <<<BLA
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns">
  <uri>/foo/bar</uri>
</root>
BLA;
        $reader = new Reader();
        $reader->contextUri = 'http://example.org/';
        $reader->elementMap = ['{http://sabredav.org/ns}uri' => 'Sabre\\Xml\\Element\\Uri'];
        $reader->xml($input);
        $output = $reader->parse();
        $this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}uri', 'value' => new Uri('http://example.org/foo/bar'), 'attributes' => []]], 'attributes' => []], $output);
    }
Exemplo n.º 25
0
    /**
     * This function behaves similar to Sabre\Xml\Reader::parseCurrentElement,
     * but instead of creating deep xml array structures, it will turn any
     * top-level element it doesn't recognize into either a string, or an
     * XmlFragment class.
     *
     * This method returns arn array with 2 properties:
     *   * name - A clark-notation XML element name.
     *   * value - The parsed value.
     *
     * @return array
     */
    private static function parseCurrentElement(Reader $reader) {

        $name = $reader->getClark();

        if (array_key_exists($name, $reader->elementMap)) {
            $deserializer = $reader->elementMap[$name];
            if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) {
                $value = call_user_func([ $deserializer, 'xmlDeserialize' ], $reader);
            } elseif (is_callable($deserializer)) {
                $value = call_user_func($deserializer, $reader);
            } else {
                $type = gettype($deserializer);
                if ($type === 'string') {
                    $type .= ' (' . $deserializer . ')';
                } elseif ($type === 'object') {
                    $type .= ' (' . get_class($deserializer) . ')';
                }
                throw new \LogicException('Could not use this type as a deserializer: ' . $type);
            }
        } else {
            $value = Complex::xmlDeserialize($reader);
        }

        return [
            'name'  => $name,
            'value' => $value,
        ];

    }
Exemplo n.º 26
0
    /**
     * The deserialize method is called during xml parsing.
     *
     * This method is called statictly, this is because in theory this method
     * may be used as a type of constructor, or factory method.
     *
     * Often you want to return an instance of the current class, but you are
     * free to return other data as well.
     *
     * You are responsible for advancing the reader to the next element. Not
     * doing anything will result in a never-ending loop.
     *
     * If you just want to skip parsing for this element altogether, you can
     * just call $reader->next();
     *
     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
     * the next element.
     *
     * @param Reader $reader
     * @return mixed
     */
    static function xmlDeserialize(Reader $reader) {

        $self = new self();

        $elementMap = $reader->elementMap;
        $elementMap['{DAV:}prop']   = 'Sabre\DAV\Xml\Element\Prop';
        $elementMap['{DAV:}set']    = 'Sabre\Xml\Element\KeyValue';
        $elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue';

        $elems = $reader->parseInnerTree($elementMap);

        foreach ($elems as $elem) {
            if ($elem['name'] === '{DAV:}set') {
                $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']);
            }
            if ($elem['name'] === '{DAV:}remove') {

                // Ensuring there are no values.
                foreach ($elem['value']['{DAV:}prop'] as $remove => $value) {
                    $self->properties[$remove] = null;
                }

            }
        }

        return $self;

    }
Exemplo n.º 27
0
 /**
  *
  * Component loading and tree construction.
  *
  */
 public static function xmlDeserialize(Reader $reader)
 {
     $class_name = get_called_class();
     $component = new $class_name();
     /* First settings. */
     $component->_nodename = 'views';
     /* Iterate through children. */
     $children = $reader->parseInnerTree();
     if (!is_array($children)) {
         return $component;
     }
     foreach ($children as $child) {
         $component->_value[] = self::rec_xmlDeserialize($child, $component);
     }
     return $component;
 }
Exemplo n.º 28
0
    function testDeserializeValueObjectEmpty()
    {
        $input = <<<XML
<?xml version="1.0"?>
<foo xmlns="urn:foo" />
XML;
        $reader = new Reader();
        $reader->xml($input);
        $reader->elementMap = ['{urn:foo}foo' => function (Reader $reader) {
            return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo');
        }];
        $output = $reader->parse();
        $vo = new TestVo();
        $expected = ['name' => '{urn:foo}foo', 'value' => $vo, 'attributes' => []];
        $this->assertEquals($expected, $output);
    }
Exemplo n.º 29
0
 /**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $self = new self();
     $reader->pushContext();
     $reader->elementMap['{DAV:}prop'] = 'Sabre\\Xml\\Element\\Elements';
     foreach (KeyValue::xmlDeserialize($reader) as $k => $v) {
         switch ($k) {
             case '{DAV:}prop':
                 $self->properties = $v;
                 break;
             case '{DAV:}allprop':
                 $self->allProp = true;
         }
     }
     $reader->popContext();
     return $self;
 }
Exemplo n.º 30
0
 /**
  * @inheritdoc
  */
 protected function addIssuesFromXml(Reader $xml)
 {
     $xmlArray = $xml->parse();
     foreach ((array) $xmlArray['value'] as $fileTag) {
         if ($fileTag['name'] != '{}file') {
             continue;
         }
         $fileName = $fileTag['attributes']['name'];
         foreach ((array) $fileTag['value'] as $issueTag) {
             $line = $issueTag['attributes']['beginline'];
             $tool = 'PHPMessDetector';
             $type = $issueTag['attributes']['rule'];
             $message = $issueTag['value'];
             $this->result->addIssue($fileName, $line, $tool, $type, $message);
         }
     }
 }