From 306012efb1f1bd94f26dbc323f99b4a8bcd8a474 Mon Sep 17 00:00:00 2001 From: davidnurdin <50957749+davidnurdin@users.noreply.github.com> Date: Thu, 17 Jul 2025 11:59:32 +0200 Subject: [PATCH] Update Client.php - Add Service/Task {list/inspect} (swarm mode) --- src/Client.php | 84 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index 3fc69d4..ddb11c3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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'; } @@ -224,6 +220,43 @@ public function containerList($all = false, $size = false) )->then(array($this->parser, 'expectJson')); } + /** + * List services + * + * @return PromiseInterface Promise 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 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 * @@ -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 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 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 *