/** * {@inheritdoc} * * @return \Psr\Http\Message\ResponseInterface|DockerRawStream */ public function attach($id, $parameters = [], $fetch = self::FETCH_OBJECT) { $response = parent::attach($id, $parameters, $fetch); if ($response->getStatusCode() == 200 && DockerRawStream::HEADER == $response->getHeaderLine('Content-Type')) { if ($fetch == self::FETCH_STREAM) { return new DockerRawStream($response->getBody()); } } return $response; }
/** * @inheritDoc * * @return \Psr\Http\Message\ResponseInterface|DockerRawStream|string[][] */ public function logs($id, $parameters = [], $fetch = self::FETCH_OBJECT) { $response = parent::logs($id, $parameters, $fetch); if ($response->getStatusCode() == 200) { if ($fetch == self::FETCH_STREAM) { return new DockerRawStream($response->getBody()); } if ($fetch == self::FETCH_OBJECT) { $dockerRawStream = new DockerRawStream($response->getBody()); $logs = ['stdout' => [], 'stderr' => []]; $dockerRawStream->onStdout(function ($logLine) use(&$logs) { $logs['stdout'][] = $logLine; }); $dockerRawStream->onStderr(function ($logLine) use(&$logs) { $logs['stderr'][] = $logLine; }); $dockerRawStream->wait(); return $logs; } } return $response; }