-
-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry; | ||
|
||
final class MonitorConfig | ||
{ | ||
/** | ||
* @var MonitorSchedule The schedule of the monitor | ||
*/ | ||
private $schedule; | ||
|
||
/** | ||
* @var int|null The check-in margin in seconds | ||
*/ | ||
private $checkinMargin; | ||
|
||
/** | ||
* @var int|null The maximum runtime in seconds | ||
*/ | ||
private $maxRuntime; | ||
|
||
/** | ||
* @var string|null The timezone | ||
*/ | ||
private $timezone; | ||
|
||
public function __construct( | ||
MonitorSchedule $schedule, | ||
?int $checkinMargin, | ||
?int $maxRuntime, | ||
?string $timezone | ||
) { | ||
$this->schedule = $schedule; | ||
$this->checkinMargin = $checkinMargin; | ||
$this->maxRuntime = $maxRuntime; | ||
$this->timezone = $timezone; | ||
} | ||
|
||
public function getShedule(): MonitorSchedule | ||
{ | ||
return $this->schedule; | ||
} | ||
|
||
public function setSchedule(MonitorSchedule $schedule): void | ||
{ | ||
$this->schedule = $schedule; | ||
} | ||
|
||
public function getCheckinMargin(): ?int | ||
{ | ||
return $this->checkinMargin; | ||
} | ||
|
||
public function setCheckinMargin(?int $checkinMargin): void | ||
{ | ||
$this->checkinMargin = $checkinMargin; | ||
} | ||
|
||
public function getMaxRuntime(): ?int | ||
{ | ||
return $this->maxRuntime; | ||
} | ||
|
||
public function setMaxRuntime(?int $maxRuntime): void | ||
{ | ||
$this->maxRuntime = $maxRuntime; | ||
} | ||
|
||
public function getTimezone(): ?string | ||
{ | ||
return $this->timezone; | ||
} | ||
|
||
public function setTimezone(?string $timezone): void | ||
{ | ||
$this->timezone = $timezone; | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'schedule' => $this->schedule->toArray(), | ||
'checkin_margin' => $this->checkinMargin, | ||
'max_runtime' => $this->maxRuntime, | ||
'timezone' => $this->timezone, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry; | ||
|
||
final class MonitorSchedule | ||
{ | ||
/** | ||
* @var string The type of the schedule | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @var string|int The value of the schedule | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* @var MonitorScheduleUnit|null The unit of the schedule | ||
*/ | ||
private $unit; | ||
|
||
public const TYPE_CRONTAB = 'crontab'; | ||
|
||
public const TYPE_INTERVAL = 'interval'; | ||
|
||
/** | ||
* @param string $type The type of the schedule | ||
* @param string|int $value The value of the schedule | ||
* @param MonitorScheduleUnit|null $unit The unit of the schedule | ||
*/ | ||
public function __construct( | ||
string $type, | ||
$value, | ||
?MonitorScheduleUnit $unit = null | ||
) { | ||
$this->type = $type; | ||
$this->value = $value; | ||
$this->unit = $unit; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function setType(string $type): void | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @return string|int | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* @param string|int $value | ||
*/ | ||
public function setValue($value): void | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function getUnit(): ?MonitorScheduleUnit | ||
{ | ||
return $this->unit; | ||
} | ||
|
||
public function setUnit(?MonitorScheduleUnit $unit): void | ||
{ | ||
$this->unit = $unit; | ||
} | ||
|
||
/** | ||
* @return array<string, string|int> | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'type' => $this->type, | ||
'value' => $this->value, | ||
'unit' => (string) $this->unit, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry; | ||
|
||
final class MonitorScheduleUnit implements \Stringable | ||
{ | ||
/** | ||
* @var string The value of the enum instance | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* @var array<string, self> A list of cached enum instances | ||
*/ | ||
private static $instances = []; | ||
|
||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function minute(): self | ||
{ | ||
return self::getInstance('minute'); | ||
} | ||
|
||
public static function hour(): self | ||
{ | ||
return self::getInstance('hour'); | ||
} | ||
|
||
public static function day(): self | ||
{ | ||
return self::getInstance('day'); | ||
} | ||
|
||
public static function week(): self | ||
{ | ||
return self::getInstance('week'); | ||
} | ||
|
||
public static function month(): self | ||
{ | ||
return self::getInstance('month'); | ||
} | ||
|
||
public static function year(): self | ||
{ | ||
return self::getInstance('year'); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
private static function getInstance(string $value): self | ||
{ | ||
if (!isset(self::$instances[$value])) { | ||
self::$instances[$value] = new self($value); | ||
} | ||
|
||
return self::$instances[$value]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters