appwrite/src/Appwrite/Docker/Compose.php

66 lines
1.4 KiB
PHP
Raw Normal View History

2020-07-29 15:26:01 +00:00
<?php
namespace Appwrite\Docker;
use Appwrite\Docker\Compose\Service;
use Exception;
class Compose
{
/**
* @var array
*/
protected $compose = [];
/**
* @var string $data
*/
public function __construct(string $data)
{
$this->compose = yaml_parse($data);
$this->compose['services'] = (isset($this->compose['services']) && is_array($this->compose['services']))
? $this->compose['services'] : [];
2022-05-23 14:54:50 +00:00
2020-07-29 15:26:01 +00:00
foreach ($this->compose['services'] as $key => &$service) {
$service = new Service($service);
}
}
/**
* @return Service[]
*/
public function getServices(): array
{
return $this->compose['services'];
}
/**
* @return Service
*/
public function getService(string $name): Service
{
2020-10-27 19:44:15 +00:00
if (!isset($this->compose['services'][$name])) {
2020-07-29 15:26:01 +00:00
throw new Exception('Service not found');
}
return $this->compose['services'][$name];
}
/**
* @return array
*/
public function getNetworks(): array
{
return (isset($this->compose['networks'])) ? array_keys($this->compose['networks']) : [];
}
/**
* @return array
*/
public function getVolumes(): array
{
return (isset($this->compose['volumes'])) ? array_keys($this->compose['volumes']) : [];
}
}