/** * @return HttpClient */ protected function getHttpClient() { if ($this->httpClient === null) { $this->httpClient = HttpClientDiscovery::find(); } $authentication = new QueryParam(['key' => $this->apiKey]); $authenticationPlugin = new AuthenticationPlugin($authentication); $client = new PluginClient($this->httpClient, [$authenticationPlugin]); return $client; }
/** * Uses php-http discovery to discover an HTTP client if one isn't set. * * @return Http\Client\HttpClient */ public function http() { if (isset($this->http)) { return $this->http; } return HttpClientDiscovery::find(); }
/** * @param string $baseUrl * @param string[] $filePaths */ public function __construct($baseUrl, array $filePaths) { $this->baseUrl = $baseUrl; $this->client = HttpClientDiscovery::find(); $this->messageFactory = MessageFactoryDiscovery::find(); $this->fileLocator = new FileLocator($filePaths); }
/** * Constructor. * * @param string $key * @param string $secret * @param \Http\Client\HttpClient|null $http * @param \Http\Message\MessageFactory|null $factory */ public function __construct($key, $secret, HttpClient $http = null, MessageFactory $factory = null) { $this->key = $key; $this->secret = $secret; $this->http = $http ?: HttpClientDiscovery::find(); $this->factory = $factory ?: MessageFactoryDiscovery::find(); }
/** * Create new client instance * * If no specific transport, parser or serializer is passed, default implementations * are used. * * @param string $uri * @param TransportInterface $transport * @param Parser\ParserInterface $parser * @param Serializer\SerializerInterface $serializer */ public function __construct($uri = null, TransportInterface $transport = null, ParserInterface $parser = null, SerializerInterface $serializer = null) { $this->uri = $uri; $this->transport = $transport ?: new HttpAdapterTransport(MessageFactoryDiscovery::find(), HttpClientDiscovery::find()); $this->parser = $parser ?: new XmlReaderParser(); $this->serializer = $serializer ?: new XmlWriterSerializer(); }
/** * Get HTTP adapter for your application. * * @return PhpHttpClient */ private function getHttpClient() { if ($this->httpClient === null) { $this->httpClient = HttpClientDiscovery::find(); } return $this->httpClient; }
/** * @return HttpMethodsClient * * @throws EventClientFactoryCreateException */ protected static function createHttpClient() { try { $httpClient = new HttpMethodsClient(HttpClientDiscovery::find(), MessageFactoryDiscovery::find()); } catch (NotFoundException $exception) { throw new EventClientFactoryCreateException($exception->getMessage(), $exception->getCode(), $exception); } return $httpClient; }
/** * @return HttpClient * @throws ZenviaRequestException */ public function getHttpClient() { if ($this->httpClient === null) { $this->httpClient = HttpClientDiscovery::find(); if ($this->httpClient === null) { throw new ZenviaRequestException('The RequestManager expects a valid Http Client or Adapter, none given. Please install a valid Http Client or Adapter'); } } return $this->httpClient; }
/** * @param string $url * @param string $token * * @return HttpClient */ public static function create($url, $token) { $plugins = [new Plugin\RedirectPlugin(), new Plugin\RetryPlugin(['retries' => 5]), new Plugin\DecoderPlugin(), new Plugin\ErrorPlugin()]; if ($token) { $plugins[] = new Plugin\AuthenticationPlugin(new QueryParam(['api_key' => $token])); } $client = new PluginClient(Discovery\HttpClientDiscovery::find(), $plugins); $streamFactory = Discovery\StreamFactoryDiscovery::find(); $builder = new MultipartStreamBuilder($streamFactory); return new HttpPlugHttpAdapterClient($client, $url, Discovery\MessageFactoryDiscovery::find(), $builder); }
/** * Build the HTTP client to talk with the API. * * @param string $apiKey Lotadata API Key * @param HttpClient $client Base HTTP client * * @return HttpClient */ public static function create($apiKey, HttpClient $client = null) { if (!$client) { $client = HttpClientDiscovery::find(); } $authentication = new QueryParamAuthentication(['api_key' => $apiKey]); $authenticationPlugin = new AuthenticationPlugin($authentication); $errorPlugin = new ErrorPlugin(); $loggerPlugin = new LoggerPlugin(new Logger('lotadata-client')); return new PluginClient($client, [$errorPlugin, $authenticationPlugin]); }
/** * AbstractHttpProvider Constructor. * * @param HttpClient $client HttpClient makes HTTP requests. * @param MessageFactory $messageFactory MessageFactory creates Request objects. */ public function __construct(HttpClient $client = null, MessageFactory $messageFactory = null) { if (null === $client && !class_exists('Http\\Discovery\\HttpClientDiscovery')) { throw ServiceMissingException::noHttpClient(); } $this->client = $client ?: \Http\Discovery\HttpClientDiscovery::find(); if (null === $messageFactory && !class_exists('Http\\Discovery\\MessageFactoryDiscovery')) { throw ServiceMissingException::noMessageFactory(); } $this->messageFactory = $messageFactory ?: \Http\Discovery\MessageFactoryDiscovery::find(); }
/** * Return the client. If no client exist, create a new one filled with plugins. * * @return HttpClient */ protected function getClient() { if ($this->client === null) { $plugins = array(); if ($this->logger) { $plugins[] = new LoggerPlugin($this->logger); } $plugins[] = new ErrorPlugin(); $this->client = new PluginClient(HttpClientDiscovery::find(), $plugins); } return $this->client; }
/** * Register the http related stuff. * * @param Application $app */ private function registerHttp(Application $app) { $app->singleton('swap.http_client', function ($app) { if ($httpClient = $app->config->get('swap.http_client')) { return $app[$httpClient]; } return HttpClientDiscovery::find(); }); $app->singleton('swap.request_factory', function ($app) { if ($requestFactory = $app->config->get('swap.request_factory')) { return $app[$requestFactory]; } return MessageFactoryDiscovery::find(); }); }
/** * @param HttpClient|null $httpClient * @param RequestFactory|null $requestFactory */ public function __construct(HttpClient $httpClient = null, RequestFactory $requestFactory = null) { $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); $this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find(); $this->registry = new Registry(); }
/** * Sets the client to be used for querying the API endpoints * * @param Client $client * @see http://php-http.readthedocs.org/en/latest/utils/#httpmethodsclient * @return $this */ public function setHttpClient(Client $client = null) { if ($client === null) { $client = new Client(HttpClientDiscovery::find(), MessageFactoryDiscovery::find()); } $this->client = $client; return $this; }
/** * @param string $baseUrl */ public function __construct($baseUrl) { $this->client = HttpClientDiscovery::find(); $this->messageFactory = MessageFactoryDiscovery::find(); $this->baseUrl = $baseUrl; }
public function build($schemaPath) { // Build serializer if ($this->serializer === null) { if (empty($this->encoders)) { $this->encoders = [new JsonEncoder(), new XmlEncoder()]; } if (empty($this->denormalizers)) { $this->denormalizers[] = new ResourceDenormalizer($this->paginationProvider); } $this->serializer = new Serializer($this->denormalizers, $this->encoders); } if ($this->uriFactory === null) { $this->uriFactory = UriFactoryDiscovery::find(); } if ($this->messageFactory === null) { $this->messageFactory = MessageFactoryDiscovery::find(); } if ($this->httpClient === null) { $this->httpClient = HttpClientDiscovery::find(); } $schemaFactory = new SwaggerSchemaFactory(); if ($this->cache !== null) { $schemaFactory = new CachedSchemaFactoryDecorator($this->cache, $schemaFactory); } $this->schema = $schemaFactory->createSchema($schemaPath); if (!isset($this->requestValidator)) { $this->requestValidator = new MessageValidator(new Validator(), new SymfonyDecoderAdapter(new ChainDecoder($this->encoders))); } return new ApiService($this->uriFactory, new UriTemplate(), $this->httpClient, $this->messageFactory, $this->schema, $this->requestValidator, $this->serializer, $this->config); }
/** * @param string $host */ public function __construct($host, HttpClient $httpClient = null) { $this->host = $host; $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); $this->messageFactory = MessageFactoryDiscovery::find(); }
/** * Make sure to use our custom strategy. * * @param Event $e */ public function onEvent(Event $e) { HttpClientDiscovery::prependStrategy(self::class); }
/** * {@inheritDoc} */ public function build() { if (null === $this->httpClient && class_exists('\\Http\\Discovery\\HttpClientDiscovery')) { try { $this->httpClient = HttpClientDiscovery::find(); } catch (\Exception $e) { } } if (null === ($httpClient = $this->httpClient)) { throw new \LogicException('No HTTP client was configured.'); } if (null === $this->requestFactory && class_exists('\\Http\\Discovery\\MessageFactoryDiscovery')) { try { $this->requestFactory = MessageFactoryDiscovery::find(); } catch (\Exception $e) { } } if (null === $this->requestFactory) { throw new \LogicException('No request factory was configured.'); } if (null === $this->baseUrl) { throw new \LogicException('Base URI value was not configured.'); } $serializerRegistry = new SerializerRegistry(); $serializerRegistry->setStatementSerializer($this->serializerFactory->createStatementSerializer()); $serializerRegistry->setStatementResultSerializer($this->serializerFactory->createStatementResultSerializer()); $serializerRegistry->setActorSerializer($this->serializerFactory->createActorSerializer()); $serializerRegistry->setDocumentDataSerializer($this->serializerFactory->createDocumentDataSerializer()); $plugins = array(); if (null !== $this->username && null !== $this->password) { $plugins[] = new AuthenticationPlugin(new BasicAuth($this->username, $this->password)); } if (null !== $this->consumerKey && null !== $this->consumerSecret && null !== $this->accessToken && null !== $this->tokenSecret) { if (!class_exists('Xabbuh\\Http\\Authentication\\OAuth1')) { throw new \LogicException('The "xabbuh/oauth1-authentication package is needed to use OAuth1 authorization.'); } $requestSigner = new RequestSigner(new ConsumerKey($this->consumerKey), new ConsumerSecret($this->consumerSecret)); $oauth = new OAuth1($requestSigner, new AccessToken($this->accessToken), new TokenSecret($this->tokenSecret)); $plugins[] = new AuthenticationPlugin($oauth); } if (!empty($plugins)) { $httpClient = new PluginClient($httpClient, $plugins); } $version = null === $this->version ? '1.0.1' : $this->version; $requestHandler = new Handler($httpClient, $this->requestFactory, $this->baseUrl, $version); return new XApiClient($requestHandler, $serializerRegistry, $this->version); }
/** * Make a client. * * @return $this */ public static function make() { $http = new HttpClient(HttpClientDiscovery::find(), MessageFactoryDiscovery::find()); return new static($http); }
/** * Create a client. */ public static function create(Configuration $configuration) { return new Client($configuration, new HttpMethodsClient(HttpClientDiscovery::find(), MessageFactoryDiscovery::find()), static::getVenueFactory()); }
/** * @param HttpClient|null $httpClient * @param MessageFactory|null $messageFactory */ public function __construct(HttpClient $httpClient = null, MessageFactory $messageFactory = null) { $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); $this->messageFactory = $messageFactory ?: MessageFactoryDiscovery::find(); }
/** * This example should be executed in console * * Requires dev dependencies! */ namespace Comindware\Tracker\API\Examples; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; use Mekras\OData\Client\Document\EntryDocument; use Mekras\OData\Client\OData; use Mekras\OData\Client\Service; use Mekras\OData\Client\URI\Uri; require __DIR__ . '/../../vendor/autoload.php'; $service = new Service('http://services.odata.org/OData/OData.svc/', HttpClientDiscovery::find(), MessageFactoryDiscovery::find()); $uri = new Uri(); $uri->collection('Products')->item(1); $document = $service->sendRequest(OData::GET, $uri); if (!$document instanceof EntryDocument) { die("Not an entry!\n"); } $entry = $document->getEntry(); printf("Entity type: %s\nProperties:\n", $entry->getEntityType()); foreach ($entry->getProperties() as $property) { $value = $property->getValue(); if ($value instanceof \DateTimeInterface) { $value = $value->format(DATE_RFC2822); } printf("- %s: %s\n", $property->getName(), $value); }
* This example should be executed in console * * Requires dev dependencies! */ namespace Comindware\Tracker\API\Examples; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; use Mekras\OData\Client\Document\EntryDocument; use Mekras\OData\Client\EDM\Primitive; use Mekras\OData\Client\OData; use Mekras\OData\Client\URI\Uri; use Mekras\OData\Client\Service; require __DIR__ . '/../../vendor/autoload.php'; // For write access to services.odata.org we need not get special URI first $httpClient = HttpClientDiscovery::find(); $requestFactory = MessageFactoryDiscovery::find(); $response = $httpClient->sendRequest($requestFactory->createRequest('GET', 'http://services.odata.org/V3/(S(readwrite))/OData/OData.svc/')); $rootUri = 'http://services.odata.org' . $response->getHeaderLine('Location'); // Now use obtained URI to create service. $service = new Service($rootUri, $httpClient, $requestFactory); // Create container document. "ODataDemo.Product" — entity type we want to create. $document = $service->getDocumentFactory()->createEntityDocument('ODataDemo.Product'); $entry = $document->getEntry(); $entry->addTitle('Foo'); $entry->getProperties()->add('ID', mt_rand(50, 10000), Primitive::INT32); $entry->getProperties()->add('ReleaseDate', new \DateTime(), Primitive::DATETIME); $entry->getProperties()->add('Rating', 4, Primitive::INT16); $entry->getProperties()->add('Price', 14.5, Primitive::DOUBLE); $uri = new Uri(); $uri->collection('Products');
<?php /** @var \Pimple\Container $container */ use Http\Client\Common\HttpMethodsClient; use Http\Client\Plugin\AuthenticationPlugin; use Http\Client\Plugin\PluginClient; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; use Http\Message\Authentication\BasicAuth; use Pimple\Container; use TonicForHealth\ReportAggregator\Sync\TestRailSync; $config = $container['config']; $container['testrail.api_url'] = $config['testrail']['api_url']; $container['testrail.user'] = $config['testrail']['user']; $container['testrail.password'] = $config['testrail']['password']; $container['testrail.base_auth'] = function (Container $c) { return new BasicAuth($c['testrail.user'], $c['testrail.password']); }; $container['testrail.auth'] = function (Container $c) { return new AuthenticationPlugin($c['testrail.base_auth']); }; $container['testrail.plugin_client'] = function (Container $c) { return new PluginClient(HttpClientDiscovery::find(), [$c['testrail.auth']]); }; $container['testrail.client'] = function (Container $c) { return new HttpMethodsClient($c['testrail.plugin_client'], MessageFactoryDiscovery::find()); }; $container['testrail.sync'] = function (Container $c) { return new TestRailSync($c['testrail.api_url'], $c['testrail.client']); };
public static function create($token, HttpClient $httpClient = null, MessageFactory $messageFactory = null, Serializer $serializer = null) { $httpClient = new PluginClient($httpClient ?: HttpClientDiscovery::find(), [new AuthenticationPlugin(new Bearer($token))]); return new self($httpClient, $messageFactory, $serializer); }
public static function create() : self { return new self(HttpClientDiscovery::find(), MessageFactoryDiscovery::find(), UriFactoryDiscovery::find()); }
/** * {@inheritDoc} */ public function createConfig(array $config = []) { $config = ArrayObject::ensureArrayObject($config); $config->defaults($this->defaultConfig); $config->defaults(['httplug.message_factory' => function (ArrayObject $config) { if (class_exists(MessageFactoryDiscovery::class)) { return MessageFactoryDiscovery::find(); } if (class_exists(\GuzzleHttp\Psr7\Request::class)) { return new GuzzleMessageFactory(); } if (class_exists(\Zend\Diactoros\Request::class)) { return new DiactorosMessageFactory(); } throw new \LogicException('The httplug.message_factory could not be guessed. Install one of the following packages: php-http/guzzle6-adapter, zendframework/zend-diactoros. You can also overwrite the config option with your implementation.'); }, 'httplug.stream_factory' => function (ArrayObject $config) { if (class_exists(StreamFactoryDiscovery::class)) { return StreamFactoryDiscovery::find(); } if (class_exists(\GuzzleHttp\Psr7\Request::class)) { return new GuzzleStreamFactory(); } if (class_exists(\Zend\Diactoros\Request::class)) { return new DiactorosStreamFactory(); } throw new \LogicException('The httplug.stream_factory could not be guessed. Install one of the following packages: php-http/guzzle6-adapter, zendframework/zend-diactoros. You can also overwrite the config option with your implementation.'); }, 'httplug.client' => function (ArrayObject $config) { if (class_exists(HttpClientDiscovery::class)) { return HttpClientDiscovery::find(); } if (class_exists(HttpGuzzle6Client::class)) { return new HttpGuzzle6Client(); } if (class_exists(HttpGuzzle5Client::class)) { return new HttpGuzzle5Client(); } if (class_exists(HttpSocketClient::class)) { return new HttpSocketClient(); } if (class_exists(HttpCurlClient::class)) { return new HttpCurlClient($config['httplug.message_factory'], $config['httplug.stream_factory']); } if (class_exists(HttpBuzzClient::class)) { return new HttpBuzzClient(); } throw new \LogicException('The httplug.client could not be guessed. Install one of the following packages: php-http/guzzle6-adapter. You can also overwrite the config option with your implementation.'); }, 'payum.http_client' => function (ArrayObject $config) { return new HttplugClient($config['httplug.client']); }, 'payum.template.layout' => '@PayumCore/layout.html.twig', 'twig.env' => function () { return new \Twig_Environment(new \Twig_Loader_Chain()); }, 'twig.register_paths' => function (ArrayObject $config) { $twig = $config['twig.env']; if (false == $twig instanceof \Twig_Environment) { throw new \LogicException(sprintf('The `twig.env config option must contains instance of Twig_Environment but got %s`', is_object($twig) ? get_class($twig) : gettype($twig))); } TwigUtil::registerPaths($twig, $config['payum.paths']); return null; }, 'payum.action.get_http_request' => new GetHttpRequestAction(), 'payum.action.capture_payment' => new CapturePaymentAction(), 'payum.action.authorize_payment' => new AuthorizePaymentAction(), 'payum.action.payout_payout' => new PayoutPayoutAction(), 'payum.action.execute_same_request_with_model_details' => new ExecuteSameRequestWithModelDetailsAction(), 'payum.action.render_template' => function (ArrayObject $config) { return new RenderTemplateAction($config['twig.env'], $config['payum.template.layout']); }, 'payum.extension.endless_cycle_detector' => new EndlessCycleDetectorExtension(), 'payum.action.get_currency' => function (ArrayObject $config) { return new GetCurrencyAction($config['payum.iso4217']); }, 'payum.prepend_actions' => [], 'payum.prepend_extensions' => [], 'payum.prepend_apis' => [], 'payum.default_options' => [], 'payum.required_options' => [], 'payum.api.http_client' => function (ArrayObject $config) { return $config['payum.http_client']; }, 'payum.security.token_storage' => null]); if ($config['payum.security.token_storage']) { $config['payum.action.get_token'] = function (ArrayObject $config) { return new GetTokenAction($config['payum.security.token_storage']); }; } $config['payum.paths'] = array_replace(['PayumCore' => __DIR__ . '/Resources/views'], $config['payum.paths'] ?: []); return (array) $config; }
/** * @param BackupEvent $event */ public function whenBackupIsCompleted(BackupEvent $event) { $request = MessageFactoryDiscovery::find()->createRequest('GET', $this->url); HttpClientDiscovery::find()->sendRequest($request); }