### Complete Example iCalendar VCALENDAR Source: https://github.com/spatie/icalendar-generator/blob/main/tests/__snapshots__/IntegrationTest__it_can_create_a_calendar__1.txt This snippet provides a full example of an iCalendar (.ics) file. It includes the VCALENDAR container, definitions for two timezones (UTC and Europe/Brussels), and three event definitions (VEVENT). It demonstrates common iCalendar properties for events, such as UID, DTSTAMP, SUMMARY, DESCRIPTION, LOCATION, ORGANIZER, ATTENDEE, GEO, URL, and embedded alarms (VALARM). Note the use of folded lines (e.g., for DESCRIPTION and X-APPLE-STRUCTURED-LOCATION) where property values are split across multiple physical lines by preceding continuation lines with a space or tab. ```iCalendar BEGIN:VCALENDAR VERSION:2.0 PRODID:spatie/icalendar-generator NAME:Laracon online X-WR-CALNAME:Laracon online REFRESH-INTERVAL;VALUE=DURATION:PT5M X-PUBLISHED-TTL:PT5M BEGIN:VTIMEZONE TZID:UTC BEGIN:STANDARD DTSTART:20180609T150000 TZOFFSETFROM:+0000 TZOFFSETTO:+0000 END:STANDARD END:VTIMEZONE BEGIN:VTIMEZONE TZID:Europe/Brussels BEGIN:STANDARD DTSTART:20181028T030000 TZOFFSETFROM:+0200 TZOFFSETTO:+0100 END:STANDARD BEGIN:DAYLIGHT DTSTART:20190331T020000 TZOFFSETFROM:+0100 TZOFFSETTO:+0200 END:DAYLIGHT END:VTIMEZONE BEGIN:VEVENT UID:uuid_1 DTSTAMP:20190306T160000Z DESCRIPTION:This description is way too long and should be put onto two dif ferent lines in the vcalendar LOCATION:Samberstraat 69D\, 2060 Antwerp\, Belgium CLASS:PUBLIC STATUS:TENTATIVE TRANSP:TRANSPARENT ORGANIZER;CN=Ruben:MAILTO:ruben@spatie.be URL:http://example.com/pub/calendars/jsmith/mytime.ics ATTENDEE;CN=Brent;PARTSTAT=ACCEPTED:MAILTO:brent@spatie.be ATTENDEE;CN=Alex;PARTSTAT=DECLINED:MAILTO:alex@spatie.be ATTENDEE;CN=Freek;PARTSTAT=TENTATIVE:MAILTO:freek@spatie.be DTSTART:20190306T150000Z DTEND:20190306T160000Z GEO:51.2343;4.4287 X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=Samberstraat 69D\, 2060 Ant werp\, Belgium;X-APPLE-RADIUS=72;X-TITLE=Spatie HQ:geo:51.2343,4.4287 BEGIN:VALARM ACTION:DISPLAY TRIGGER:-PT5M DESCRIPTION:Laracon online is going to start in five mintutes END:VALARM BEGIN:VALARM ACTION:DISPLAY TRIGGER;RELATED=END:PT5M DESCRIPTION:Laracon online has ended\, see you next year! END:VALARM BEGIN:VALARM ACTION:DISPLAY TRIGGER;VALUE=DATE-TIME:20200516T120000Z DESCRIPTION:Laracon online has ended\, see you next year! END:VALARM END:VEVENT BEGIN:VEVENT UID:uuid_2 DTSTAMP:20190306T150000Z SUMMARY:Laracon Online DTSTART:20190306T150000Z DTEND:20190307T150000Z END:VEVENT BEGIN:VEVENT UID:uuid_3 DTSTAMP:20190306T160000Z SUMMARY:In a timezone URL: DTSTART;TZID=Europe/Brussels:20190306T000000 END:VEVENT END:VCALENDAR ``` -------------------------------- ### Installing spatie/icalendar-generator - Bash Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Provides the Composer command necessary to install the spatie/icalendar-generator package into a PHP project. Composer is the dependency manager for PHP. ```bash composer require spatie\/icalendar-generator ``` -------------------------------- ### Creating Basic Event with Start Date - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows the minimal requirement for creating an Event: using Event::create() and setting a start date/time using startsAt. The event name is optional. ```php Event::create('Laracon Online') ->startsAt(new DateTime('6 march 2019')); ``` -------------------------------- ### Creating Basic Calendar and Event - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates creating a Calendar instance, adding an Event with start and end times using PHP's DateTime, and generating the iCalendar string output. This snippet shows the basic usage of the library's fluent API for calendar and event generation. ```php use Spatie\IcalendarGenerator\Components\Calendar; use Spatie\IcalendarGenerator\Components\Event; Calendar::create('Laracon online') ->event(Event::create('Creating calender feeds') ->startsAt(new DateTime('6 March 2019 15:00')) ->endsAt(new DateTime('6 March 2019 16:00')) ) ->get(); ``` -------------------------------- ### Adding Attendees to Event - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates adding multiple attendees to an event using the attendee method. It shows examples of adding attendees with just an email and with both email and name. ```php Event::create() ->attendee('ruben@spatie.be') \/\/ only an email address is required ->attendee('brent@spatie.be', 'Brent') ... ``` -------------------------------- ### Example Generated iCalendar Output Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows the textual output in the iCalendar format (RFC 5545) generated by the preceding PHP code snippet. This is the standard format that calendar applications consume. ```icalendar BEGIN:VCALENDAR VERSION:2.0 PRODID:spatie\/icalendar-generator NAME:Laracon online X-WR-CALNAME:Laracon online BEGIN:VEVENT UID:5ef5c3f64cb2c DTSTAMP;TZID=UTC:20200626T094630 SUMMARY:Creating calendar feeds DTSTART:20190306T150000Z DTEND:20190306T160000Z DTSTAMP:20190419T135034Z END:VEVENT END:VCALENDAR ``` -------------------------------- ### Setting Event Period (Start/End) - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Provides a convenient shorthand method, period, to set both the start and end dates/times for an event in a single method call. ```php Event::create('Laracon Online') ->period(new DateTime('6 march 2019'), new DateTime('7 march 2019')); ``` -------------------------------- ### Generating iCalendar String Output - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Explains how to convert a configured Calendar object into its final iCalendar string representation using the get method, which is the format ready for output or download. ```php Calendar::create('Laracon Online')->get(); \/\/ BEGIN:VCALENDAR ... ``` -------------------------------- ### Initializing Calendar Object - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates the most basic way to create a new instance of the Calendar component using its static create method, preparing it for configuration. ```php $calendar = Calendar::create(); ``` -------------------------------- ### Running Package Tests Bash Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Command-line instruction to execute the test suite defined for the package. This command uses Composer, the PHP dependency manager, to run the tests specified in the package's configuration. ```Bash composer test ``` -------------------------------- ### Using Carbon Dates with Events - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates seamless integration with the popular Carbon date/time library in PHP, showing how Carbon objects can be used with date-related methods like startsAt. ```php use Carbon\Carbon; Event::create('Laracon Online') ->startsAt(Carbon::now()) ... ``` -------------------------------- ### Adding Description to Calendar - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Illustrates adding both a name and a description to a calendar instance using chained method calls after creation. ```php $calendar = Calendar::create() ->name('Laracon Online') ->description('Experience Laracon all around the world'); ``` -------------------------------- ### Naming a Calendar - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows how to set a name for the calendar directly upon creation by passing a string argument to the static create method. ```php $calendar = Calendar::create('Laracon Online'); ``` -------------------------------- ### Setting Multiple Event Properties - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Illustrates setting various common properties on an Event object using chained method calls like name, description, uniqueIdentifier, createdAt, startsAt, and endsAt. ```php Event::create() ->name('Laracon Online') ->description('Experience Laracon all around the world') ->uniqueIdentifier('A unique identifier can be set here') ->createdAt(new DateTime('6 march 2019')) ->startsAt(new DateTime('6 march 2019 15:00')) ->endsAt(new DateTime('6 march 2019 16:00')); ``` -------------------------------- ### Setting Event Organizer - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows how to specify the organizer of an event using the organizer method, which requires an email address and optionally accepts a name for the organizer. ```php Event::create() ->organizer('ruben@spatie.be', 'Ruben') ... ``` -------------------------------- ### Setting Attendee Participation Status - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows how to specify the participation status of an attendee when adding them using the attendee method, leveraging the ParticipationStatus enum. ```php Event::create() ->attendee('ruben@spatie.be', 'Ruben', ParticipationStatus::Accepted) ... ``` -------------------------------- ### Adding Event (Closure) to Calendar - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows an alternative method for adding and configuring an event by passing a closure to the event method. The closure receives the Event object as an argument. ```php \/\/ As a closure Calendar::create('Laracon Online') ->event(function(Event $event){ $event->name('Creating calender feeds'); }) ... ``` -------------------------------- ### Creating a Full-Day Event - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates how to create an event that spans an entire day, typically affecting how the event is displayed in the calendar application. ```php Event::create() ->fullDay() ... ``` -------------------------------- ### Setting Event Status - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows how to set the status of an event using the status method with values from the EventStatus enum (Confirmed, Cancelled, or Tentative). ```php Event::create() ->status(EventStatus::Cancelled) ... ``` -------------------------------- ### Making Event Transparent - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows how to mark an event as transparent using the transparent method, indicating that it does not block the user's free time in the calendar application. ```php Event::create() ->transparent() ... ``` -------------------------------- ### Appending Text Property to Calendar Component PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates how to add a simple text property like ORGANIZER to a Calendar object using the appendProperty method. This requires creating a TextProperty instance with the desired property name and value. ```PHP Calendar::create() ->appendProperty( TextProperty::create('ORGANIZER', 'ruben@spatie.be') ) ... ``` -------------------------------- ### Adding URL Attachments to Event - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows how to add attachments linked via a URL to an event using the attachment method. It supports specifying the URL and an optional MIME type. ```php Event::create() ->attachment('https:\/\/spatie.be\/logo.svg') ->attachment('https:\/\/spatie.be\/feed.xml', 'application\/json') ... ``` -------------------------------- ### Adding Images to Event - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows how to associate images with an event using the image method. It supports specifying the image URL, MIME type, and a display type from the Display enum. ```php Event::create() ->image('https:\/\/spatie.be\/logo.svg') ->image('https:\/\/spatie.be\/logo.svg', 'text\/svg+xml') ->image('https:\/\/spatie.be\/logo.svg', 'text\/svg+xml', Display::Badge) ... ``` -------------------------------- ### Adding Multiple Events (Array) to Calendar - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates adding several Event objects to a Calendar instance by passing an array of event objects to the event method. ```php \/\/ As an array of events Calendar::create('Laracon Online') ->event([ Event::create('Creating calender feeds'), Event::create('Creating contact lists'), ]) ... ``` -------------------------------- ### Appending Event Subcomponent to Calendar PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Illustrates adding a subcomponent, specifically an Event, to a Calendar object using the appendSubComponent method. This requires creating the subcomponent instance beforehand, typically using its create method. ```PHP Calendar::create() ->appendSubComponent( Event::create('Extending icalendar-generator') ) ... ``` -------------------------------- ### Setting Calendar Refresh Interval - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates setting the refresh interval for the calendar (X-PUBLISH-TTL property) using the refreshInterval method, specified in minutes, advising the consuming application how often to check for updates. ```php Calendar::create('Laracon Online') ->refreshInterval(5) ... ``` -------------------------------- ### Adding Parameter to Property and Appending PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows how to add additional parameters, such as a Common Name (CN), to a property instance using the addParameter method. The modified property is then appended to a calendar component. ```PHP $property = TextProperty::create('ORGANIZER', 'ruben@spatie.be') ->addParameter(Parameter::create('CN', 'RUBEN VAN ASSCHE')); Calendar::create() ->appendProperty($property) ... ``` -------------------------------- ### Adding Location Details to Event - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates adding physical location information to an event, including the street address, a name for the location, and geographical coordinates. ```php Event::create() ->address('Kruikstraat 22, 2018 Antwerp, Belgium') ->addressName('Spatie HQ') ->coordinates(51.2343, 4.4287) ... ``` -------------------------------- ### Requiring Attendee Response - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates how to indicate that an attendee is required to RSVP to the event by using the requiresResponse parameter in the attendee method. ```php Event::create() ->attendee('ruben@spatie.be', 'Ruben', ParticipationStatus::NeedsAction, requiresResponse: true) ... ``` -------------------------------- ### Adding Single Event to Calendar - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Shows one method for adding an existing Event object to a Calendar instance by passing the event object directly to the event method. ```php \/\/ As a single event parameter $event = Event::create('Creating calendar feeds'); Calendar::create('Laracon Online') ->event($event) ... ``` -------------------------------- ### Setting Event Sequence Number - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates how to set the sequence number (SEQUENCE property) for an event using the sequence method, indicating the revision number of the event. ```php Event::create() ->sequence(1) ... ``` -------------------------------- ### Setting Event Classification - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates setting the classification level of an event using the classification method with values from the Classification enum (Public, Private, or Confidential). ```php Event::create() ->classification(Classification::Private) ... ``` -------------------------------- ### Updating Enum Usage (2.x to 3.x) - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/UPGRADING.md This snippet illustrates the required change in syntax for accessing enum values when upgrading from version 2.x to 3.x. Due to the migration from spatie/enum to native PHP enums, the syntax changes from a method call (::january()) to accessing a static case property (::January). ```php RecurrenceMonth::january(); // old RecurrenceMonth::January; // new ``` -------------------------------- ### Adding Embedded (Base64) Attachments - PHP Source: https://github.com/spatie/icalendar-generator/blob/main/README.md Demonstrates adding attachments directly embedded within the iCalendar file as base64 encoded data using the embeddedAttachment method. It allows providing the content string, MIME type, and controlling encoding. ```php Event::create() ->embeddedAttachment($file->toString()) ->embeddedAttachment($fileString, 'application\/json') ->embeddedAttachment($base64String, 'application\/json', needsEncoding: false) ... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.