Lines
100.00%
10 / 10
Methods
100.00%
6 / 6
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| findOrCreateStateOf | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | ||
| activateScope | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| releaseScope | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| pauseScope | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| resumeScope | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| stopAll | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| 9 | final class ScopeLifecycle | |
| 10 | { | |
| 11 | /** @var array<string, ScopeState> */ | |
| 12 | private array $statesByScope = []; | |
| 13 | ||
| 14 | private bool $stopped = false; | |
| 15 | ||
| 16 | public function findOrCreateStateOf(ResourceScope $scope): ScopeState | |
| 17 | { | |
| 18 | return $this->statesByScope[$scope->wireValue()] ??= new ScopeState($scope, $this->stopped ? ScopePhase::Closed : ScopePhase::Starting); | |
| 19 | } | |
| 20 | ||
| 21 | public function activateScope(ResourceScope $scope): void | |
| 22 | { | |
| 23 | if ($this->stopped) { | |
| 24 | return; | |
| 25 | } | |
| 26 | ||
| 27 | $this->findOrCreateStateOf($scope)->activate(); | |
| 28 | } | |
| 29 | ||
| 30 | public function releaseScope(ResourceScope $scope): void | |
| 31 | { | |
| 32 | $this->findOrCreateStateOf($scope)->close(); | |
| 33 | } | |
| 34 | ||
| 35 | public function pauseScope(ResourceScope $scope): void | |
| 36 | { | |
| 37 | $this->findOrCreateStateOf($scope)->pause(); | |
| 38 | } | |
| 39 | ||
| 40 | public function resumeScope(ResourceScope $scope): void | |
| 41 | { | |
| 42 | $this->findOrCreateStateOf($scope)->resume(); | |
| 43 | } | |
| 44 | ||
| 45 | public function stopAll(): void | |
| 46 | { | |
| 47 | $this->stopped = true; | |
| 48 | ||
| 49 | foreach ($this->statesByScope as $state) { | |
| 50 | $state->close(); | |
| 51 | } | |
| 52 | } | |
| 53 | } |