Skip to content

Commit

Permalink
chore: fix issues with uid not showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemilloy committed May 5, 2024
1 parent 99e42d3 commit f712adf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itsnubix/nowcal",
"version": "1.2.2",
"version": "1.2.3",
"description": "A modern PHP library for generating iCalendar v2.0 events",
"keywords": [
"icalendar",
Expand Down
33 changes: 26 additions & 7 deletions src/NowCal/NowCal.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class NowCal
* @var array
*/
public const REQUIRED = [
'uid',
'stamp',
'start',
'prodid',
Expand All @@ -71,6 +70,7 @@ class NowCal
*/
public const CASTS = [
'end' => 'datetime',
'method' => 'upper',
'stamp' => 'datetime',
'start' => 'datetime',
'created' => 'datetime',
Expand All @@ -97,7 +97,7 @@ class NowCal
*
* @see https://tools.ietf.org/html/rfc5545#section-3.7.3
*/
private string $prodid = '-//itsnubix//NowCal//EN';
private string $prodid = '-//NowCal//EN';

/**
* Specifies the minimum iCalendar specification that is required
Expand Down Expand Up @@ -324,7 +324,7 @@ public function timezone(string|DateTimeZone|Closure $timezone): self
*/
public function method(string $method): self
{
$this->set('method', strtoupper($method));
$this->set('method', $method);

return $this;
}
Expand Down Expand Up @@ -386,6 +386,11 @@ protected function set(string|array $key, $val = null): void
return;
}

// if (method_exists($this, $key)) {
// $this->{$key}($val);
// return;
// }

$this->{$key} = $val;
}

Expand Down Expand Up @@ -413,6 +418,7 @@ protected function merge(array $props): void
protected function cast(mixed $value, ?string $as = null): string
{
return match ($as) {
'upper' => $this->castUpper($value),
'datetime' => $this->castDateTime($value),
'interval' => $this->castInterval($value),
'timezone' => $this->castTimezone($value),
Expand All @@ -428,6 +434,14 @@ protected function hasCaster(string $key): bool
return array_key_exists($key, static::CASTS);
}

/**
* Cast the specified value to uppercase.
*/
public function castUpper($value): string
{
return strtoupper($value);
}

/**
* Cast the specified value as a datetime.
*/
Expand Down Expand Up @@ -516,7 +530,9 @@ protected function createTimezone(): void
continue;
}

$standard = $transition;
if (!$transition['isdst']) {
$standard = $transition;
}
}

$this->output[] = 'BEGIN:STANDARD';
Expand Down Expand Up @@ -550,6 +566,7 @@ protected function formatOffset(int $offset): string
protected function createEvent(): void
{
$this->output[] = 'BEGIN:VEVENT';
$this->output[] = $this->getUidAttribute();

foreach ($this->event_parameters as $key) {
$this->output[] = $this->getParameter($key);
Expand All @@ -572,7 +589,9 @@ protected function getParameter(string $key): string
}

if ($this->required($key)) {
throw new Exception('Key "' . $key . '" is not set but is required');
$value = $this->{$key} ?? '';

return $this->getParameterKey($key) . ':' . $value;
}
}

Expand Down Expand Up @@ -632,13 +651,13 @@ protected function getEventParametersAttribute(): array
array_merge(static::VEVENT, static::ALLOWED),
fn($key) => match ($key) {
'method', 'timezone' => false,
default => $this->has($key),
default => $this->required($key) || $this->has($key),
},
);
}

/**
* Create and return a UUID.
* Create and return a uid.
*/
protected function getUidAttribute(): string
{
Expand Down
7 changes: 2 additions & 5 deletions tests/NowCal/NowCalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ public function test_places_that_do_not_witness_dst_dont_get_daylight_hours()
public function test_it_can_customize_the_uid()
{
$this->nowcal->uid($uid = 'abcd-1234');

echo $this->nowcal->plain;

$this->assertEquals('UID:' . $uid, 'UID:' . $this->nowcal->uid);
$this->assertStringContainsString('UID:' . $uid, $this->nowcal->plain);
}

public function test_it_can_set_a_sequence()
Expand All @@ -172,6 +169,6 @@ public function test_it_can_set_a_method()
{
$this->nowcal->method($method = 'request');

$this->assertEquals(strtoupper($method), $this->nowcal->method);
$this->assertEquals($method, $this->nowcal->method);
}
}

0 comments on commit f712adf

Please sign in to comment.