implement environment model

This commit is contained in:
yggverse 2024-05-04 19:26:15 +03:00
parent ecc7c66143
commit 048ae2c3ac
2 changed files with 39 additions and 3 deletions

34
src/Model/Environment.php Normal file
View file

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Yggverse\Pulsar\Model;
class Environment
{
private array $_argument;
public function __construct(
array $argv
) {
foreach ($argv as $value)
{
if (preg_match('/^(?<key>[^=]+)=(?<value>.*)$/', $value, $argument))
{
$this->_argument[mb_strtolower($argument['key'])] = (string) $argument['value'];
}
}
}
public function get(
string $key
): ?string
{
$key = mb_strtolower(
$key
);
return isset($this->_argument[$key]) ? $this->_argument[$key]
: null;
}
}

View file

@ -15,12 +15,14 @@ require_once __DIR__ .
DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'vendor' .
DIRECTORY_SEPARATOR . 'autoload.php'; DIRECTORY_SEPARATOR . 'autoload.php';
// Init profile argument // Init environment
if (empty($argv[1])) throw new \Exception; $environment = new \Yggverse\Pulsar\Model\Environment(
$argv
);
// Init config // Init config
$config = new \Yggverse\Pulsar\Model\Config( $config = new \Yggverse\Pulsar\Model\Config(
$argv[1] $environment->get('config')
); );
$config = $config->get(); // registry only $config = $config->get(); // registry only