/** * Creates and returns the Perun client. * * @param array $config * @throws CommonException\MissingOptionException * @return Client */ public function createClient(array $config = array()) { if (!isset($config[self::OPT_CLIENT])) { throw new CommonException\MissingOptionException(self::OPT_CLIENT); } $httpClient = $this->createHttpClient($config); $serializer = $this->createSerializer($config); $authenticator = $this->createAuthenticator($config); $client = new Client($config[self::OPT_CLIENT], $httpClient, $serializer); $client->setAuthenticator($authenticator); return $client; }
/** * Performs a remote call to a manager method. * @param string $methodName * @param array $params * @param string $changeState * @throws Exception\ClientRuntimeException * @throws Exception\PerunErrorException * @return EntityInterface|Collection */ public function callMethod($methodName, array $params = array(), $changeState = null) { $params = $this->paramsToArray($params); try { $response = $this->client->sendRequest($this->managerName, $methodName, $params, $changeState); } catch (\Exception $e) { throw new Exception\ClientRuntimeException(sprintf("Exception during client request: [%s] %s", get_class($e), $e->getMessage()), null, $e); } if ($response->isError()) { throw PerunErrorException::createFromResponse($response); } return $this->getEntityFactory()->createFromResponsePayload($response->getPayload()); }
public function testGetHttpClient() { $httpClient = $this->createHttpClientMock(); $client = new Client(null, $httpClient, $this->createSerializerMock()); $this->assertSame($httpClient, $client->getHttpClient()); }