/** * Initialize the React client. * * @param ResponseFactory|null $responseFactory * @param LoopInterface|null $loop * @param ReactClient|null $client * @param StreamFactory|null $streamFactory */ public function __construct(ResponseFactory $responseFactory = null, LoopInterface $loop = null, ReactClient $client = null, StreamFactory $streamFactory = null) { if (null !== $client && null === $loop) { throw new \RuntimeException('You must give a LoopInterface instance with the Client'); } $this->loop = $loop ?: ReactFactory::buildEventLoop(); $this->client = $client ?: ReactFactory::buildHttpClient($this->loop); $this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find(); $this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); }
/** * @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); }
/** * Register php-http interfaces to container. */ protected function registerHttplugFactories() { $this->app->bind('httplug.message_factory.default', function ($app) { return MessageFactoryDiscovery::find(); }); $this->app->alias('httplug.message_factory.default', MessageFactory::class); $this->app->alias('httplug.message_factory.default', ResponseFactory::class); $this->app->bind('httplug.uri_factory.default', function ($app) { return UriFactoryDiscovery::find(); }); $this->app->alias('httplug.uri_factory.default', UriFactory::class); $this->app->bind('httplug.stream_factory.default', function ($app) { return StreamFactoryDiscovery::find(); }); $this->app->alias('httplug.stream_factory.default', StreamFactory::class); }
/** * AbstractHttpClient constructor. */ public function __construct() { $this->messageFactory = MessageFactoryDiscovery::find(); $this->streamFactory = StreamFactoryDiscovery::find(); }
/** * @param StreamFactory|null $streamFactory */ public function __construct(StreamFactory $streamFactory = null) { $this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); }
/** * Create new client * * @param MessageFactory|null $messageFactory HTTP Message factory * @param StreamFactory|null $streamFactory HTTP Stream factory * @param array $options cURL options (see http://php.net/curl_setopt) * * @throws \Http\Discovery\Exception\NotFoundException If factory discovery failed. * * @since 1.0 */ public function __construct(MessageFactory $messageFactory = null, StreamFactory $streamFactory = null, array $options = []) { $this->messageFactory = $messageFactory ?: MessageFactoryDiscovery::find(); $this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); $this->options = $options; }
/** * {@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; }