Several cool features

- replace vars from collection by default
- replace vars from environment file with -e
- bearer auth header
This commit is contained in:
2023-08-13 10:26:22 +08:00
parent c630af8795
commit c4961b1238
6 changed files with 257 additions and 36 deletions

65
src/Environment.php Normal file
View File

@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace PmConverter;
class Environment implements \ArrayAccess
{
/**
* @var array
*/
protected array $vars = [];
/**
* @param object $env
*/
public function __construct(protected object $env)
{
foreach ($env->values as $var) {
$this->vars["{{{$var->key}}}"] = $var->value;
}
}
/**
* Tells if there are some vars or not
*
* @return bool
*/
public function hasVars(): bool
{
return !empty($this->vars);
}
/**
* @inheritDoc
*/
public function offsetExists(mixed $offset): bool
{
return array_key_exists($offset, $this->vars);
}
/**
* @inheritDoc
*/
public function offsetGet(mixed $offset): mixed
{
return $this->vars[$offset];
}
/**
* @inheritDoc
*/
public function offsetSet(mixed $offset, mixed $value): void
{
$this->vars[$offset] = $value;
}
/**
* @inheritDoc
*/
public function offsetUnset(mixed $offset): void
{
unset($this->vars[$offset]);
}
}