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


PHP Component::createProperty方法代码示例

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


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

示例1: readProperty

 /**
  * Reads a property or component from a line.
  *
  * @return void
  */
 protected function readProperty($line)
 {
     if ($this->options & self::OPTION_FORGIVING) {
         $propNameToken = 'A-Z0-9\\-\\._\\/';
     } else {
         $propNameToken = 'A-Z0-9\\-\\.';
     }
     $paramNameToken = 'A-Z0-9\\-';
     $safeChar = '^";:,';
     $qSafeChar = '^"';
     $regex = "/\n            ^(?P<name> [{$propNameToken}]+ ) (?=[;:])        # property name\n            |\n            (?<=:)(?P<propValue> .+)\$                      # property value\n            |\n            ;(?P<paramName> [{$paramNameToken}]+) (?=[=;:])  # parameter name\n            |\n            (=|,)(?P<paramValue>                           # parameter value\n                (?: [{$safeChar}]*) |\n                \"(?: [{$qSafeChar}]+)\"\n            ) (?=[;:,])\n            /xi";
     //echo $regex, "\n"; die();
     preg_match_all($regex, $line, $matches, PREG_SET_ORDER);
     $property = ['name' => null, 'parameters' => [], 'value' => null];
     $lastParam = null;
     /**
      * Looping through all the tokens.
      *
      * Note that we are looping through them in reverse order, because if a
      * sub-pattern matched, the subsequent named patterns will not show up
      * in the result.
      */
     foreach ($matches as $match) {
         if (isset($match['paramValue'])) {
             if ($match['paramValue'] && $match['paramValue'][0] === '"') {
                 $value = substr($match['paramValue'], 1, -1);
             } else {
                 $value = $match['paramValue'];
             }
             $value = $this->unescapeParam($value);
             if (is_null($lastParam)) {
                 throw new ParseException('Invalid Mimedir file. Line starting at ' . $this->startLine . ' did not follow iCalendar/vCard conventions');
             }
             if (is_null($property['parameters'][$lastParam])) {
                 $property['parameters'][$lastParam] = $value;
             } elseif (is_array($property['parameters'][$lastParam])) {
                 $property['parameters'][$lastParam][] = $value;
             } else {
                 $property['parameters'][$lastParam] = [$property['parameters'][$lastParam], $value];
             }
             continue;
         }
         if (isset($match['paramName'])) {
             $lastParam = strtoupper($match['paramName']);
             if (!isset($property['parameters'][$lastParam])) {
                 $property['parameters'][$lastParam] = null;
             }
             continue;
         }
         if (isset($match['propValue'])) {
             $property['value'] = $match['propValue'];
             continue;
         }
         if (isset($match['name']) && $match['name']) {
             $property['name'] = strtoupper($match['name']);
             continue;
         }
         // @codeCoverageIgnoreStart
         throw new \LogicException('This code should not be reachable');
         // @codeCoverageIgnoreEnd
     }
     if (is_null($property['value'])) {
         $property['value'] = '';
     }
     if (!$property['name']) {
         if ($this->options & self::OPTION_IGNORE_INVALID_LINES) {
             return false;
         }
         throw new ParseException('Invalid Mimedir file. Line starting at ' . $this->startLine . ' did not follow iCalendar/vCard conventions');
     }
     // vCard 2.1 states that parameters may appear without a name, and only
     // a value. We can deduce the value based on it's name.
     //
     // Our parser will get those as parameters without a value instead, so
     // we're filtering these parameters out first.
     $namedParameters = [];
     $namelessParameters = [];
     foreach ($property['parameters'] as $name => $value) {
         if (!is_null($value)) {
             $namedParameters[$name] = $value;
         } else {
             $namelessParameters[] = $name;
         }
     }
     $propObj = $this->root->createProperty($property['name'], null, $namedParameters);
     foreach ($namelessParameters as $namelessParameter) {
         $propObj->add(null, $namelessParameter);
     }
     if (strtoupper($propObj['ENCODING']) === 'QUOTED-PRINTABLE') {
         $propObj->setQuotedPrintableValue($this->extractQuotedPrintableValue());
     } else {
         $propObj->setRawMimeDirValue($property['value']);
     }
     return $propObj;
 }
开发者ID:roidelapluie,项目名称:jorani,代码行数:100,代码来源:MimeDir.php


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