/** * 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; }
/** * 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; }
/** * 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:}owner'] = 'Sabre\\Xml\\Element\\XmlFragment'; $values = KeyValue::xmlDeserialize($reader); $reader->popContext(); $new = new self(); $new->owner = !empty($values['{DAV:}owner']) ? $values['{DAV:}owner']->getXml() : null; $new->scope = LockInfo::SHARED; if (isset($values['{DAV:}lockscope'])) { foreach ($values['{DAV:}lockscope'] as $elem) { if ($elem['name'] === '{DAV:}exclusive') { $new->scope = LockInfo::EXCLUSIVE; } } } return $new; }
/** * @param \GuzzleHttp\Psr7\Response $response * @return JobOutlookEntity * */ public function map(Response $response) { $reader = new Reader(); $reader->elementMap = ['{}outlook' => function (Reader $reader) { $parsed = KeyValue::xmlDeserialize($reader); return new Outlook($parsed['{}category'], $parsed['{}description']); }, '{}bright_outlook' => function (Reader $reader) { $parsed = KeyValue::xmlDeserialize($reader); return new Outlook($parsed['{}category'], $parsed['{}description'], TRUE); }, '{}green' => function (Reader $reader) { $parsed = KeyValue::xmlDeserialize($reader); return new Green($parsed['{}description'], $parsed['{}category']); }, '{}salary' => function (Reader $reader) { $parsed = KeyValue::xmlDeserialize($reader); return $parsed['{}annual_median']; }, '{}job_outlook' => function (Reader $reader) { $outlooks = []; $children = $reader->parseGetElements(); $green = NULL; $salary = NULL; foreach ($children as $child) { if (isset($child['name'])) { switch ($child['name']) { case '{}outlook': $outlooks[] = $child['value']; break; case '{}bright_outlook': $outlooks[] = $child['value']; break; case '{}green': $outlooks[] = $child['value']; break; case '{}salary': $salary = $child['value']; break; } } } return new JobOutlookEntity($outlooks, $salary, $green); }]; $reader->xml($response->getBody()); $parsed = $reader->parse(); return $parsed['value']; }
/** * @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) { $elems = KeyValue::xmlDeserialize($reader); $href = null; $calendarUri = null; $inReplyTo = null; $summary = null; $status = null; foreach ($elems as $name => $value) { switch ($name) { case '{' . Plugin::NS_CALENDARSERVER . '}hosturl': foreach ($value as $bla) { if ($bla['name'] === '{DAV:}href') { $calendarUri = $bla['value']; } } break; case '{' . Plugin::NS_CALENDARSERVER . '}invite-accepted': $status = SharingPlugin::STATUS_ACCEPTED; break; case '{' . Plugin::NS_CALENDARSERVER . '}invite-declined': $status = SharingPlugin::STATUS_DECLINED; break; case '{' . Plugin::NS_CALENDARSERVER . '}in-reply-to': $inReplyTo = $value; break; case '{' . Plugin::NS_CALENDARSERVER . '}summary': $summary = $value; break; case '{DAV:}href': $href = $value; break; } } if (is_null($calendarUri)) { throw new BadRequest('The {http://calendarserver.org/ns/}hosturl/{DAV:}href element must exist'); } return new self($href, $calendarUri, $inReplyTo, $summary, $status); }