Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,57 @@
<?php
/**
* @file
* Contains \Drupal\Core\StackMiddleware\KernelPreHandle.
*/
namespace Drupal\Core\StackMiddleware;
use Drupal\Core\DrupalKernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* Prepares the environment after page caching ran.
*/
class KernelPreHandle implements HttpKernelInterface {
/**
* The wrapped HTTP kernel.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* The main Drupal kernel.
*
* @var \Drupal\Core\DrupalKernelInterface
*/
protected $drupalKernel;
/**
* Constructs a new KernelPreHandle instance.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
* The wrapped HTTP kernel.
*
* @param \Drupal\Core\DrupalKernelInterface $drupal_kernel
* The main Drupal kernel.
*/
public function __construct(HttpKernelInterface $http_kernel, DrupalKernelInterface $drupal_kernel) {
$this->httpKernel = $http_kernel;
$this->drupalKernel = $drupal_kernel;
}
/**
* {@inheritdoc}
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
$this->drupalKernel->preHandle($request);
return $this->httpKernel->handle($request, $type, $catch);
}
}

View file

@ -0,0 +1,85 @@
<?php
/**
* @file
* Contains \Drupal\Core\StackMiddleware\NegotiationMiddleware.
*/
namespace Drupal\Core\StackMiddleware;
use Drupal\Core\ContentNegotiation;
use Drupal\Core\ContentNegotiationInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* Provides a middleware to determine the content type upon the accept header.
*
* @todo This is a temporary solution, remove this in https://www.drupal.org/node/2364011
*/
class NegotiationMiddleware implements HttpKernelInterface {
/**
* The wrapped HTTP kernel.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $app;
/**
* The content negotiator.
*
* @var \Drupal\Core\ContentNegotiation
*/
protected $negotiator;
/**
* Contains a hashmap of format as key and mimetype as value.
*
* @var array
*/
protected $formats = [];
/**
* Constructs a new NegotiationMiddleware.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $app
* The wrapper HTTP kernel
* @param \Drupal\Core\ContentNegotiation $negotiator
* The content negotiator.
*/
public function __construct(HttpKernelInterface $app, ContentNegotiation $negotiator) {
$this->app = $app;
$this->negotiator = $negotiator;
}
/**
* {@inheritdoc}
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) {
// Register available mime types.
foreach ($this->formats as $format => $mime_type) {
$request->setFormat($format, $mime_type);
}
// Determine the request format using the negotiator.
$request->setRequestFormat($this->negotiator->getContentType($request));
return $this->app->handle($request, $type, $catch);
}
/**
* Registers a format for a given MIME type.
*
* @param string $format
* The format.
* @param string $mime_type
* The MIME type.
*
* @return $this
*/
public function registerFormat($format, $mime_type) {
$this->formats[$format] = $mime_type;
return $this;
}
}

View file

@ -0,0 +1,61 @@
<?php
/**
* @file
* Contains \Drupal\Core\StackMiddleware\ReverseProxyMiddleware.
*/
namespace Drupal\Core\StackMiddleware;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
*
*/
class ReverseProxyMiddleware implements HttpKernelInterface {
/**
* The decorated kernel.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* The site settings.
*
* @var \Drupal\Core\Site\Settings
*/
protected $settings;
/**
* Constructs a ReverseProxyMiddleware object.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
* The decorated kernel.
* @param \Drupal\Core\Site\Settings $settings
* The site settings.
*/
public function __construct(HttpKernelInterface $http_kernel, Settings $settings) {
$this->httpKernel = $http_kernel;
$this->settings = $settings;
}
/**
* {@inheritdoc}
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
// Initialize proxy settings.
if ($this->settings->get('reverse_proxy', FALSE)) {
$reverse_proxy_header = $this->settings->get('reverse_proxy_header', 'X_FORWARDED_FOR');
$request::setTrustedHeaderName($request::HEADER_CLIENT_IP, $reverse_proxy_header);
$proxies = $this->settings->get('reverse_proxy_addresses', array());
if (count($proxies) > 0) {
$request::setTrustedProxies($proxies);
}
}
return $this->httpKernel->handle($request, $type, $catch);
}
}

View file

@ -0,0 +1,71 @@
<?php
/**
* @file
* Contains \Drupal\Core\StackMiddleware\Session.
*/
namespace Drupal\Core\StackMiddleware;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* Wrap session logic around a HTTP request.
*
* Note, the session service is not injected into this class in order to prevent
* premature initialization of session storage (database). Instead the session
* service is retrieved from the container only when handling the request.
*/
class Session implements HttpKernelInterface {
use ContainerAwareTrait;
/**
* The wrapped HTTP kernel.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* The session service name.
*
* @var string
*/
protected $sessionServiceName;
/**
* Constructs a Session stack middleware object.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
* The decorated kernel.
* @param string $service_name
* The name of the session service, defaults to "session".
*/
public function __construct(HttpKernelInterface $http_kernel, $service_name = 'session') {
$this->httpKernel = $http_kernel;
$this->sessionServiceName = $service_name;
}
/**
* {@inheritdoc}
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
if ($type === self::MASTER_REQUEST && PHP_SAPI !== 'cli') {
$session = $this->container->get($this->sessionServiceName);
$session->start();
$request->setSession($session);
}
$result = $this->httpKernel->handle($request, $type, $catch);
if ($type === self::MASTER_REQUEST && $request->hasSession()) {
$request->getSession()->save();
}
return $result;
}
}