Documentation fixes.
parent
867e7707f5
commit
820a633cce
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* Definition of Drupal\Core\EventSubscriber\RouterListener.
|
* Definition of Drupal\Core\EventSubscriber\RouteProcessorSubscriber.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Drupal\Core\EventSubscriber;
|
namespace Drupal\Core\EventSubscriber;
|
||||||
|
@ -18,33 +18,10 @@ use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
|
||||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drupal-specific Router listener.
|
* Listener to process request controller information.
|
||||||
*
|
|
||||||
* This is the bridge from the kernel to the UrlMatcher.
|
|
||||||
*/
|
*/
|
||||||
class RouteProcessorSubscriber implements EventSubscriberInterface {
|
class RouteProcessorSubscriber implements EventSubscriberInterface {
|
||||||
|
|
||||||
/**
|
|
||||||
* The Matcher object for this listener.
|
|
||||||
*
|
|
||||||
* This property is private in the base class, so we have to hack around it.
|
|
||||||
*
|
|
||||||
* @var Symfony\Component\Router\Matcher\UrlMatcherInterface
|
|
||||||
*/
|
|
||||||
protected $urlMatcher;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Logging object for this listener.
|
|
||||||
*
|
|
||||||
* This property is private in the base class, so we have to hack around it.
|
|
||||||
*
|
|
||||||
* @var Symfony\Component\HttpKernel\Log\LoggerInterface
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a default controller for a route if one was not specified.
|
* Sets a default controller for a route if one was not specified.
|
||||||
*/
|
*/
|
||||||
|
@ -54,7 +31,6 @@ class RouteProcessorSubscriber implements EventSubscriberInterface {
|
||||||
if (!$request->attributes->has('_controller') && $request->attributes->has('_content')) {
|
if (!$request->attributes->has('_controller') && $request->attributes->has('_content')) {
|
||||||
$request->attributes->set('_controller', '\Drupal\Core\HtmlPageController::content');
|
$request->attributes->set('_controller', '\Drupal\Core\HtmlPageController::content');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Definition of Drupal\Core\HtmlPageController.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Drupal\Core;
|
namespace Drupal\Core;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
@ -7,6 +12,9 @@ use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default controller for most HTML pages.
|
||||||
|
*/
|
||||||
class HtmlPageController implements ContainerAwareInterface {
|
class HtmlPageController implements ContainerAwareInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,10 +24,25 @@ class HtmlPageController implements ContainerAwareInterface {
|
||||||
*/
|
*/
|
||||||
protected $container;
|
protected $container;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injects the service container used by this object.
|
||||||
|
*
|
||||||
|
* @param ContainerInterface $container
|
||||||
|
* The service container this object should use.
|
||||||
|
*/
|
||||||
public function setContainer(ContainerInterface $container = NULL) {
|
public function setContainer(ContainerInterface $container = NULL) {
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller method for generic HTML pages.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* The request object.
|
||||||
|
* @param type $_content
|
||||||
|
* The body content callable that contains the body region of this page.
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
public function content(Request $request, $_content) {
|
public function content(Request $request, $_content) {
|
||||||
|
|
||||||
// @todo When we have a Generator, we can replace the forward() call with
|
// @todo When we have a Generator, we can replace the forward() call with
|
||||||
|
@ -28,7 +51,7 @@ class HtmlPageController implements ContainerAwareInterface {
|
||||||
// https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml
|
// https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml
|
||||||
// https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/InternalController.php
|
// https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/InternalController.php
|
||||||
$attributes = $request->attributes;
|
$attributes = $request->attributes;
|
||||||
$controller = $attributes->get('_content');
|
$controller = $_content;
|
||||||
$attributes->remove('system_path');
|
$attributes->remove('system_path');
|
||||||
$attributes->remove('_content');
|
$attributes->remove('_content');
|
||||||
$response = $this->container->get('http_kernel')->forward($controller, $attributes->all(), $request->query->all());
|
$response = $this->container->get('http_kernel')->forward($controller, $attributes->all(), $request->query->all());
|
||||||
|
@ -37,42 +60,4 @@ class HtmlPageController implements ContainerAwareInterface {
|
||||||
|
|
||||||
return new Response(drupal_render_page($page_content));
|
return new Response(drupal_render_page($page_content));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getContentController($controller) {
|
|
||||||
if (is_array($controller) || (is_object($controller) && method_exists($controller, '__invoke'))) {
|
|
||||||
return $controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FALSE === strpos($controller, ':')) {
|
|
||||||
if (method_exists($controller, '__invoke')) {
|
|
||||||
return new $controller;
|
|
||||||
} elseif (function_exists($controller)) {
|
|
||||||
return $controller;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
list($controller, $method) = $this->createController($controller);
|
|
||||||
|
|
||||||
if (!method_exists($controller, $method)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Method "%s::%s" does not exist.', get_class($controller), $method));
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($controller, $method);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function createController($controller) {
|
|
||||||
if (false === strpos($controller, '::')) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Unable to find controller "%s".', $controller));
|
|
||||||
}
|
|
||||||
|
|
||||||
list($class, $method) = explode('::', $controller, 2);
|
|
||||||
|
|
||||||
if (!class_exists($class)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(new $class(), $method);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Definition of Drupal\system\Tests\Routing\RouterTest.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Drupal\system\Tests\Routing;
|
namespace Drupal\system\Tests\Routing;
|
||||||
|
|
||||||
use Drupal\Core\Database\Database;
|
|
||||||
use Drupal\simpletest\WebTestBase;
|
use Drupal\simpletest\WebTestBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue