Added plugins and build tools
This commit is contained in:
37
plugins/com.noccy.docker/DockerCompose/Service.php
Normal file
37
plugins/com.noccy.docker/DockerCompose/Service.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace SparkPlug\Com\Noccy\Docker\DockerCompose;
|
||||
|
||||
|
||||
class Service
|
||||
{
|
||||
private array $service;
|
||||
|
||||
private array $environment = [];
|
||||
|
||||
private Stack|null $stack;
|
||||
|
||||
public function __construct(array $service, ?Stack $stack)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->stack = $stack;
|
||||
|
||||
foreach ($this->service['environment']??[] as $k=>$v) {
|
||||
if (is_numeric($k)) {
|
||||
[$k, $v] = explode("=", $v, 2);
|
||||
}
|
||||
$this->environment[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
public function getImage():?String
|
||||
{
|
||||
return $this->service['image']??null;
|
||||
}
|
||||
|
||||
public function getEnvironment(): array
|
||||
{
|
||||
return $this->environment;
|
||||
}
|
||||
|
||||
}
|
42
plugins/com.noccy.docker/DockerCompose/Stack.php
Normal file
42
plugins/com.noccy.docker/DockerCompose/Stack.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace SparkPlug\Com\Noccy\Docker\DockerCompose;
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Stack
|
||||
{
|
||||
|
||||
private array $compose;
|
||||
|
||||
private string $version;
|
||||
|
||||
private array $services;
|
||||
|
||||
public function __construct(string $filename)
|
||||
{
|
||||
$this->compose = Yaml::parseFile($filename);
|
||||
|
||||
$this->version = $this->compose['version']??null;
|
||||
$this->enumServices();
|
||||
}
|
||||
|
||||
private function enumServices()
|
||||
{
|
||||
foreach ($this->compose['services'] as $service=>$config) {
|
||||
$this->services[$service] = new Service($config, $this);
|
||||
}
|
||||
}
|
||||
|
||||
public function getServiceNames(): array
|
||||
{
|
||||
return array_keys($this->services);
|
||||
}
|
||||
|
||||
public function getService(string $name): ?Service
|
||||
{
|
||||
return $this->services[$name] ?? null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user