Skip to content

Instantly share code, notes, and snippets.

@naderman
Created March 5, 2011 13:20
Show Gist options
  • Save naderman/856350 to your computer and use it in GitHub Desktop.
Save naderman/856350 to your computer and use it in GitHub Desktop.
Drupal 7.0 Symfony2 Integration (Proof of Concept)
name = Symfony
description = Symfony Integration
core = 7.x
<?php
require_once __DIR__.'/../../../../../../../symfony-sandbox/app/bootstrap.php';
require_once __DIR__.'/../../../../../../../symfony-sandbox/app/AppKernel.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session;
use phpBB\DrupalIntegration\DrupalSessionStorage;
function symfony_menu()
{
return array(
'symfony' => array(
'title' => 'Symfony Sandbox',
'page callback' => 'symfony_show_view',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
),
);
}
function symfony_replace_uri($uri)
{
$destination = drupal_get_destination();
$destination = preg_replace('/\?.*/', '', $destination['destination']);
return preg_replace_callback(
'#/\?q=('.$destination.')/?(?:&?(.*))$#',
function ($matches) {
$result = '/'.$matches[1];
if ('symfony' === $matches[1]) {
$result .= '/';
}
return $result . ((isset($matches[2])) ? '?'.$matches[2] : '');
},
$uri);
}
function symfony_show_view()
{
$server = $_SERVER;
if (isset($_REQUEST['q'])) {
$server['REQUEST_URI'] = symfony_replace_uri($server['REQUEST_URI']);
}
$server['SCRIPT_FILENAME'] = str_replace('/index.php/', '/', $server['SCRIPT_FILENAME'].'/symfony');
$server['SCRIPT_NAME'] = $server['PHP_SELF'] = $GLOBALS['base_path'].'symfony';
$server['SCRIPT_URL'] .= 'symfony/';
$server['SCRIPT_URI'] .= 'symfony/';
$request = new Request($_GET, $_POST, array(), $_COOKIE, $_FILES, $server);
$kernel = new AppKernel('dev', true);
$kernel->boot();
$kernel->getContainer()->set('session.storage', new DrupalSessionStorage());
$response = $kernel->handle($request);
$response->sendHeaders();
$content = $response->getContent();
if (strpos($content, '<!-- START') !== false) {
$response->sendContent();
return;
}
return $content;
}
@iadegesso
Copy link

Interesting idea, but... some working example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment