From 5bcad5764672d2952d63b7a78000d870165502c6 Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Thu, 22 Feb 2024 23:01:04 +0100 Subject: [PATCH] Use enum for runtime (#92) --- serverless.php | 3 ++- src/Container.php | 4 ++-- src/Runtime.php | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 src/Runtime.php diff --git a/serverless.php b/serverless.php index 68eca36..8d1e89e 100644 --- a/serverless.php +++ b/serverless.php @@ -5,6 +5,7 @@ use Bref\Context\Context; use Inverse\Termin\Config\ConfigParser; use Inverse\Termin\Container; +use Inverse\Termin\Runtime; use Symfony\Component\Yaml\Yaml; require __DIR__.'/vendor/autoload.php'; @@ -16,7 +17,7 @@ public function handle($event, Context $context) $configLoader = new ConfigParser(); $config = $configLoader->parse(Yaml::parseFile(__DIR__.'/config.yml')); - $container = new Container($config, 'serverless'); + $container = new Container($config, Runtime::SERVERLESS); $termin = $container->getTermin(); $termin->run($config->getSites()); diff --git a/src/Container.php b/src/Container.php index ce44230..919bf95 100644 --- a/src/Container.php +++ b/src/Container.php @@ -20,7 +20,7 @@ class Container extends Pimple { private const ROOT_DIR = __DIR__.'/../'; - public function __construct(Config $config, string $runtime = 'normal') + public function __construct(Config $config, Runtime $runtime = Runtime::NORMAL) { parent::__construct(); @@ -28,7 +28,7 @@ public function __construct(Config $config, string $runtime = 'normal') $this[LoggerInterface::class] = static function () use ($config, $runtime) { $logger = new Logger('termin'); - if ($config->getLogToFile() || 'serverless' !== $runtime) { + if ($config->getLogToFile() || Runtime::SERVERLESS !== $runtime) { $logger->pushHandler(new StreamHandler(self::ROOT_DIR.'var/log/app.log', $config->getLogLevel())); } $logger->pushHandler(new StreamHandler('php://stdout', $config->getLogLevel())); diff --git a/src/Runtime.php b/src/Runtime.php new file mode 100644 index 0000000..beb5f92 --- /dev/null +++ b/src/Runtime.php @@ -0,0 +1,11 @@ +