mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-26 22:50:29 +01:00
84 lines
1.9 KiB
PHP
84 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Xentral\Modules\GoogleCalendar\Data;
|
|
|
|
use Xentral\Modules\GoogleCalendar\Exception\InvalidArgumentException;
|
|
|
|
final class GoogleCalendarEventReminderValue
|
|
{
|
|
/** @var string METHOD_EMAIL */
|
|
public const METHOD_EMAIL = 'email';
|
|
|
|
/** @var string METHOD_POPUP */
|
|
public const METHOD_POPUP = 'popup';
|
|
|
|
/** @var string $method */
|
|
private $method;
|
|
|
|
/** @var int $minutes */
|
|
private $minutes;
|
|
|
|
/**
|
|
* @param string $method
|
|
* @param int $minutes
|
|
*
|
|
* @throws InvalidArgumentException
|
|
*/
|
|
public function __construct(string $method, int $minutes)
|
|
{
|
|
if ($method !== self::METHOD_EMAIL && $method !== self::METHOD_POPUP) {
|
|
throw new InvalidArgumentException(
|
|
'Invalid notification method; only "email" and "popup" are allowed'
|
|
);
|
|
}
|
|
$this->method = $method;
|
|
$this->minutes = $minutes;
|
|
}
|
|
|
|
/**
|
|
* @param array $data
|
|
*
|
|
* @throws InvalidArgumentException
|
|
*
|
|
* @return GoogleCalendarEventReminderValue
|
|
*/
|
|
public static function fromArray(array $data): GoogleCalendarEventReminderValue
|
|
{
|
|
if (!isset($data['method'], $data['minutes'])) {
|
|
throw new InvalidArgumentException('method and minutes required for notification values.');
|
|
}
|
|
|
|
return new self($data['method'], $data['minutes']);
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
$data = [];
|
|
$data['method'] = $this->getMethod();
|
|
$data['minutes'] = $this->getMinutes();
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getMethod(): string
|
|
{
|
|
return $this->method;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getMinutes(): int
|
|
{
|
|
return $this->minutes;
|
|
}
|
|
}
|