2017 © Pedro Peláez
 

library legacy-php-http-kernel

Symfony HttpKernel for supporting controllers that exit or return null.

image

bangpound/legacy-php-http-kernel

Symfony HttpKernel for supporting controllers that exit or return null.

  • Tuesday, April 8, 2014
  • by bangpound
  • Repository
  • 2 Watchers
  • 1 Stars
  • 98 Installations
  • PHP
  • 3 Dependents
  • 2 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Legacy PHP HttpKernel

Build Status, (*1)

Controllers in legacy PHP applications don't return Symfony Response objects, and they might return nothing or even exit. These low-level Symfony components provide a simple bridge to legacy PHP applications., (*2)

Usage

Use the HttpKernel class and add the ShutdownListener and OutputBufferListener subscribers to the EventDispatcher., (*3)

Working Example #1

This component is used in Drufony to run Drupal 7 in the Symfony2 framework., (*4)

Working Example #2

  • Download and expand a recent version of WordPress.
  • In the WordPress directory, create composer.json:
{
    "require": {
        "bangpound/legacy-php-http-kernel": "1.0.*"
    }
}
  • Run composer install.
  • Replace WordPress's index.php front controller:
<?php
require "vendor/autoload.php";

use Bangpound\LegacyPhp\EventListener\OutputBufferListener;
use Bangpound\LegacyPhp\EventListener\ShutdownListener;
use Bangpound\LegacyPhp\HttpKernel;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcher;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

// Use a request attribute to identify requests which are legacy.
$matcher = new RequestMatcher();
$matcher->matchAttribute('_legacy', 'true');

$dispatcher = new EventDispatcher();

// Event listeners make Symfony reponses from output buffer and
// register a shutdown handler.
$dispatcher->addSubscriber(new OutputBufferListener($matcher));
$dispatcher->addSubscriber(new ShutdownListener($matcher));

// Add a listener that modifies every request to have a controller
// that imitates Wordpress index.php.
$dispatcher->addListener(KernelEvents::REQUEST,

    function (GetResponseEvent $event) {
        $request = $event->getRequest();
        $request->attributes->add(array(
            '_legacy' => 'true',
            '_controller' => function () {
                define('WP_USE_THEMES', true);
                require( dirname( __FILE__ ) . '/wp-blog-header.php' );
            },
        ));
    }

);

// This HttpKernel has a shutdown method which completes the kernel
// response cyle when a controller exits or dies.
$kernel = new HttpKernel($dispatcher, new ControllerResolver());

// Symfony front controller code
call_user_func(function () use ($kernel) {
    $request = Request::createFromGlobals();
    $response = $kernel->handle($request);
    $response->send();
    $kernel->terminate($request, $response);
});
  • Run php -S localhost:8000

The Versions

08/04 2014

dev-develop

dev-develop

Symfony HttpKernel for supporting controllers that exit or return null.

  Sources   Download

MIT

The Requires

 

The Development Requires

08/04 2014

dev-master

9999999-dev

Symfony HttpKernel for supporting controllers that exit or return null.

  Sources   Download

MIT

The Requires

 

The Development Requires

08/04 2014

1.1.1

1.1.1.0

Symfony HttpKernel for supporting controllers that exit or return null.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/04 2014

1.1.0

1.1.0.0

Symfony HttpKernel for supporting controllers that exit or return null.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/03 2014

1.0.0

1.0.0.0

Symfony HttpKernel for supporting controllers that exit or rreturn null.

  Sources   Download

MIT

The Requires