php Sabre-Xml-Reader类(方法)实例源码

下面列出了php Sabre-Xml-Reader 类(方法)源码代码实例,从而了解它的用法。

作者:sMatarue    项目:sabre-xm   
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);
    }

作者:BlaBlaNe    项目:hubzill   
/**
  * 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;
 }

作者:sebbie4    项目:casebo   
/**
  * 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;
 }

作者:sebbie4    项目:casebo   
/**
  * 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;
 }

作者:sebbie4    项目:casebo   
/**
  * 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;
 }

作者:Radiergumm    项目:anacronis   
function parse($xml, array $elementMap = [])
 {
     $reader = new Reader();
     $reader->elementMap = array_merge($this->elementMap, $elementMap);
     $reader->xml($xml);
     return $reader->parse();
 }

作者:BlaBlaNe    项目:hubzill   
/**
  * 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;
 }

作者:sebbie4    项目:casebo   
/**
  * 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;
 }

作者:kitb    项目:twin   
public function read($path)
 {
     parent::read($path);
     $reader = new Reader();
     $reader->xml($this->contents);
     $this->parsed = $reader->parse();
     return $this;
 }

作者:sebbie4    项目:casebo   
function parse($xml)
 {
     $reader = new Reader();
     $reader->elementMap['{DAV:}root'] = 'Sabre\\DAVACL\\Xml\\Property\\CurrentUserPrivilegeSet';
     $reader->xml($xml);
     $result = $reader->parse();
     return $result['value'];
 }

作者:kenw    项目:cor   
/**
  * 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);
 }

作者:GitHubUser423    项目:cor   
/**
  * 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);
 }

作者:dennisenderin    项目:makelaars-impor   
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);
 }

作者:BlaBlaNe    项目:hubzill   
/**
  * 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;
 }

作者:BlaBlaNe    项目:hubzill   
/**
  * 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);
 }

作者:kalma    项目:sabre-xm   
/**
  * 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();
 }

作者:sMatarue    项目:sabre-xm   
/**
  * 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();
 }

作者:BlaBlaNe    项目:hubzill   
/**
  * 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;
 }

作者:betterweekday    项目:one   
/**
  * 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;
 }

作者:mermetb    项目:biom   
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;
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号