1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00
appwrite/src/Appwrite/Docker/Compose/Service.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

76 lines
1.7 KiB
PHP

<?php
namespace Appwrite\Docker\Compose;
use Appwrite\Docker\Env;
class Service
{
/**
* @var array
*/
protected $service = [];
/**
* @var string $path
*/
public function __construct(array $service)
{
$this->service = $service;
$ports = (isset($this->service['ports']) && is_array($this->service['ports'])) ? $this->service['ports'] : [];
$this->service['ports'] = [];
array_walk($ports, function(&$value, &$key) {
$split = explode(':', $value);
$this->service['ports'][
(isset($split[0])) ? $split[0] : ''
] = (isset($split[1])) ? $split[1] : '';
});
$this->service['environment'] = (isset($this->service['environment']) && is_array($this->service['environment'])) ? $this->service['environment'] : [];
$this->service['environment'] = new Env(implode("\n", $this->service['environment']));
}
/**
* @return string
*/
public function getContainerName(): string
{
return (isset($this->service['container_name'])) ? $this->service['container_name'] : '';
}
/**
* @return string
*/
public function getImage(): string
{
return (isset($this->service['image'])) ? $this->service['image'] : '';
}
/**
* @return string
*/
public function getImageVersion(): string
{
$image = $this->getImage();
return substr($image, ((int)strpos($image, ':'))+1);
}
/**
* @return Env
*/
public function getEnvironment(): Env
{
return $this->service['environment'];
}
/**
* @return array
*/
public function getPorts(): array
{
return $this->service['ports'];
}
}