Skip to content

Commit

Permalink
Use enum for runtime (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
inverse authored Feb 22, 2024
1 parent 218a923 commit 5bcad57
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion serverless.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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();

$this[NotifierInterface::class] = static fn () => (new NotifierFactory(new MultiNotifier()))->create($config);

$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()));
Expand Down
11 changes: 11 additions & 0 deletions src/Runtime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Inverse\Termin;

enum Runtime
{
case SERVERLESS;
case NORMAL;
}

0 comments on commit 5bcad57

Please sign in to comment.