Commit 2f6b442d authored by katbailey's avatar katbailey

Initial steps toward adding the language manager service

parent 5efc932f
......@@ -6,6 +6,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
......@@ -17,11 +18,15 @@
class CoreBundle extends Bundle
{
public function build(ContainerBuilder $container) {
$container->addScope(new Scope('request'));
$container->register('dispatcher', 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher')
->addArgument(new Reference('service_container'));
$container->register('resolver', 'Symfony\Component\HttpKernel\Controller\ControllerResolver');
$container->register('http_kernel', 'Symfony\Component\HttpKernel\HttpKernel')
$container->register('http_kernel', 'Drupal\Core\HttpKernel')
->addArgument(new Reference('dispatcher'))
->addArgument(new Reference('service_container'))
->addArgument(new Reference('resolver'));
$container->register('matcher', 'Drupal\Core\LegacyUrlMatcher');
$container->register('router_listener', 'Drupal\Core\EventSubscriber\RouterListener')
......@@ -58,6 +63,11 @@ public function build(ContainerBuilder $container) {
->addArgument(new Reference('service_container'))
->setFactoryClass('Drupal\Core\ExceptionController')
->setFactoryMethod('getExceptionListener');
$container->register('request', 'Symfony\Component\HttpFoundation\Request')
->setSynthetic(TRUE);
$container->register('language_manager', 'Drupal\Core\Language\LanguageManager')
->addArgument(new Reference('request'))
->setScope('request');
// Add a compiler pass for registering event subscribers.
$container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
......
......@@ -12,7 +12,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\HttpKernel;
use Drupal\Core\HttpKernel;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
......
<?php
/**
* @file
* Definition of Drupal\Core\HttpKernel.
*/
namespace Drupal\Core;
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\HttpKernel as BaseHttpKernel;
/**
* This HttpKernel is used to manage scope changes of the DI container.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class HttpKernel extends BaseHttpKernel
{
protected $container;
public function __construct(ContainerAwareEventDispatcher $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver)
{
parent::__construct($dispatcher, $controllerResolver);
$this->container = $container;
}
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
$request->headers->set('X-Php-Ob-Level', ob_get_level());
$this->container->enterScope('request');
$this->container->set('request', $request, 'request');
try {
$response = parent::handle($request, $type, $catch);
} catch (\Exception $e) {
$this->container->leaveScope('request');
throw $e;
}
$this->container->leaveScope('request');
return $response;
}
}
<?php
/**
* @file
* Definition of Drupal\Core\Language\LanguageManager.
*/
namespace Drupal\Core\Language;
use Symfony\Component\HttpFoundation\Request;
/**
* Ajl
*/
class LanguageManager {
private $container;
public function __construct(Request $request) {
$this->request = $request;
}
public function interfaceLanguage() {
$language = language_types_initialize(LANGUAGE_TYPE_INTERFACE);
return $language;
}
public function contentLanguage() {
$language = language_types_initialize(LANGUAGE_TYPE_CONTENT);
return $language;
}
public function urlLanguage() {
$language = language_types_initialize(LANGUAGE_TYPE_URL);
return $language;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment