/** * Get the default chain to use with clients * * @param ClientInterface $client Client to base the chain on * * @return self */ public static function getDefaultChain(ClientInterface $client) { $factories = array(); if ($description = $client->getDescription()) { $factories[] = new ServiceDescriptionFactory($description); } $factories[] = new ConcreteClassFactory($client); return new self($factories); }
/** * Get the default chain to use with clients * * @return CompositeFactory */ public static function getDefaultChain(ClientInterface $client) { $chain = new self(); $description = $client->getDescription(); if ($description instanceof ServiceDescription) { $chain->add(new ServiceDescriptionFactory($description)); } $chain->add(new ConcreteClassFactory($client)); return $chain; }
public function factory($name, array $args = array()) { // Determine the class to instantiate based on the namespace of the current client and the default directory $prefix = $this->client->getConfig('command.prefix'); if (!$prefix) { // The prefix can be specified in a factory method and is cached $prefix = implode('\\', array_slice(explode('\\', get_class($this->client)), 0, -1)) . '\\Command\\'; $this->client->getConfig()->set('command.prefix', $prefix); } $class = $prefix . str_replace(' ', '\\', ucwords(str_replace('.', ' ', $this->inflector->camel($name)))); // Create the concrete command if it exists if (class_exists($class)) { return new $class($args); } }
/** * @param HttpRequest $request * @return HttpResponse */ public function handleRequest(HttpRequest $request) { //TODO: Guzzle request $guzzleRequest = $this->client->createRequest($request->getMethod(), $request->getUrl(), $request->getHeaders()); $guzzleRequest->getCurlOptions()->remove(CURLOPT_SSL_VERIFYPEER); $guzzleRequest->getCurlOptions()->remove(CURLOPT_CAINFO); $guzzleRequest->getCurlOptions()->add(CURLOPT_SSL_VERIFYPEER, 0); $guzzleRequest->getCurlOptions()->add(CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); $guzzleRequest->getCurlOptions()->add(CURLOPT_RETURNTRANSFER, true); $guzzleRequest->getCurlOptions()->add(CURLOPT_VERBOSE, 0); $guzzleRequest->getCurlOptions()->add(CURLOPT_HEADER, false); $guzzleRequest->getCurlOptions()->add(CURLOPT_TIMEOUT, 10); //$guzzleRequest = $this->enableCurlOptionProxy($guzzleRequest); //TODO: Guzzle response $guzzleResponse = $this->client->send($guzzleRequest); $response = new HttpResponse($guzzleResponse->getInfo('http_code'), '', array(HttpAdapterInterface::HTTP_HEADER_CONTENT_TYPE => $guzzleResponse->getInfo('content_type')), $guzzleResponse->getBody(true)); return $response; }
/** * It connects to the url and give response. * * @param PrestashopRestClientParameters $clientParameters * * @return \Guzzle\Http\Message\Response * * @throws \Exception */ protected function connect($clientParameters) { $parametersHash = $clientParameters->getHash(); if (!isset($this->resultCache[$parametersHash])) { $guzzleParams = ['connect_timeout' => self::CONNECT_TIMEOUT, 'timeout' => self::TIMEOUT, 'auth' => [$clientParameters->getHttpLogin(), $clientParameters->getHttpPassword()]]; $request = $this->client->get($clientParameters->getPrestashopUrl(), [], $guzzleParams); $request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT, self::CONNECT_TIMEOUT); $request->getCurlOptions()->set(CURLOPT_TIMEOUT, self::TIMEOUT); try { $response = $this->client->send($request); $this->resultCache[$parametersHash] = $response; } catch (\Exception $e) { $this->resultCache[$parametersHash] = $e; throw $e; } } else { $response = $this->resultCache[$parametersHash]; if ($response instanceof \Exception) { throw $response; } } return $response; }
/** * @param $username * @param $password * * @return User * @throws \Ice\JanusClientBundle\Exception\AuthenticationException when credentials are bad * @throws \Exception|\Guzzle\Http\Exception\BadResponseException when an unknown error (eg 500) occurs */ public function authenticate($username, $password) { try { $command = $this->client->getCommand('Authenticate'); $command->prepare(); $command->getRequest()->setAuth($username, $password, CURLAUTH_BASIC); return $command->execute(); } catch (BadResponseException $e) { switch ($e->getResponse()->getStatusCode()) { case 401: case 403: throw new AuthenticationException(); break; } throw $e; } }
/** * {@inheritDoc} */ public function getContent($url) { $response = $this->client->get($url)->send(); return (string) $response->getBody(); }
/** * {@inheritdoc} */ public final function addSubscriber(EventSubscriberInterface $subscriber) { $this->client->addSubscriber($subscriber); }
/** * @covers PusherService::getPresenceUsers */ public function testFormatParametersWhenGetPresenceUsers() { $expectedParameters = array('channel' => 'presence-foobar'); $this->client->expects($this->once())->method('getPresenceUsers')->with($expectedParameters)->will($this->returnValue(new Collection())); $this->service->getPresenceUsers('presence-foobar'); }