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


PHP Reader::getAttribute方法代码示例

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


在下文中一共展示了Reader::getAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 = ['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;
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:40,代码来源:CalendarData.php

示例2: map

 /**
  * @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'];
 }
开发者ID:betterweekdays,项目名称:onet,代码行数:26,代码来源:KnowledgeDetailed.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();
     $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;
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:58,代码来源:PrincipalPropertySearchReport.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)
 {
     $result = ['contentType' => $reader->getAttribute('content-type') ?: 'text/vcard', 'version' => $reader->getAttribute('version') ?: '3.0'];
     $reader->next();
     return $result;
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:27,代码来源:AddressData.php


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