-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove boolean flags for error recovery and shutting down and replace…
… with a State object. This will be replaced by a ENUM in future versions
- Loading branch information
1 parent
ed640dd
commit d0d51af
Showing
3 changed files
with
74 additions
and
22 deletions.
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
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,49 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the PHP Event Correlation package. | ||
* | ||
* (c) James Lucas <james@lucas.net.au> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EdgeTelemetrics\EventCorrelation\Scheduler; | ||
|
||
//enum State implements \BackedEnum { | ||
|
||
class State { | ||
|
||
public const STARTING = 'starting'; | ||
public const RECOVERY = 'recovery'; | ||
public const RUNNING = 'running'; | ||
public const STOPPING = 'stopping'; | ||
|
||
public const STOPPED = 'stopped'; | ||
|
||
public const STOPPED_UNCLEAN = 'unclean shutdown'; | ||
|
||
public const VALID_STATES = [self::STARTING, self::RECOVERY, self::RUNNING, self::STOPPING, self::STOPPED, self::STOPPED_UNCLEAN]; | ||
|
||
private string $state; | ||
|
||
public function __construct(string $state) { | ||
if (in_array($state, self::VALID_STATES, true)) { | ||
$this->state = $state; | ||
} else { | ||
throw new \RuntimeException('Invalid state ' . $state); | ||
} | ||
} | ||
|
||
public function state() : string { | ||
return $this->state; | ||
} | ||
|
||
public function isStopping() : bool { | ||
return match($this->state) { | ||
self::STOPPING => true, | ||
default => false | ||
}; | ||
} | ||
} |