Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -1,70 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\Core\Http\Client.
*/
namespace Drupal\Core\Http;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Site\Settings;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Event\SubscriberInterface;
/**
* Drupal default HTTP client class.
*/
class Client extends GuzzleClient {
/**
* {@inheritdoc}
*/
public function __construct(array $config = []) {
$default_config = array(
// Security consideration: we must not use the certificate authority
// file shipped with Guzzle because it can easily get outdated if a
// certificate authority is hacked. Instead, we rely on the certificate
// authority file provided by the operating system which is more likely
// going to be updated in a timely fashion. This overrides the default
// path to the pem file bundled with Guzzle.
'verify' => TRUE,
'timeout' => 30,
'headers' => array(
'User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . static::getDefaultUserAgent(),
),
);
// The entire config array is merged/configurable to allow Guzzle client
// options outside of 'defaults' to be changed, such as 'adapter', or
// 'message_factory'.
$config = NestedArray::mergeDeep(array('defaults' => $default_config), $config, Settings::get('http_client_config', array()));
parent::__construct($config);
}
/**
* Attaches an event subscriber.
*
* @param \GuzzleHttp\Event\SubscriberInterface $subscriber
* The subscriber to attach.
*
* @see \GuzzleHttp\Event\Emitter::attach()
*/
public function attach(SubscriberInterface $subscriber) {
$this->getEmitter()->attach($subscriber);
}
/**
* Detaches an event subscriber.
*
* @param \GuzzleHttp\Event\SubscriberInterface $subscriber
* The subscriber to detach.
*
* @see \GuzzleHttp\Event\Emitter::detach()
*/
public function detach(SubscriberInterface $subscriber) {
$this->getEmitter()->detach($subscriber);
}
}

View file

@ -0,0 +1,67 @@
<?php
/**
* @file
* Contains \Drupal\Core\Http\ClientFactory.
*/
namespace Drupal\Core\Http;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Site\Settings;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
/**
* Helper class to construct a HTTP client with Drupal specific config.
*/
class ClientFactory {
/**
* The handler stack.
*
* @var \GuzzleHttp\HandlerStack
*/
protected $stack;
/**
* Constructs a new ClientFactory instance.
*
* @param \GuzzleHttp\HandlerStack $stack
* The handler stack.
*/
public function __construct(HandlerStack $stack) {
$this->stack = $stack;
}
/**
* Constructs a new client object from some configuration.
*
* @param array $config
* The config for the client.
*
* @return \GuzzleHttp\Client
* The HTTP client.
*/
public function fromOptions(array $config = []) {
$default_config = [
// Security consideration: we must not use the certificate authority
// file shipped with Guzzle because it can easily get outdated if a
// certificate authority is hacked. Instead, we rely on the certificate
// authority file provided by the operating system which is more likely
// going to be updated in a timely fashion. This overrides the default
// path to the pem file bundled with Guzzle.
'verify' => TRUE,
'timeout' => 30,
'headers' => [
'User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . \GuzzleHttp\default_user_agent(),
],
'handler' => $this->stack,
];
$config = NestedArray::mergeDeep($default_config, Settings::get('http_client_config', []), $config);
return new Client($config);
}
}

View file

@ -0,0 +1,94 @@
<?php
/**
* @file
* Contains \Drupal\Core\Http\HandlerStackConfigurator.
*/
namespace Drupal\Core\Http;
use GuzzleHttp\HandlerStack;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a class for configuring middlewares on the http handler stack.
*
* The http_client service requires a handler stack to perform http requests.
* This is provided by the http_handler_stack service. Modules wishing to add
* additional middlewares to the handler stack can create services and tag them
* as http_client_middleware. Each service must contain an __invoke method that
* returns a closure which will serve as the middleware.
*
* @see https://guzzle.readthedocs.org/en/latest/handlers-and-middleware.html
*
* @see \Drupal\Core\Http\Client
* @see \Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware
*/
class HandlerStackConfigurator {
/**
* Array of middlewares to add to the handler stack.
*
* @var callable[]
*/
protected $middlewares = NULL;
/**
* A list of used middleware service IDs.
*
* @var string[]
*/
protected $middlewareIds = [];
/**
* The service container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* Contructs a new HandlerStackConfigurator object.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container.
* @param string[] $middleware_ids
* The middleware IDs.
*/
public function __construct(ContainerInterface $container, array $middleware_ids) {
$this->middlewareIds = $middleware_ids;
$this->container = $container;
}
/**
* Ensures that the middlewares are initialized.
*/
protected function initializeMiddlewares() {
if (!isset($this->middlewares)) {
$this->middlewares = [];
foreach ($this->middlewareIds as $middleware_id) {
$middleware = $this->container->get($middleware_id);
if (is_callable($middleware)) {
$this->middlewares[$middleware_id] = $middleware();
}
else {
throw new \InvalidArgumentException('Middlewares need to implement __invoke, see https://guzzle.readthedocs.org/en/latest/handlers-and-middleware.html for more information about middlewares.');
}
}
}
}
/**
* Configures the stack using services tagged as http_client_middleware.
*
* @param \GuzzleHttp\HandlerStack $handler_stack
* The handler stack
*/
public function configure(HandlerStack $handler_stack) {
$this->initializeMiddlewares();
foreach ($this->middlewares as $middleware_id => $middleware) {
$handler_stack->push($middleware, $middleware_id);
}
}
}