当前位置: 首页>>代码示例>>PHP>>正文


PHP Xml\Reader类代码示例

本文整理汇总了PHP中Sabre\Xml\Reader的典型用法代码示例。如果您正苦于以下问题:PHP Reader类的具体用法?PHP Reader怎么用?PHP Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Reader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDeserialize

    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);
    }
开发者ID:sMataruev,项目名称:sabre-xml,代码行数:27,代码来源:ElementsTest.php

示例2: xmlDeserialize

 /**
  * 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;
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:50,代码来源:PropFilter.php

示例3: xmlDeserialize

 /**
  * 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;
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:54,代码来源:SyncCollectionReport.php

示例4: xmlDeserialize

 /**
  * 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;
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:28,代码来源:ExpandPropertyReport.php

示例5: xmlDeserialize

 /**
  * 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;
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:51,代码来源:PropFilter.php

示例6: parse

 function parse($xml, array $elementMap = [])
 {
     $reader = new Reader();
     $reader->elementMap = array_merge($this->elementMap, $elementMap);
     $reader->xml($xml);
     return $reader->parse();
 }
开发者ID:Radiergummi,项目名称:anacronism,代码行数:7,代码来源:XmlTest.php

示例7: xmlDeserialize

 /**
  * 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;
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:53,代码来源:CompFilter.php

示例8: xmlDeserialize

 /**
  * 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;
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:47,代码来源:FreeBusyQueryReport.php

示例9: read

 public function read($path)
 {
     parent::read($path);
     $reader = new Reader();
     $reader->xml($this->contents);
     $this->parsed = $reader->parse();
     return $this;
 }
开发者ID:kitbs,项目名称:twine,代码行数:8,代码来源:AbstractXML.php

示例10: parse

 function parse($xml)
 {
     $reader = new Reader();
     $reader->elementMap['{DAV:}root'] = 'Sabre\\DAVACL\\Xml\\Property\\CurrentUserPrivilegeSet';
     $reader->xml($xml);
     $result = $reader->parse();
     return $result['value'];
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:8,代码来源:CurrentUserPrivilegeSetTest.php

示例11: xmlDeserialize

 /**
  * 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);
 }
开发者ID:kenwi,项目名称:core,代码行数:31,代码来源:taglist.php

示例12: xmlDeserialize

 /**
  * 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);
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:16,代码来源:ShareTypeList.php

示例13: testParseReturnsArray

 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);
 }
开发者ID:dennisenderink,项目名称:makelaars-import,代码行数:10,代码来源:RealworksTest.php

示例14: xmlDeserialize

 /**
  * 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;
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:31,代码来源:PrincipalSearchPropertySetReport.php

示例15: xmlDeserialize

 /**
  * 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);
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:33,代码来源:ShareResource.php


注:本文中的Sabre\Xml\Reader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。