bangpound/drupal-kernel

Symfony HTTP kernel wrapper around Drupal 7

dev-master 2013-10-10 02:20 UTC

This package is auto-updated.

Last update: 2024-11-12 03:47:21 UTC


README

These two experimental classes wrap Drupal 7 in a Symfony HTTP kernel.

The kernel serializes the Symfony request object in customized front controller for Drupal. The front controller runs in an isolated PHP process. It requires the Composer autoloader so that it can access Symfony classes.

Before Drupal is bootstrapped, the injected request is unserialized and those values replace the globals in the Drupal process. The Drupal process is bootstrapped and the Drupal request is handled and the response is echoed as PHP CGI output.

The kernel which opened the process captures the output, parses the headers and returns a Symfony response object.

Inspiration, code and fair warning are taken from Igor Wiedler's CgiHttpKernel and The HttpKernelInterface is a lie.

This is not a way to run Drupal.

Usage

Just add bangpound/drupal-kernel to your composer.json file.

{
    "require": {
        "bangpound/drupal-kernel": "dev-master"
    }
}

Then create a front controller named index.php with this code in it:

<?php

$loader = require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR .'vendor'. DIRECTORY_SEPARATOR .'autoload.php';

$app = new \Bangpound\Drupal\Kernel($loader, __DIR__ .'/../vendor/drupal/drupal');

$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$response = $app->handle($request);
$response->send();
if ($app instanceof \Symfony\Component\HttpKernel\TerminableInterface) {
    $app->terminate($request, $response);
}

If you need to make changes to your Request object so that it provides all the globals Drupal needs, change the request object before handing it to the handle() method.