Sabre\VObject\ITip\Broker::processMessage PHP Method

processMessage() public method

Examples: 1. A user is an attendee to an event. The organizer sends an updated meeting using a new iTip message with METHOD:REQUEST. This function will process the message and update the attendee's event accordingly. 2. The organizer cancelled the event using METHOD:CANCEL. We will update the users event to state STATUS:CANCELLED. 3. An attendee sent a reply to an invite using METHOD:REPLY. We can update the organizers event to update the ATTENDEE with its correct PARTSTAT. The $existingObject is updated in-place. If there is no existing object (because it's a new invite for example) a new object will be created. If an existing object does not exist, and the method was CANCEL or REPLY, the message effectively gets ignored, and no 'existingObject' will be created. The updated $existingObject is also returned from this function. If the iTip message was not supported, we will always return false.
public processMessage ( Sabre\VObject\ITip\Message $itipMessage, Sabre\VObject\Component\VCalendar $existingObject = null ) : Sabre\VObject\Component\VCalendar | null
$itipMessage Sabre\VObject\ITip\Message
$existingObject Sabre\VObject\Component\VCalendar
return Sabre\VObject\Component\VCalendar | null
    public function processMessage(Message $itipMessage, VCalendar $existingObject = null)
    {
        // We only support events at the moment.
        if ($itipMessage->component !== 'VEVENT') {
            return false;
        }
        switch ($itipMessage->method) {
            case 'REQUEST':
                return $this->processMessageRequest($itipMessage, $existingObject);
            case 'CANCEL':
                return $this->processMessageCancel($itipMessage, $existingObject);
            case 'REPLY':
                return $this->processMessageReply($itipMessage, $existingObject);
            default:
                // Unsupported iTip message
                return null;
        }
        return $existingObject;
    }

Usage Example

Example #1
0
 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);
 }
All Usage Examples Of Sabre\VObject\ITip\Broker::processMessage