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


PHP Reader::parseAttributes方法代码示例

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


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

示例1: 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

示例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, '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

示例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)
 {
     $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

示例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.
  *
  * 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->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, 'text-match' => null];
     $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 . '}is-not-defined':
                     $result['is-not-defined'] = true;
                     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,代码行数:41,代码来源:ParamFilter.php

示例5: xmlDeserialize

 /**
  * Convert XML Elements to IodefElement Objects
  * @param  SabreReader $reader [description]
  * @return IodefElement
  */
 public static function xmlDeserialize(SabreReader $reader)
 {
     $IodefElement = new static();
     $IodefElement->setAttributes($reader->parseAttributes());
     $innerData = $reader->parseInnerTree();
     // parseInnerTree will return an array or string.
     if (is_array($innerData)) {
         foreach ($innerData as $child) {
             // This should always and only by of type 'object'.
             if (gettype($child['value']) == 'object') {
                 $className = $child['value']->getShortName();
                 if (substr($IodefElement->elements[$className], -6) == '_MULTI') {
                     $IodefElement->{$className}[] = $child['value'];
                 } else {
                     $IodefElement->{$className} = $child['value'];
                 }
             }
         }
     } else {
         if (!empty($innerData)) {
             $IodefElement->value = $innerData;
         }
     }
     return $IodefElement;
 }
开发者ID:marknl,项目名称:iodef,代码行数:30,代码来源:IodefElement.php

示例6: parseCurriculumXml

 /**
  * Parse the curriculum definition file.
  *
  * By passing the official curriculum definition file (XML), this method
  * will parse it and return a curriculum definition it can understand and
  * treat. It mainly needs a "dictionary" of term types.
  *
  * @param string $curriculumXml
  *    The curriculum definition file, in XML.
  * @param string $variant
  *    (optional) The variant of the curriculum to parse. Defaults to 'V_EF'.
  *
  * @return array
  *    An object with 2 properties:
  *    - curriculum: A parsed and prepared curriculum tree. It uses
  *      Educa\DSB\Client\Curriculum\Term\LP21Term elements to define
  *      the curriculum tree.
  *    - dictionary: A dictionary of term identifiers, with name and type
  *      information for each one of them.
  *
  * @see \Educa\DSB\Client\Curriculum\LP21Curriculum::setCurriculumDictionary()
  */
 public static function parseCurriculumXml($curriculumXml, $variant = 'V_EF')
 {
     $reader = new Reader();
     // Prepare custom handlers for reading an XML node. See the Sabre\Xml
     // documentation for more information.
     $baseHandler = function ($reader) use($variant) {
         $node = new \stdClass();
         // Fetch the attributes. We want the UUID attribute.
         $attributes = $reader->parseAttributes();
         $node->uuid = trim($attributes['uuid']);
         // We derive the type from the node name.
         $node->type = strtolower(str_replace('{}', '', trim($reader->getClark())));
         // Give a default description.
         $node->description = (object) array('de' => '');
         // Fetch the descendants.
         $children = $reader->parseInnerTree();
         if (!empty($children)) {
             $node->children = array();
             foreach ($children as $child) {
                 // Look for child types that are relevant for us. Some must
                 // be parsed as child types of their own, others should be
                 // treated as being part of the current node.
                 if (in_array($child['name'], array('{}fach', '{}kompetenzbereich', '{}handlungs-themenaspekt', '{}kompetenz', '{}kompetenzstufe'))) {
                     $node->children[] = $child;
                 } elseif ($child['name'] == '{}bezeichnung') {
                     $node->description = (object) array_reduce($child['value'], function ($carry, $item) {
                         $langcode = strtolower(str_replace('{}', '', $item['name']));
                         $carry[$langcode] = $item['value'];
                         return $carry;
                     }, array());
                 } elseif ($child['name'] == '{}kantone') {
                     $node->cantons = array_map('trim', explode(',', $child['value']));
                 }
             }
         }
         if (!empty($node->cantons) && !in_array($variant, $node->cantons)) {
             return null;
         }
         return $node;
     };
     $kompetenzstufeHandler = function ($reader) use($variant) {
         $nodes = array();
         $cycle = $url = $version = $code = null;
         // Fetch the descendants.
         $children = $reader->parseInnerTree();
         if (!empty($children)) {
             foreach ($children as $child) {
                 if ($child['name'] == '{}absaetze') {
                     $nodes = $child['value'];
                 } elseif ($child['name'] == '{}zyklus') {
                     $cycle = trim($child['value']);
                 } elseif ($child['name'] == '{}lehrplanversion') {
                     $version = trim($child['value']);
                 } elseif ($child['name'] == '{}kanton' && $child['attributes']['id'] == $variant) {
                     foreach ($child['value'] as $grandChild) {
                         if ($grandChild['name'] == '{}code') {
                             $code = trim($grandChild['value']);
                         } elseif ($grandChild['name'] == '{}url') {
                             $url = trim($grandChild['value']);
                         }
                     }
                 }
             }
         }
         // Map all the Kompetenzstufe properties to the child Absaetzen.
         return array_map(function ($node) use($cycle, $url, $version, $code) {
             if (isset($cycle)) {
                 $node->cycle = $cycle;
             }
             if (isset($url)) {
                 $node->url = $url;
             }
             if (isset($version)) {
                 $node->version = $version;
             }
             if (isset($code)) {
                 $node->code = $code;
             }
//.........这里部分代码省略.........
开发者ID:educach,项目名称:dsb-client,代码行数:101,代码来源:LP21Curriculum.php


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