Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 79 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ class Client
* @param ?string $url
* @throws \InvalidArgumentException
*/
public function __construct($loop = null, $url = null)
public function __construct(LoopInterface $loop = null, $url = null)
{
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
throw new \InvalidArgumentException('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
}

if ($url === null) {
$url = 'unix:///var/run/docker.sock';
}
Expand Down Expand Up @@ -224,6 +220,43 @@ public function containerList($all = false, $size = false)
)->then(array($this->parser, 'expectJson'));
}

/**
* List services
*
* @return PromiseInterface Promise<array> list of container objects
* @link https://docs.docker.com/engine/api/v1.40/#operation/ServiceList
*/
public function serviceList()
{
return $this->browser->get(
$this->uri->expand(
'services',
array(
)
)
)->then(array($this->parser, 'expectJson'));
}

/**
* List tasks from a service
*
* @return PromiseInterface Promise<array> list of tasks objects
* @link https://docs.docker.com/engine/api/v1.40/#operation/TaskList
*/
public function taskList($service)
{
return $this->browser->get(
$this->uri->expand(
'tasks{?filter}',
array(
'filter' => 'service=' . $service
)
)
)->then(array($this->parser, 'expectJson'));
}



/**
* Create a container
*
Expand Down Expand Up @@ -264,6 +297,47 @@ public function containerInspect($container)
)->then(array($this->parser, 'expectJson'));
}


/**
* Return low-level information on the service id
*
* @param string $service service ID
* @return PromiseInterface Promise<array> service properties
* @link https://docs.docker.com/engine/api/v1.40/#operation/ServiceInspect
*/
public function serviceInspect($service)
{
return $this->browser->get(
$this->uri->expand(
'services/{service}',
array(
'service' => $service
)
)
)->then(array($this->parser, 'expectJson'));
}


/**
* Return low-level information on the task id
*
* @param string $task task ID
* @return PromiseInterface Promise<array> task properties
* @link https://docs.docker.com/engine/api/v1.40/#operation/TaskInspect
*/
public function taskInspect($task)
{
return $this->browser->get(
$this->uri->expand(
'tasks/{task}',
array(
'task' => $task
)
)
)->then(array($this->parser, 'expectJson'));
}


/**
* List processes running inside the container id
*
Expand Down
Loading