-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds detection for application starting mode, to skip some initializa…
…tion parts.
- Loading branch information
1 parent
d95f6b0
commit 4e28645
Showing
5 changed files
with
54 additions
and
13 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
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application; | ||
|
||
use Spiral\Boot\EnvironmentInterface; | ||
use Spiral\Boot\Injector\InjectableEnumInterface; | ||
use Spiral\Boot\Injector\ProvideFrom; | ||
|
||
#[ProvideFrom(method: 'detect')] | ||
enum Mode implements InjectableEnumInterface | ||
{ | ||
case Cli; | ||
case RoadRunner; | ||
|
||
public function insideRoadRunner(): bool | ||
{ | ||
return $this === self::RoadRunner; | ||
} | ||
|
||
public static function detect(EnvironmentInterface $environment): self | ||
{ | ||
$value = $environment->get('MODE'); | ||
|
||
return match ($value) { | ||
'roadrunner', 'rr' => self::RoadRunner, | ||
default => self::Cli, | ||
}; | ||
} | ||
} |