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


PHP Component::create方法代码示例

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


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

示例1: createComponent

 /**
  * Creates a new component
  *
  * This method automatically searches for the correct component class, based
  * on its name.
  *
  * You can specify the children either in key=>value syntax, in which case
  * properties will automatically be created, or you can just pass a list of
  * Component and Property object.
  *
  * @param string $name
  * @param array $children
  * @return Component
  */
 public function createComponent($name, array $children = array())
 {
     $component = Component::create($name);
     foreach ($children as $k => $v) {
         if ($v instanceof Node) {
             $component->add($v);
         } else {
             $component->add($k, $v);
         }
     }
     return $component;
 }
开发者ID:TamirAl,项目名称:hubzilla,代码行数:26,代码来源:Document.php

示例2: readLine

 /**
  * Reads and parses a single line.
  *
  * This method receives the full array of lines. The array pointer is used
  * to traverse.
  *
  * @param array $lines
  * @return Element
  */
 private static function readLine(&$lines)
 {
     $line = current($lines);
     $lineNr = key($lines);
     next($lines);
     // Components
     if (stripos($line, "BEGIN:") === 0) {
         $componentName = strtoupper(substr($line, 6));
         $obj = Component::create($componentName);
         $nextLine = current($lines);
         while (stripos($nextLine, "END:") !== 0) {
             $obj->add(self::readLine($lines));
             $nextLine = current($lines);
             if ($nextLine === false) {
                 throw new ParseException('Invalid VObject. Document ended prematurely.');
             }
         }
         // Checking component name of the 'END:' line.
         if (substr($nextLine, 4) !== $obj->name) {
             throw new ParseException('Invalid VObject, expected: "END:' . $obj->name . '" got: "' . $nextLine . '"');
         }
         next($lines);
         return $obj;
     }
     // Properties
     //$result = preg_match('/(?P<name>[A-Z0-9-]+)(?:;(?P<parameters>^(?<!:):))(.*)$/',$line,$matches);
     $token = '[A-Z0-9-\\.]+';
     $parameters = "(?:;(?P<parameters>([^:^\"]|\"([^\"]*)\")*))?";
     $regex = "/^(?P<name>{$token}){$parameters}:(?P<value>.*)\$/i";
     $result = preg_match($regex, $line, $matches);
     if (!$result) {
         throw new ParseException('Invalid VObject, line ' . ($lineNr + 1) . ' did not follow the icalendar/vcard format');
     }
     $propertyName = strtoupper($matches['name']);
     $propertyValue = preg_replace_callback('#(\\\\(\\\\|N|n|;|,))#', function ($matches) {
         if ($matches[2] === 'n' || $matches[2] === 'N') {
             return "\n";
         } else {
             return $matches[2];
         }
     }, $matches['value']);
     $obj = Property::create($propertyName, $propertyValue);
     if ($matches['parameters']) {
         foreach (self::readParameters($matches['parameters']) as $param) {
             $obj->add($param);
         }
     }
     return $obj;
 }
开发者ID:ZerGabriel,项目名称:friendica-addons,代码行数:58,代码来源:Reader.php

示例3: getResult


//.........这里部分代码省略.........
                             if ($this->end && $startTime > $this->end) {
                                 break;
                             }
                             $times[] = array($iterator->getDTStart(), $iterator->getDTEnd());
                             $iterator->next();
                         }
                     } else {
                         $startTime = $component->DTSTART->getDateTime();
                         if ($this->end && $startTime > $this->end) {
                             break;
                         }
                         $endTime = null;
                         if (isset($component->DTEND)) {
                             $endTime = $component->DTEND->getDateTime();
                         } elseif (isset($component->DURATION)) {
                             $duration = DateTimeParser::parseDuration((string) $component->DURATION);
                             $endTime = clone $startTime;
                             $endTime->add($duration);
                         } elseif ($component->DTSTART->getDateType() === Property\DateTime::DATE) {
                             $endTime = clone $startTime;
                             $endTime->modify('+1 day');
                         } else {
                             // The event had no duration (0 seconds)
                             break;
                         }
                         $times[] = array($startTime, $endTime);
                     }
                     foreach ($times as $time) {
                         if ($this->end && $time[0] > $this->end) {
                             break;
                         }
                         if ($this->start && $time[1] < $this->start) {
                             break;
                         }
                         $busyTimes[] = array($time[0], $time[1], $FBTYPE);
                     }
                     break;
                 case 'VFREEBUSY':
                     foreach ($component->FREEBUSY as $freebusy) {
                         $fbType = isset($freebusy['FBTYPE']) ? strtoupper($freebusy['FBTYPE']) : 'BUSY';
                         // Skipping intervals marked as 'free'
                         if ($fbType === 'FREE') {
                             continue;
                         }
                         $values = explode(',', $freebusy);
                         foreach ($values as $value) {
                             list($startTime, $endTime) = explode('/', $value);
                             $startTime = DateTimeParser::parseDateTime($startTime);
                             if (substr($endTime, 0, 1) === 'P' || substr($endTime, 0, 2) === '-P') {
                                 $duration = DateTimeParser::parseDuration($endTime);
                                 $endTime = clone $startTime;
                                 $endTime->add($duration);
                             } else {
                                 $endTime = DateTimeParser::parseDateTime($endTime);
                             }
                             if ($this->start && $this->start > $endTime) {
                                 continue;
                             }
                             if ($this->end && $this->end < $startTime) {
                                 continue;
                             }
                             $busyTimes[] = array($startTime, $endTime, $fbType);
                         }
                     }
                     break;
             }
         }
     }
     if ($this->baseObject) {
         $calendar = $this->baseObject;
     } else {
         $calendar = Component::create('VCALENDAR');
         $calendar->version = '2.0';
         $calendar->prodid = '-//Sabre//Sabre VObject ' . Version::VERSION . '//EN';
         $calendar->calscale = 'GREGORIAN';
     }
     $vfreebusy = Component::create('VFREEBUSY');
     $calendar->add($vfreebusy);
     if ($this->start) {
         $dtstart = Property::create('DTSTART');
         $dtstart->setDateTime($this->start, Property\DateTime::UTC);
         $vfreebusy->add($dtstart);
     }
     if ($this->end) {
         $dtend = Property::create('DTEND');
         $dtend->setDateTime($this->end, Property\DateTime::UTC);
         $vfreebusy->add($dtend);
     }
     $dtstamp = Property::create('DTSTAMP');
     $dtstamp->setDateTime(new \DateTime('now'), Property\DateTime::UTC);
     $vfreebusy->add($dtstamp);
     foreach ($busyTimes as $busyTime) {
         $busyTime[0]->setTimeZone(new \DateTimeZone('UTC'));
         $busyTime[1]->setTimeZone(new \DateTimeZone('UTC'));
         $prop = Property::create('FREEBUSY', $busyTime[0]->format('Ymd\\THis\\Z') . '/' . $busyTime[1]->format('Ymd\\THis\\Z'));
         $prop['FBTYPE'] = $busyTime[2];
         $vfreebusy->add($prop);
     }
     return $calendar;
 }
开发者ID:thermalpaste,项目名称:pydio-core,代码行数:101,代码来源:FreeBusyGenerator.php

示例4: testAddScalarParams

 function testAddScalarParams()
 {
     $comp = Component::create('VCALENDAR');
     $comp->add('myprop', 'value', array('param1' => 'value1'));
     $this->assertEquals(1, count($comp->children));
     $this->assertTrue($comp->children[0] instanceof Property);
     $this->assertEquals('MYPROP', $comp->children[0]->name);
     $this->assertEquals('value', $comp->children[0]->value);
     $this->assertEquals(1, count($comp->children[0]->parameters));
     $this->assertTrue($comp->children[0]->parameters[0] instanceof Parameter);
     $this->assertEquals('PARAM1', $comp->children[0]->parameters[0]->name);
     $this->assertEquals('value1', $comp->children[0]->parameters[0]->value);
 }
开发者ID:floffel03,项目名称:pydio-core,代码行数:13,代码来源:ComponentTest.php


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