本文整理汇总了PHP中Sabre\VObject\Reader::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::read方法的具体用法?PHP Reader::read怎么用?PHP Reader::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\VObject\Reader
的用法示例。
在下文中一共展示了Reader::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readTask
/**
* read object from calendar data
*
* @param \OCA\Tasks\Db\Tasks $task
* @return mixed
*/
private function readTask($task)
{
if (is_null($task->getSummary())) {
return false;
}
return \Sabre\VObject\Reader::read($task->getCalendardata());
}
示例2: testQueryTimerange
function testQueryTimerange()
{
$request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', ['Content-Type' => 'application/xml', 'Depth' => '1']);
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120226T230000Z" end="20120228T225959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20120226T230000Z" end="20120228T225959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
$this->fail('Got no events instead of 1. Output: ' . $response->body);
}
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
// We expect 1 event
$this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
}
示例3: getBirthdayEvents
public static function getBirthdayEvents($parameters)
{
$name = $parameters['calendar_id'];
if (strpos($name, 'birthday_') != 0) {
return;
}
$info = explode('_', $name);
$aid = $info[1];
Addressbook::find($aid);
foreach (VCard::all($aid) as $contact) {
try {
$vcard = VObject\Reader::read($contact['carddata']);
} catch (Exception $e) {
continue;
}
$birthday = $vcard->BDAY;
if ($birthday) {
$date = new \DateTime($birthday);
$vevent = VObject\Component::create('VEVENT');
//$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
$vevent->add('DTSTART');
$vevent->DTSTART->setDateTime($date, VObject\Property\DateTime::DATE);
$vevent->add('DURATION', 'P1D');
$vevent->{'UID'} = substr(md5(rand() . time()), 0, 10);
// DESCRIPTION?
$vevent->{'RRULE'} = 'FREQ=YEARLY';
$title = str_replace('{name}', $vcard->FN, App::$l10n->t('{name}\'s Birthday'));
$parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title, 'calendardata' => "BEGIN:VCALENDAR\nVERSION:2.0\n" . "PRODID:ownCloud Contacts " . \OCP\App::getAppVersion('contacts') . "\n" . $vevent->serialize() . "END:VCALENDAR");
}
}
}
示例4: substr
function testIssue205()
{
$request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120325T220000Z" end="20120401T215959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:comp-filter name="VALARM">
<C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
$this->assertFalse(strpos($response->body, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $response->body);
$this->assertFalse(strpos($response->body, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $response->body);
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
$this->assertEquals(1, count($vObject->VEVENT));
}
示例5: testExpand
function testExpand()
{
$request = new HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120205T230000Z" end="20120212T225959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
// We only expect 3 events
$this->assertEquals(3, count($vObject->VEVENT), 'We got 6 events instead of 3. Output: ' . $body);
// TZID should be gone
$this->assertFalse(isset($vObject->VEVENT->DTSTART['TZID']));
}
示例6: testValid
/**
* @dataProvider provider
*/
function testValid($icalObject, $filters, $outcome)
{
$validator = new CalendarQueryValidator();
// Wrapping filter in a VCALENDAR component filter, as this is always
// there anyway.
$filters = array('name' => 'VCALENDAR', 'comp-filters' => array($filters), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => null);
$vObject = VObject\Reader::read($icalObject);
switch ($outcome) {
case 0:
$this->assertFalse($validator->validate($vObject, $filters));
break;
case 1:
$this->assertTrue($validator->validate($vObject, $filters));
break;
case -1:
try {
$validator->validate($vObject, $filters);
$this->fail('This test was supposed to fail');
} catch (\Exception $e) {
// We need to test something to be valid for phpunit strict
// mode.
$this->assertTrue(true);
}
break;
}
}
示例7: process
function process($input, $existingObject = null, $expected = false)
{
$version = \Sabre\VObject\Version::VERSION;
$vcal = Reader::read($input);
foreach ($vcal->getComponents() as $mainComponent) {
break;
}
$message = new Message();
$message->message = $vcal;
$message->method = isset($vcal->METHOD) ? $vcal->METHOD->getValue() : null;
$message->component = $mainComponent->name;
$message->uid = $mainComponent->UID->getValue();
$message->sequence = isset($vcal->VEVENT[0]) ? (string) $vcal->VEVENT[0]->SEQUENCE : null;
if ($message->method === 'REPLY') {
$message->sender = $mainComponent->ATTENDEE->getValue();
$message->senderName = isset($mainComponent->ATTENDEE['CN']) ? $mainComponent->ATTENDEE['CN']->getValue() : null;
$message->recipient = $mainComponent->ORGANIZER->getValue();
$message->recipientName = isset($mainComponent->ORGANIZER['CN']) ? $mainComponent->ORGANIZER['CN'] : null;
}
$broker = new Broker();
if (is_string($existingObject)) {
$existingObject = str_replace('%foo%', "VERSION:2.0\nPRODID:-//Sabre//Sabre VObject {$version}//EN\nCALSCALE:GREGORIAN", $existingObject);
$existingObject = Reader::read($existingObject);
}
$result = $broker->processMessage($message, $existingObject);
if (is_null($expected)) {
$this->assertTrue(!$result);
return;
}
$this->assertVObjectEqualsVObject($expected, $result);
}
示例8: testValid
/**
* @dataProvider provider
*/
function testValid($icalObject, $filters, $outcome)
{
$validator = new CalendarQueryValidator();
// Wrapping filter in a VCALENDAR component filter, as this is always
// there anyway.
$filters = array('name' => 'VCALENDAR', 'comp-filters' => array($filters), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => null);
$vObject = VObject\Reader::read($icalObject);
switch ($outcome) {
case 0:
$this->assertFalse($validator->validate($vObject, $filters));
break;
case 1:
$this->assertTrue($validator->validate($vObject, $filters));
break;
case -1:
try {
$validator->validate($vObject, $filters);
} catch (DAV\Exception $e) {
// Success
} catch (\LogicException $e) {
// Success
}
break;
}
}
示例9: getContactVCard
/**
* @brief Gets the VCard as a \Sabre\VObject\Component
* @param integer $id
* @returns \Sabre\VObject\Component|null The card or null if the card could not be parsed.
*/
public static function getContactVCard($id)
{
$card = null;
$vcard = null;
try {
$card = VCard::find($id);
} catch (\Exception $e) {
return null;
}
if (!$card) {
return null;
}
try {
$vcard = \Sabre\VObject\Reader::read($card['carddata']);
} catch (\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
\OCP\Util::writeLog('contacts', __METHOD__ . ', id: ' . $id, \OCP\Util::DEBUG);
return null;
}
if (!is_null($vcard) && !isset($vcard->REV)) {
$rev = new \DateTime('@' . $card['lastmodified']);
$vcard->REV = $rev->format(\DateTime::W3C);
}
return $vcard;
}
示例10: __construct
/**
* Constructor
*
* The splitter should receive an readable file stream as it's input.
*
* @param resource $input
* @param int $options Parser options, see the OPTIONS constants.
*/
public function __construct($input, $options = 0)
{
$data = VObject\Reader::read($input, $options);
$vtimezones = array();
$components = array();
if (!$data instanceof VObject\Component\VCalendar) {
throw new VObject\ParseException('Supplied input could not be parsed as VCALENDAR.');
}
foreach ($data->children() as $component) {
if (!$component instanceof VObject\Component) {
continue;
}
// Get all timezones
if ($component->name === 'VTIMEZONE') {
$this->vtimezones[(string) $component->TZID] = $component;
continue;
}
// Get component UID for recurring Events search
if (!$component->UID) {
$component->UID = sha1(microtime()) . '-vobjectimport';
}
$uid = (string) $component->UID;
// Take care of recurring events
if (!array_key_exists($uid, $this->objects)) {
$this->objects[$uid] = new VCalendar();
}
$this->objects[$uid]->add(clone $component);
}
}
示例11: getVCard
/**
* @throws VObject\ParseException
* @return VObject\Component\VCard
*/
private function getVCard()
{
if ($this->vcard === null) {
$this->vcard = VObject\Reader::read($this->getEntry());
}
return $this->vcard;
}
示例12: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$principalBackend = new Principal($this->config, $this->userManager);
$this->backend = new CardDavBackend($this->dbConnection, $principalBackend);
// ensure system addressbook exists
$systemAddressBook = $this->ensureSystemAddressBookExists();
$converter = new Converter();
$output->writeln('Syncing users ...');
$progress = new ProgressBar($output);
$progress->start();
$this->userManager->callForAllUsers(function ($user) use($systemAddressBook, $converter, $progress) {
/** @var IUser $user */
$name = $user->getBackendClassName();
$userId = $user->getUID();
$cardId = "{$name}:{$userId}.vcf";
$card = $this->backend->getCard($systemAddressBook['id'], $cardId);
if ($card === false) {
$vCard = $converter->createCardFromUser($user);
$this->backend->createCard($systemAddressBook['id'], $cardId, $vCard->serialize());
} else {
$vCard = Reader::read($card['carddata']);
if ($converter->updateCard($vCard, $user)) {
$this->backend->updateCard($systemAddressBook['id'], $cardId, $vCard->serialize());
}
}
$progress->advance();
});
$progress->finish();
$output->writeln('');
}
示例13: testGetDTEnd
/**
* A pretty slow test. Had to be marked as 'medium' for phpunit to not die
* after 1 second. Would be good to optimize later.
*
* @medium
*/
function testGetDTEnd()
{
$ics = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 4.0.4//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
TRANSP:OPAQUE
DTEND;TZID=America/New_York:20070925T170000
UID:uuid
DTSTAMP:19700101T000000Z
LOCATION:
DESCRIPTION:
STATUS:CONFIRMED
SEQUENCE:18
SUMMARY:Stuff
DTSTART;TZID=America/New_York:20070925T160000
CREATED:20071004T144642Z
RRULE:FREQ=MONTHLY;INTERVAL=1;UNTIL=20071030T035959Z;BYDAY=5TU
END:VEVENT
END:VCALENDAR
ICS;
$vObject = Reader::read($ics);
$it = new Recur\EventIterator($vObject, (string) $vObject->VEVENT->UID);
while ($it->valid()) {
$it->next();
}
// If we got here, it means we were successful. The bug that was in the
// system before would fail on the 5th tuesday of the month, if the 5th
// tuesday did not exist.
$this->assertTrue(true);
}
示例14: __construct
/**
* Constructor
*
* The splitter should receive an readable file stream as it's input.
*
* @param resource $input
*/
public function __construct($input)
{
$data = VObject\Reader::read(stream_get_contents($input));
$vtimezones = array();
$components = array();
foreach ($data->children as $component) {
if (!$component instanceof VObject\Component) {
continue;
}
// Get all timezones
if ($component->name === 'VTIMEZONE') {
$this->vtimezones[(string) $component->TZID] = $component;
continue;
}
// Get component UID for recurring Events search
if ($component->UID) {
$uid = (string) $component->UID;
} else {
// Generating a random UID
$uid = sha1(microtime()) . '-vobjectimport';
}
// Take care of recurring events
if (!array_key_exists($uid, $this->objects)) {
$this->objects[$uid] = VObject\Component::create('VCALENDAR');
}
$this->objects[$uid]->add(clone $component);
}
}
示例15: testExpand
/**
* This tests the expansion of dates with DAILY frequency in RRULE with BYMONTH restrictions
*/
function testExpand()
{
$ics = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 4.0.4//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
TRANSP:OPAQUE
DTEND:20070925T183000Z
UID:uuid
DTSTAMP:19700101T000000Z
LOCATION:
DESCRIPTION:
STATUS:CONFIRMED
SEQUENCE:18
SUMMARY:Stuff
DTSTART:20070925T160000Z
CREATED:20071004T144642Z
RRULE:FREQ=DAILY;BYMONTH=9,10;BYDAY=SU
END:VEVENT
END:VCALENDAR
ICS;
$vcal = Reader::read($ics);
$this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
$vcal->expand(new DateTime('2013-09-28'), new DateTime('2014-09-11'));
foreach ($vcal->VEVENT as $event) {
$dates[] = $event->DTSTART->getValue();
}
$expectedDates = array("20130929T160000Z", "20131006T160000Z", "20131013T160000Z", "20131020T160000Z", "20131027T160000Z", "20140907T160000Z");
$this->assertEquals($expectedDates, $dates, 'Recursed dates are restricted by month');
}