本文整理汇总了PHP中GuzzleHttp\Middleware::prepareBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Middleware::prepareBody方法的具体用法?PHP Middleware::prepareBody怎么用?PHP Middleware::prepareBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Middleware
的用法示例。
在下文中一共展示了Middleware::prepareBody方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildClient
/**
* Build the guzzle client instance.
*
* @param array $config Additional configuration
*
* @return GuzzleClient
*/
private static function buildClient(array $config = [])
{
$handlerStack = new HandlerStack(\GuzzleHttp\choose_handler());
$handlerStack->push(Middleware::prepareBody(), 'prepare_body');
$config = array_merge(['handler' => $handlerStack], $config);
return new GuzzleClient($config);
}
示例2: __construct
/**
* @param ClientInterface|null $client
*/
public function __construct(ClientInterface $client = null)
{
if (!$client) {
$handlerStack = new HandlerStack(\GuzzleHttp\choose_handler());
$handlerStack->push(Middleware::prepareBody(), 'prepare_body');
$client = new Client(['handler' => $handlerStack]);
}
$this->client = $client;
}
示例3: create
/**
* Creates a default handler stack that can be used by clients.
*
* The returned handler will wrap the provided handler or use the most
* appropriate default handler for you system. The returned HandlerStack has
* support for cookies, redirects, HTTP error exceptions, and preparing a body
* before sending.
*
* The returned handler stack can be passed to a client in the "handler"
* option.
*
* @param callable $handler HTTP handler function to use with the stack. If no
* handler is provided, the best handler for your
* system will be utilized.
*
* @return HandlerStack
*/
public static function create(callable $handler = null)
{
$stack = new self($handler ?: choose_handler());
$stack->push(Middleware::httpErrors(), 'http_errors');
$stack->push(Middleware::redirect(), 'allow_redirects');
$stack->push(Middleware::cookies(), 'cookies');
$stack->push(Middleware::prepareBody(), 'prepare_body');
return $stack;
}
示例4: __construct
/**
* @param string $apiKey
* @param string $secret
* @param string $url
* @param ClientInterface|null $client
* @param BucketManager $bucketManager
* @param FileManager $fileManager
* @param array $connectionConfig
*/
public function __construct($apiKey, $secret, $url = 'https://myracloud-upload.local/v2/', ClientInterface $client = null, BucketManager $bucketManager = null, FileManager $fileManager = null, array $connectionConfig = [])
{
$this->apiKey = $apiKey;
$this->secret = $secret;
$this->url = $url;
if ($client === null) {
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push(Middleware::prepareBody());
$stack->push(Middleware::mapRequest(function (RequestInterface $request) use($secret, $apiKey) {
return $request->withHeader('Authorization', "MYRA {$apiKey}:" . new Authentication\Signature($request->getMethod(), $request->getRequestTarget(), $secret, $request->getHeaders(), $request->getBody()));
}));
$client = new Client(array_merge(['base_uri' => $this->url, 'handler' => $stack], $connectionConfig));
}
$this->client = $client;
$this->bucketManager = $bucketManager ?: new BucketManager($this->client);
$this->fileManager = $fileManager ?: new FileManager($this->client);
}
示例5: register
public function register(Application $app)
{
/** @var \Qandidate\Toggle\ToggleManager $toggles */
$toggles = $app['toggles'];
$importFromSapi = $toggles->active('import-from-sapi', $app['toggles.context']);
$app['udb2_log_handler'] = $app->share(function (Application $app) {
return new \Monolog\Handler\StreamHandler(__DIR__ . '/../log/udb2.log');
});
$app['udb2_deserializer_locator'] = $app->share(function (Application $app) {
$deserializerLocator = new SimpleDeserializerLocator();
$deserializerLocator->registerDeserializer(new StringLiteral('application/vnd.cultuurnet.udb2-events.actor-created+json'), new ActorCreatedJSONDeserializer());
$deserializerLocator->registerDeserializer(new StringLiteral('application/vnd.cultuurnet.udb2-events.actor-updated+json'), new ActorUpdatedJSONDeserializer());
$deserializerLocator->registerDeserializer(new StringLiteral('application/vnd.cultuurnet.udb2-events.event-created+json'), new EventCreatedJSONDeserializer());
$deserializerLocator->registerDeserializer(new StringLiteral('application/vnd.cultuurnet.udb2-events.event-updated+json'), new EventUpdatedJSONDeserializer());
return $deserializerLocator;
});
$app['udb2_event_bus_forwarding_consumer_factory'] = $app->share(function (Application $app) {
return new EventBusForwardingConsumerFactory($app['amqp-execution-delay'], $app['amqp.connection'], $app['logger.amqp.event_bus_forwarder'], $app['udb2_deserializer_locator'], $app['event_bus'], new StringLiteral($app['config']['amqp']['consumer_tag']));
});
$app['amqp.udb2_event_bus_forwarding_consumer'] = $app->share(function (Application $app) {
$consumerConfig = $app['config']['amqp']['consumers']['udb2'];
$exchange = new StringLiteral($consumerConfig['exchange']);
$queue = new StringLiteral($consumerConfig['queue']);
/** @var EventBusForwardingConsumerFactory $consumerFactory */
$consumerFactory = $app['udb2_event_bus_forwarding_consumer_factory'];
return $consumerFactory->create($exchange, $queue);
});
$app['cdbxml_enricher_http_client_adapter'] = $app->share(function (Application $app) {
$handlerStack = new HandlerStack(\GuzzleHttp\choose_handler());
$handlerStack->push(Middleware::prepareBody(), 'prepare_body');
$responseTimeout = 3;
$connectTimeout = 1;
if (isset($app['udb2_cdbxml_enricher.http_response_timeout'])) {
$responseTimeout = $app['udb2_cdbxml_enricher.http_response_timeout'];
}
if (isset($app['udb2_cdbxml_enricher.http_connect_timeout'])) {
$connectTimeout = $app['udb2_cdbxml_enricher.http_connect_timeout'];
}
$client = new Client(['handler' => $handlerStack, 'timeout' => $responseTimeout, 'connect_timeout' => $connectTimeout]);
return new ClientAdapter($client);
});
$app['cdbxml_enricher_logger'] = $app->share(function (Application $app) {
$logger = new \Monolog\Logger('udb2-events-cdbxml-enricher');
$logger->pushHandler($app['udb2_log_handler']);
return $logger;
});
$app['udb2_events_cdbxml_enricher'] = $app->share(function (Application $app) use($importFromSapi) {
$enricher = new EventCdbXmlEnricher($app['event_bus'], $app['cdbxml_enricher_http_client_adapter']);
$enricher->setLogger($app['cdbxml_enricher_logger']);
if ($importFromSapi) {
$eventUrlFormat = $app['config']['udb2_import']['event_url_format'];
if (!isset($eventUrlFormat)) {
throw new \Exception('can not import events from sapi without configuring an url format');
}
$transformer = new OfferToSapiUrlTransformer($eventUrlFormat);
$enricher->withUrlTransformer($transformer);
}
return $enricher;
});
$app['udb2_actor_events_cdbxml_enricher'] = $app->share(function (Application $app) use($importFromSapi) {
$enricher = new ActorEventCdbXmlEnricher($app['event_bus'], $app['cdbxml_enricher_http_client_adapter']);
$enricher->setLogger($app['cdbxml_enricher_logger']);
if ($importFromSapi) {
$actorUrlFormat = $app['config']['udb2_import']['actor_url_format'];
if (!isset($actorUrlFormat)) {
throw new \Exception('can not import actors from sapi without configuring an url format');
}
$transformer = new OfferToSapiUrlTransformer($actorUrlFormat);
$enricher->withUrlTransformer($transformer);
}
return $enricher;
});
$app['udb2_events_to_udb3_place_applier'] = $app->share(function (Application $app) {
$applier = new EventApplier(new LabeledAsUDB3Place(), $app['place_repository'], new EventToUDB3PlaceFactory());
$logger = new \Monolog\Logger('udb2-events-to-udb3-place-applier');
$logger->pushHandler($app['udb2_log_handler']);
$applier->setLogger($logger);
return $applier;
});
$app['udb2_events_to_udb3_event_applier'] = $app->share(function (Application $app) {
$applier = new EventApplier(new Not(new LabeledAsUDB3Place()), $app['event_repository'], new EventToUDB3EventFactory());
$logger = new \Monolog\Logger('udb2-events-to-udb3-event-applier');
$logger->pushHandler($app['udb2_log_handler']);
$applier->setLogger($logger);
return $applier;
});
$app['udb2_actor_events_to_udb3_place_applier'] = $app->share(function (Application $app) {
$applier = new ActorEventApplier($app['place_repository'], new ActorToUDB3PlaceFactory(), new QualifiesAsPlaceSpecification());
$logger = new \Monolog\Logger('udb2-actor-events-to-udb3-place-applier');
$logger->pushHandler($app['udb2_log_handler']);
$applier->setLogger($logger);
return $applier;
});
$app['udb2_actor_events_to_udb3_organizer_applier'] = $app->share(function (Application $app) {
$applier = new ActorEventApplier($app['organizer_repository'], new ActorToUDB3OrganizerFactory(), new QualifiesAsOrganizerSpecification());
$logger = new \Monolog\Logger('udb2-actor-events-to-udb3-organizer-applier');
$logger->pushHandler($app['udb2_log_handler']);
$applier->setLogger($logger);
return $applier;
});
//.........这里部分代码省略.........
示例6: prepareBody
/**
* @codeCoverageIgnore
*/
public static function prepareBody() : callable
{
return GuzzleMiddleware::prepareBody();
}
示例7: testIgnoresIfExpectIsPresent
public function testIgnoresIfExpectIsPresent()
{
$bd = Psr7\stream_for(fopen(__DIR__ . '/../composer.json', 'r'));
$h = new MockHandler([function (RequestInterface $request) {
$this->assertEquals(['Foo'], $request->getHeader('Expect'));
return new Response(200);
}]);
$m = Middleware::prepareBody();
$stack = new HandlerStack($h);
$stack->push($m);
$comp = $stack->resolve();
$p = $comp(new Request('PUT', 'http://www.google.com', ['Expect' => 'Foo'], $bd), ['expect' => true]);
$this->assertInstanceOf(PromiseInterface::class, $p);
$response = $p->wait();
$this->assertEquals(200, $response->getStatusCode());
}