Skip to content

Commit a2c6d1d

Browse files
authored
Merge pull request #95 from mogic-le/cal-source
Add calendar source parameter
2 parents 65cea2b + fabbd23 commit a2c6d1d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Components/Calendar.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class Calendar extends Component implements HasTimezones
3434

3535
private ?string $productIdentifier = null;
3636

37+
private ?string $source = null;
38+
3739
public static function create(string $name = null): Calendar
3840
{
3941
return new self($name);
@@ -146,6 +148,18 @@ public function refreshInterval(int $minutes): Calendar
146148
return $this;
147149
}
148150

151+
/**
152+
* Identifies a location where a client can retrieve updated data for the calendar.
153+
*
154+
* @link https://datatracker.ietf.org/doc/html/rfc7986#section-5.7
155+
*/
156+
public function source(string $source): self
157+
{
158+
$this->source = $source;
159+
160+
return $this;
161+
}
162+
149163
public function get(): string
150164
{
151165
return $this->toString();
@@ -173,6 +187,10 @@ protected function payload(): ComponentPayload
173187
$this->description,
174188
fn () => TextProperty::create('DESCRIPTION', $this->description)->addAlias('X-WR-CALDESC')
175189
)
190+
->optional(
191+
$this->source,
192+
fn () => TextProperty::create('SOURCE', $this->source)->addParameter(new Parameter('VALUE', 'URI'))
193+
)
176194
->optional(
177195
$this->refreshInterval,
178196
fn () => DurationProperty::create('REFRESH-INTERVAL', $this->refreshInterval)->addParameter(new Parameter('VALUE', 'DURATION'))

tests/Components/CalendarTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ public function a_refresh_rate_can_be_set()
154154
->expectParameterValue('VALUE', 'DURATION');
155155
}
156156

157+
/** @test */
158+
public function a_source_can_be_set()
159+
{
160+
$payload = Calendar::create()
161+
->source('https://example.org/cal.ics')
162+
->resolvePayload();
163+
164+
PropertyExpectation::create($payload, 'SOURCE')
165+
->expectValue('https://example.org/cal.ics')
166+
->expectParameterValue('VALUE', 'URI');
167+
}
168+
157169
/** @test */
158170
public function it_will_automatically_add_multiple_timezone_components()
159171
{

0 commit comments

Comments
 (0)