1
0
Fork 0
mirror of synced 2024-05-20 04:32:37 +12:00
appwrite/src/Appwrite/Docker/Env.php
Eldad A. Fux 042660b15c
Feat psalm analysis (#699)
* Added static code analysis
* Updated code to solve psalm issue
2020-10-27 02:08:29 +02:00

80 lines
1.3 KiB
PHP

<?php
namespace Appwrite\Docker;
use Exception;
class Env
{
/**
* @var array
*/
protected $vars = [];
/**
* @var string $data
*/
public function __construct(string $data)
{
$data = explode("\n", $data);
foreach($data as &$row) {
$row = explode('=', $row);
$key = (isset($row[0])) ? trim($row[0]) : null;
$value = (isset($row[1])) ? trim($row[1]) : null;
if($key) {
$this->vars[$key] = $value;
}
}
}
/**
* @param string $key
* @param mixed $value
*
* @return $this
*/
public function setVar(string $key, $value): self
{
$this->vars[$key] = $value;
return $this;
}
/**
* @param string $key
*
* @return string
*/
public function getVar(string $key): string
{
return (isset($this->vars[$key])) ? $this->vars[$key] : '';
}
/**
* Get All Vars
*
* @return array
*/
public function list(): array
{
return $this->vars;
}
/**
* @return string
*/
public function export(): string
{
$output = '';
foreach ($this->vars as $key => $value) {
$output .= $key.'='.$value."\n";
}
return $output;
}
}