43 lines
821 B
PHP
43 lines
821 B
PHP
<?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;
|
|
}
|
|
|
|
}
|
|
|