mirror of
https://github.com/YGGverse/Pulsar.git
synced 2026-03-31 17:55:37 +00:00
implement environment model
This commit is contained in:
parent
ecc7c66143
commit
048ae2c3ac
2 changed files with 39 additions and 3 deletions
34
src/Model/Environment.php
Normal file
34
src/Model/Environment.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,12 +15,14 @@ require_once __DIR__ .
|
|||
DIRECTORY_SEPARATOR . 'vendor' .
|
||||
DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
|
||||
// Init profile argument
|
||||
if (empty($argv[1])) throw new \Exception;
|
||||
// Init environment
|
||||
$environment = new \Yggverse\Pulsar\Model\Environment(
|
||||
$argv
|
||||
);
|
||||
|
||||
// Init config
|
||||
$config = new \Yggverse\Pulsar\Model\Config(
|
||||
$argv[1]
|
||||
$environment->get('config')
|
||||
);
|
||||
|
||||
$config = $config->get(); // registry only
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue