Example #1
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 = ['contentType' => $reader->getAttribute('content-type') ?: 'text/calendar', 'version' => $reader->getAttribute('version') ?: '2.0'];
     $elems = (array) $reader->parseInnerTree();
     foreach ($elems as $elem) {
         switch ($elem['name']) {
             case '{' . Plugin::NS_CALDAV . '}expand':
                 $result['expand'] = ['start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null, 'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null];
                 if (!$result['expand']['start'] || !$result['expand']['end']) {
                     throw new BadRequest('The "start" and "end" attributes are required when expanding calendar-data');
                 }
                 if ($result['expand']['end'] <= $result['expand']['start']) {
                     throw new BadRequest('The end-date must be larger than the start-date when expanding calendar-data');
                 }
                 break;
         }
     }
     return $result;
 }
 /**
  * @param \GuzzleHttp\Psr7\Response $response
  * @return Element[]
  */
 public function map(Response $response)
 {
     $reader = new Reader();
     $reader->elementMap = ['{}element' => function (Reader $reader) {
         $id = $reader->getAttribute('id');
         $parsed = KeyValue::xmlDeserialize($reader);
         $name = $parsed['{}name'];
         $desc = $parsed['{}description'];
         $score = $parsed['{}score'];
         return new Element($id, $name, $desc, $score, 'knowledge');
     }, '{}knowledge' => function (Reader $reader) {
         $items = [];
         $children = $reader->parseGetElements();
         foreach ($children as $child) {
             $items[] = $child['value'];
         }
         return $items;
     }];
     $reader->xml($response->getBody());
     $parsed = $reader->parse();
     return $parsed['value'];
 }
 /**
  * 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();
     $foundSearchProp = false;
     $self->test = 'allof';
     if ($reader->getAttribute('test') === 'anyof') {
         $self->test = 'anyof';
     }
     $elemMap = ['{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue'];
     foreach ($reader->parseInnerTree($elemMap) as $elem) {
         switch ($elem['name']) {
             case '{DAV:}prop':
                 $self->properties = array_keys($elem['value']);
                 break;
             case '{DAV:}property-search':
                 $foundSearchProp = true;
                 // This property has two sub-elements:
                 //   {DAV:}prop - The property to be searched on. This may
                 //                also be more than one
                 //   {DAV:}match - The value to match with
                 if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) {
                     throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element');
                 }
                 foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) {
                     $self->searchProperties[$propName] = $elem['value']['{DAV:}match'];
                 }
                 break;
             case '{DAV:}apply-to-principal-collection-set':
                 $self->applyToPrincipalCollectionSet = true;
                 break;
         }
     }
     if (!$foundSearchProp) {
         throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element');
     }
     return $self;
 }
Example #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 = ['contentType' => $reader->getAttribute('content-type') ?: 'text/vcard', 'version' => $reader->getAttribute('version') ?: '3.0'];
     $reader->next();
     return $result;
 }