Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ics as file #174

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Generators/Ics.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class Ics implements Generator
{
public const OPTION_AS_FILE = 'as_file';

/** @var string {@see https://www.php.net/manual/en/function.date.php} */
protected $dateFormat = 'Ymd';
/** @var string */
Expand Down Expand Up @@ -64,6 +66,10 @@ public function generate(Link $link): string
$url[] = 'END:VEVENT';
$url[] = 'END:VCALENDAR';

if ($this->options[self::OPTION_AS_FILE] ?? false) {
return implode("\r\n", $url);
}

return $this->buildLink($url);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Generators/IcsGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ public function it_has_a_product_dtstamp(): void
$this->generator(['DTSTAMP' => '20180201T090000Z'])->generate($this->createShortEventLink())
);
}

/** @test */
public function it_can_generate_a_file(): void
{
$this->assertMatchesSnapshot(
$this->generator([Ics::OPTION_AS_FILE => true])->generate($this->createShortEventLink())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:Spatie calendar-links
BEGIN:VEVENT
UID:94ab75add84a67c019eae57539658036
SUMMARY:Birthday
DTSTAMP:20180201T090000Z
DTSTART:20180201T090000Z
DTEND:20180201T180000Z
DESCRIPTION:With balloons\, clowns and stuff\nBring a dog\, bring a frog
LOCATION:Party Lane 1A\, 1337 Funtown
END:VEVENT
END:VCALENDAR