summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries2012-06-01 15:46:10 (GMT)
committer Dries2012-06-01 15:46:10 (GMT)
commit302061324de2c865a44e3c7f8dc7d2a6bbf8c8b2 (patch)
treef4d544ed2f346345c0174dfc9b9f7c6da8406825
parent5b0715d78b4e26e86166ef4793a1ebf738e1d05c (diff)
parent94d877eb947195bc0c5d94c01bdf7f0430bc238e (diff)
Merge remote-tracking branch 'wscci/kernel' into 8.x
-rw-r--r--core/authorize.php5
-rw-r--r--core/includes/batch.inc6
-rw-r--r--core/includes/bootstrap.inc39
-rw-r--r--core/includes/common.inc43
-rw-r--r--core/includes/errors.inc16
-rw-r--r--core/includes/file.inc41
-rw-r--r--core/includes/install.core.inc20
-rw-r--r--core/lib/Drupal/Core/ContentNegotiation.php54
-rw-r--r--core/lib/Drupal/Core/Database/Connection.php17
-rw-r--r--core/lib/Drupal/Core/Database/DatabaseExceptionWrapper.php19
-rw-r--r--core/lib/Drupal/Core/Database/Driver/mysql/Connection.php10
-rw-r--r--core/lib/Drupal/Core/DrupalKernel.php65
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php49
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php83
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/LegacyControllerSubscriber.php62
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php61
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php59
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/PathListenerBase.php29
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php126
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php63
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/RouterListener.php96
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php128
-rw-r--r--core/lib/Drupal/Core/ExceptionController.php406
-rw-r--r--core/lib/Drupal/Core/LegacyUrlMatcher.php164
-rw-r--r--core/lib/Drupal/Core/Lock/DatabaseLockBackend.php4
-rw-r--r--core/modules/aggregator/aggregator.admin.inc9
-rw-r--r--core/modules/comment/comment.admin.inc2
-rw-r--r--core/modules/comment/comment.pages.inc11
-rw-r--r--core/modules/image/image.module14
-rw-r--r--core/modules/image/image.test2
-rw-r--r--core/modules/node/lib/Drupal/node/Tests/NodeFeedTest.php7
-rw-r--r--core/modules/node/node.module15
-rw-r--r--core/modules/openid/tests/openid_test.module32
-rw-r--r--core/modules/overlay/overlay.module60
-rw-r--r--core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php2
-rw-r--r--core/modules/system/system.admin.inc5
-rw-r--r--core/modules/system/system.module13
-rw-r--r--core/modules/system/system.test2
-rw-r--r--core/modules/system/tests/bootstrap.test2
-rw-r--r--core/modules/system/tests/error.test6
-rw-r--r--core/modules/taxonomy/taxonomy.test5
-rw-r--r--core/modules/update/tests/modules/update_test/update_test.module15
-rw-r--r--core/modules/update/update.fetch.inc2
-rw-r--r--core/modules/user/user.module5
-rw-r--r--core/update.php53
-rw-r--r--index.php32
46 files changed, 1795 insertions, 164 deletions
diff --git a/core/authorize.php b/core/authorize.php
index d703b33..fd0774d 100644
--- a/core/authorize.php
+++ b/core/authorize.php
@@ -84,10 +84,7 @@ module_list(TRUE, FALSE, FALSE, $module_list);
drupal_load('module', 'system');
drupal_load('module', 'user');
-// We also want to have the language system available, but we do *NOT* want to
-// actually call drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE), since that would
-// also force us through the DRUPAL_BOOTSTRAP_PAGE_HEADER phase, which loads
-// all the modules, and that's exactly what we're trying to avoid.
+// Initialize the language system.
drupal_language_initialize();
// Initialize the maintenance theme for this administrative script.
diff --git a/core/includes/batch.inc b/core/includes/batch.inc
index 83ddd30..0b07d8e 100644
--- a/core/includes/batch.inc
+++ b/core/includes/batch.inc
@@ -14,6 +14,8 @@
* @see batch_get()
*/
+use \Symfony\Component\HttpFoundation\JsonResponse;
+
/**
* Loads a batch from the database.
*
@@ -77,7 +79,7 @@ function _batch_page() {
case 'do':
// JavaScript-based progress page callback.
- _batch_do();
+ $output = _batch_do();
break;
case 'do_nojs':
@@ -160,7 +162,7 @@ function _batch_do() {
// Perform actual processing.
list($percentage, $message) = _batch_process();
- drupal_json_output(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message));
+ return new JsonResponse(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message));
}
/**
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index c2c3d91..e64bfca 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -4,6 +4,7 @@ use Drupal\Core\Database\Database;
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Symfony\Component\HttpFoundation\Request;
/**
* @file
@@ -137,12 +138,12 @@ const DRUPAL_BOOTSTRAP_SESSION = 4;
const DRUPAL_BOOTSTRAP_PAGE_HEADER = 5;
/**
- * Seventh bootstrap phase: find out language of the page.
+ * Seventh bootstrap phase: load code for subsystems and modules.
*/
-const DRUPAL_BOOTSTRAP_LANGUAGE = 6;
+const DRUPAL_BOOTSTRAP_CODE = 6;
/**
- * Final bootstrap phase: Drupal is fully loaded; validate and fix input data.
+ * Final bootstrap phase: initialize language, path, theme, and modules.
*/
const DRUPAL_BOOTSTRAP_FULL = 7;
@@ -1606,6 +1607,29 @@ function request_uri($omit_query_string = FALSE) {
}
/**
+ * Returns the current global request object.
+ *
+ * @todo Replace this function with a proper dependency injection container.
+ *
+ * @staticvar Symfony\Component\HttpFoundation\Request $request
+ *
+ * @param Symfony\Component\HttpFoundation\Request $new_request
+ * Optional. The new request object to store. This parameter should only be
+ * used by index.php.
+ *
+ * @return Symfony\Component\HttpFoundation\Request
+ * The current request object.
+ */
+function request(Request $new_request = NULL) {
+ static $request;
+
+ if ($new_request) {
+ $request = $new_request;
+ }
+ return $request;
+}
+
+/**
* Logs an exception.
*
* This is a wrapper function for watchdog() which automatically decodes an
@@ -2094,7 +2118,7 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
DRUPAL_BOOTSTRAP_VARIABLES,
DRUPAL_BOOTSTRAP_SESSION,
DRUPAL_BOOTSTRAP_PAGE_HEADER,
- DRUPAL_BOOTSTRAP_LANGUAGE,
+ DRUPAL_BOOTSTRAP_CODE,
DRUPAL_BOOTSTRAP_FULL,
);
// Not drupal_static(), because the only legitimate API to control this is to
@@ -2147,12 +2171,12 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
_drupal_bootstrap_page_header();
break;
- case DRUPAL_BOOTSTRAP_LANGUAGE:
- drupal_language_initialize();
+ case DRUPAL_BOOTSTRAP_CODE:
+ require_once DRUPAL_ROOT . '/core/includes/common.inc';
+ _drupal_bootstrap_code();
break;
case DRUPAL_BOOTSTRAP_FULL:
- require_once DRUPAL_ROOT . '/core/includes/common.inc';
_drupal_bootstrap_full();
break;
}
@@ -2375,7 +2399,6 @@ function _drupal_bootstrap_page_header() {
if (!drupal_is_cli()) {
ob_start();
- drupal_page_header();
}
}
diff --git a/core/includes/common.inc b/core/includes/common.inc
index 4a8b1f0..be6cab9 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -1,5 +1,7 @@
<?php
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\Core\Database\Database;
/**
@@ -705,7 +707,7 @@ function drupal_site_offline() {
* bubble up to menu_execute_active_handler() should call drupal_not_found().
*/
function drupal_not_found() {
- drupal_deliver_page(MENU_NOT_FOUND);
+ throw new NotFoundHttpException();
}
/**
@@ -718,7 +720,7 @@ function drupal_not_found() {
* drupal_access_denied().
*/
function drupal_access_denied() {
- drupal_deliver_page(MENU_ACCESS_DENIED);
+ throw new AccessDeniedHttpException();
}
/**
@@ -5101,13 +5103,10 @@ function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) {
return (($skip_anonymous && $user->uid == 0) || ($token == drupal_get_token($value)));
}
-function _drupal_bootstrap_full() {
- static $called = FALSE;
-
- if ($called) {
- return;
- }
- $called = TRUE;
+/**
+ * Loads code for subsystems and modules, and registers stream wrappers.
+ */
+function _drupal_bootstrap_code() {
require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'core/includes/path.inc');
require_once DRUPAL_ROOT . '/core/includes/theme.inc';
require_once DRUPAL_ROOT . '/core/includes/pager.inc';
@@ -5126,16 +5125,38 @@ function _drupal_bootstrap_full() {
// Load all enabled modules
module_load_all();
+
// Make sure all stream wrappers are registered.
file_get_stream_wrappers();
+ // Now that stream wrappers are registered, log fatal errors from a simpletest
+ // child site to a test specific file directory.
$test_info = &$GLOBALS['drupal_test_info'];
if (!empty($test_info['in_child_site'])) {
- // Running inside the simpletest child site, log fatal errors to test
- // specific file directory.
ini_set('log_errors', 1);
ini_set('error_log', 'public://error.log');
}
+}
+
+/**
+ * Temporary BC function for scripts not using DrupalKernel.
+ *
+ * DrupalKernel skips this and replicates it via event listeners.
+ *
+ * @see Drupal\Core\EventSubscriber\PathSubscriber;
+ * @see Drupal\Core\EventSubscriber\LegacyRequestSubscriber;
+ */
+function _drupal_bootstrap_full($skip = FALSE) {
+ static $called = FALSE;
+
+ if ($called || $skip) {
+ $called = TRUE;
+ return;
+ }
+
+ // Initialize language (which can strip path prefix) prior to initializing
+ // current_path().
+ drupal_language_initialize();
// Initialize current_path() prior to invoking hook_init().
drupal_path_initialize();
diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index 0524170..97f5b6a 100644
--- a/core/includes/errors.inc
+++ b/core/includes/errors.inc
@@ -5,6 +5,8 @@
* Functions for error handling.
*/
+use Symfony\Component\HttpFoundation\Response;
+
/**
* Error reporting level: display no errors.
*/
@@ -215,10 +217,6 @@ function _drupal_log_error($error, $fatal = FALSE) {
watchdog('php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);
- if ($fatal) {
- drupal_add_http_header('Status', '500 Service unavailable (with message)');
- }
-
if (drupal_is_cli()) {
if ($fatal) {
// When called from CLI, simply output a plain text message.
@@ -254,8 +252,14 @@ function _drupal_log_error($error, $fatal = FALSE) {
drupal_set_title(t('Error'));
// We fallback to a maintenance page at this point, because the page generation
// itself can generate errors.
- print theme('maintenance_page', array('content' => t('The website encountered an unexpected error. Please try again later.')));
- exit;
+ $output = theme('maintenance_page', array('content' => t('The website encountered an unexpected error. Please try again later.')));
+
+ $response = new Response($output, 500);
+ if ($fatal) {
+ $response->setStatusCode(500, '500 Service unavailable (with message)');
+ }
+
+ return $response;
}
}
}
diff --git a/core/includes/file.inc b/core/includes/file.inc
index f204989..f6cab86 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -5,6 +5,9 @@
* API for handling file uploads and server file management.
*/
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Symfony\Component\HttpFoundation\StreamedResponse;
use Drupal\Core\StreamWrapper\LocalStream;
/**
@@ -1975,26 +1978,15 @@ function file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EX
* An array of HTTP headers to send along with file.
*/
function file_transfer($uri, $headers) {
- if (ob_get_level()) {
- ob_end_clean();
- }
-
- foreach ($headers as $name => $value) {
- drupal_add_http_header($name, $value);
- }
- drupal_send_headers();
- $scheme = file_uri_scheme($uri);
- // Transfer file in 1024 byte chunks to save memory usage.
- if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) {
- while (!feof($fd)) {
- print fread($fd, 1024);
+ return new StreamedResponse(function() use ($uri) {
+ // Transfer file in 1024 byte chunks to save memory usage.
+ if (file_exists($uri) && $fd = fopen($uri, 'rb')) {
+ while (!feof($fd)) {
+ print fread($fd, 1024);
+ }
+ fclose($fd);
}
- fclose($fd);
- }
- else {
- drupal_not_found();
- }
- drupal_exit();
+ }, 200, $headers);
}
/**
@@ -2026,18 +2018,18 @@ function file_download() {
$function = $module . '_file_download';
$result = $function($uri);
if ($result == -1) {
- return drupal_access_denied();
+ throw new AccessDeniedHttpException();
}
if (isset($result) && is_array($result)) {
$headers = array_merge($headers, $result);
}
}
if (count($headers)) {
- file_transfer($uri, $headers);
+ return file_transfer($uri, $headers);
}
- return drupal_access_denied();
+ throw new AccessDeniedHttpException();
}
- return drupal_not_found();
+ throw new NotFoundHttpException();
}
@@ -2517,7 +2509,8 @@ function file_directory_temp() {
* A file object.
*
* @return
- * An associative array of headers, as expected by file_transfer().
+ * An associative array of headers, as expected by
+ * \Symfony\Component\HttpFoundation\StreamedResponse.
*/
function file_get_content_headers($file) {
$name = mime_header_encode($file->filename);
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index e62a7b5..eb9dff9 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -3,6 +3,9 @@
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Install\TaskException;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
/**
* @file
* API functions for installing Drupal.
@@ -248,6 +251,14 @@ function install_begin_request(&$install_state) {
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
+ // A request object from the HTTPFoundation to tell us about the request.
+ $request = Request::createFromGlobals();
+
+ // Set the global $request object. This is a temporary measure to
+ // keep legacy utility functions working. It should be moved to a dependency
+ // injection container at some point.
+ request($request);
+
// This must go after drupal_bootstrap(), which unsets globals!
global $conf;
@@ -477,6 +488,15 @@ function install_run_task($task, &$install_state) {
elseif ($current_batch == $function) {
include_once DRUPAL_ROOT . '/core/includes/batch.inc';
$output = _batch_page();
+ // Because Batch API now returns a JSON response for intermediary steps,
+ // but the installer doesn't handle Response objects yet, just send the
+ // output here and emulate the old model.
+ // @todo Replace this when we refactor the installer to use a request-
+ // response workflow.
+ if ($output instanceof Response) {
+ $output->send();
+ $output = NULL;
+ }
// The task is complete when we try to access the batch page and receive
// FALSE in return, since this means we are at a URL where we are no
// longer requesting a batch ID.
diff --git a/core/lib/Drupal/Core/ContentNegotiation.php b/core/lib/Drupal/Core/ContentNegotiation.php
new file mode 100644
index 0000000..6302db8
--- /dev/null
+++ b/core/lib/Drupal/Core/ContentNegotiation.php
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\ContentNegotiation.
+ */
+
+namespace Drupal\Core;
+
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * This class is a central library for content type negotiation.
+ *
+ * @todo Replace this class with a real content negotiation library based on
+ * mod_negotiation. Development of that is a work in progress.
+ */
+class ContentNegotiation {
+
+ /**
+ * Gets the normalized type of a request.
+ *
+ * The normalized type is a short, lowercase version of the format, such as
+ * 'html', 'json' or 'atom'.
+ *
+ * @param Symfony\Component\HttpFoundation\Request $request
+ * The request object from which to extract the content type.
+ *
+ * @return
+ * The normalized type of a given request.
+ */
+ public function getContentType(Request $request) {
+ // AJAX iframe uploads need special handling, because they contain a JSON
+ // response wrapped in <textarea>.
+ if ($request->get('ajax_iframe_upload', FALSE)) {
+ return 'iframeupload';
+ }
+
+ // AJAX calls need to be run through ajax rendering functions
+ elseif ($request->isXmlHttpRequest()) {
+ return 'ajax';
+ }
+
+ foreach ($request->getAcceptableContentTypes() as $mime_type) {
+ $format = $request->getFormat($mime_type);
+ if (!is_null($format)) {
+ return $format;
+ }
+ }
+
+ // Do HTML last so that it always wins.
+ return 'html';
+ }
+}
diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php
index 446ab99..94a23fb 100644
--- a/core/lib/Drupal/Core/Database/Connection.php
+++ b/core/lib/Drupal/Core/Database/Connection.php
@@ -524,15 +524,14 @@ abstract class Connection extends PDO {
}
catch (PDOException $e) {
if ($options['throw_exception']) {
- // Add additional debug information.
- if ($query instanceof DatabaseStatementInterface) {
- $e->query_string = $stmt->getQueryString();
- }
- else {
- $e->query_string = $query;
- }
- $e->args = $args;
- throw $e;
+ // Wrap the exception in another exception, because PHP does not allow
+ // overriding Exception::getMessage(). Its message is the extra database
+ // debug information.
+ $query_string = ($query instanceof DatabaseStatementInterface) ? $stmt->getQueryString() : $query;
+ $message = $e->getMessage() . ": " . $query_string . "; " . print_r($args, TRUE);
+ $exception = new DatabaseExceptionWrapper($message, 0, $e);
+
+ throw $exception;
}
return NULL;
}
diff --git a/core/lib/Drupal/Core/Database/DatabaseExceptionWrapper.php b/core/lib/Drupal/Core/Database/DatabaseExceptionWrapper.php
new file mode 100644
index 0000000..b212478
--- /dev/null
+++ b/core/lib/Drupal/Core/Database/DatabaseExceptionWrapper.php
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\Database\DatabaseExceptionWrapper.
+ */
+
+namespace Drupal\Core\Database;
+
+use RuntimeException;
+
+/**
+ * This wrapper class serves only to provide additional debug information.
+ *
+ * This class will always wrap a PDOException.
+ */
+class DatabaseExceptionWrapper extends RuntimeException implements DatabaseException {
+
+}
diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
index 8668c0f..fbbff42 100644
--- a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
@@ -7,12 +7,14 @@
namespace Drupal\Core\Database\Driver\mysql;
+use Drupal\Core\Database\DatabaseExceptionWrapper;
+
use Drupal\Core\Database\Database;
use Drupal\Core\Database\TransactionCommitFailedException;
+use Drupal\Core\Database\DatabaseException;
use Drupal\Core\Database\Connection as DatabaseConnection;
use PDO;
-use PDOException;
/**
* @addtogroup database
@@ -153,7 +155,7 @@ class Connection extends DatabaseConnection {
// errors. There is no problem with completely ignoring errors here: if
// these queries fail, the sequence will work just fine, just use a bit
// more database storage and memory.
- catch (PDOException $e) {
+ catch (DatabaseException $e) {
}
}
@@ -180,7 +182,7 @@ class Connection extends DatabaseConnection {
try {
$this->query('RELEASE SAVEPOINT ' . $name);
}
- catch (PDOException $e) {
+ catch (DatabaseExceptionWrapper $e) {
// However, in MySQL (InnoDB), savepoints are automatically committed
// when tables are altered or created (DDL transactions are not
// supported). This can cause exceptions due to trying to release
@@ -188,7 +190,7 @@ class Connection extends DatabaseConnection {
//
// To avoid exceptions when no actual error has occurred, we silently
// succeed for MySQL error code 1305 ("SAVEPOINT does not exist").
- if ($e->errorInfo[1] == '1305') {
+ if ($e->getPrevious()->errorInfo[1] == '1305') {
// If one SAVEPOINT was released automatically, then all were.
// Therefore, clean the transaction stack.
$this->transactionLayers = array();
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
new file mode 100644
index 0000000..7361a82
--- /dev/null
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\DrupalKernel.
+ */
+
+namespace Drupal\Core;
+
+use Symfony\Component\HttpKernel\HttpKernel;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
+use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
+use Drupal\Core\EventSubscriber\ViewSubscriber;
+use Drupal\Core\EventSubscriber\AccessSubscriber;
+use Drupal\Core\EventSubscriber\FinishResponseSubscriber;
+use Drupal\Core\EventSubscriber\PathSubscriber;
+use Drupal\Core\EventSubscriber\LegacyRequestSubscriber;
+use Drupal\Core\EventSubscriber\LegacyControllerSubscriber;
+use Drupal\Core\EventSubscriber\MaintenanceModeSubscriber;
+use Drupal\Core\EventSubscriber\RequestCloseSubscriber;
+use Drupal\Core\EventSubscriber\RouterListener;
+
+/**
+ * The DrupalKernel class is the core of Drupal itself.
+ */
+class DrupalKernel extends HttpKernel {
+
+ /**
+ * Constructor.
+ *
+ * @param Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
+ * An EventDispatcherInterface instance.
+ * @param Symfony\Component\HttpKernel\Controller\ControllerResolverInterface $resolver
+ * A ControllerResolverInterface instance.
+ */
+ public function __construct(EventDispatcherInterface $dispatcher, ControllerResolverInterface $resolver) {
+ parent::__construct($dispatcher, $resolver);
+
+ $this->matcher = new LegacyUrlMatcher();
+ $this->dispatcher->addSubscriber(new RouterListener($this->matcher));
+
+ $negotiation = new ContentNegotiation();
+
+ // @todo Make this extensible rather than just hard coding some.
+ // @todo Add a subscriber to handle other things, too, like our Ajax
+ // replacement system.
+ $this->dispatcher->addSubscriber(new ViewSubscriber($negotiation));
+ $this->dispatcher->addSubscriber(new AccessSubscriber());
+ $this->dispatcher->addSubscriber(new MaintenanceModeSubscriber());
+ $this->dispatcher->addSubscriber(new PathSubscriber());
+ $this->dispatcher->addSubscriber(new LegacyRequestSubscriber());
+ $this->dispatcher->addSubscriber(new LegacyControllerSubscriber());
+ $this->dispatcher->addSubscriber(new FinishResponseSubscriber());
+ $this->dispatcher->addSubscriber(new RequestCloseSubscriber());
+
+ // Some other form of error occured that wasn't handled by another kernel
+ // listener. That could mean that it's a method/mime-type/error
+ // combination that is not accounted for, or some other type of error.
+ // Either way, treat it as a server-level error and return an HTTP 500.
+ // By default, this will be an HTML-type response because that's a decent
+ // best guess if we don't know otherwise.
+ $this->dispatcher->addSubscriber(new ExceptionListener(array(new ExceptionController($this, $negotiation), 'execute')));
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php
new file mode 100644
index 0000000..4f1dc75
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\AccessSubscriber.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Access subscriber for controller requests.
+ */
+class AccessSubscriber implements EventSubscriberInterface {
+
+ /**
+ * Verifies that the current user can access the requested path.
+ *
+ * @todo This is a total hack to keep our current access system working. It
+ * should be replaced with something robust and injected at some point.
+ *
+ * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onKernelRequestAccessCheck(GetResponseEvent $event) {
+
+ $router_item = $event->getRequest()->attributes->get('drupal_menu_item');
+
+ if (isset($router_item['access']) && !$router_item['access']) {
+ throw new AccessDeniedHttpException();
+ }
+ }
+
+ /**
+ * Registers the methods in this class that should be listeners.
+ *
+ * @return array
+ * An array of event listener definitions.
+ */
+ static function getSubscribedEvents() {
+ $events[KernelEvents::REQUEST][] = array('onKernelRequestAccessCheck', 30);
+
+ return $events;
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
new file mode 100644
index 0000000..6e23845
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\FinishResponseSubscriber.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Response subscriber to handle finished responses.
+ */
+class FinishResponseSubscriber implements EventSubscriberInterface {
+
+ /**
+ * Sets extra headers on successful responses.
+ *
+ * @param Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
+ * The event to process.
+ */
+ public function onRespond(FilterResponseEvent $event) {
+ $response = $event->getResponse();
+
+ // Set the X-UA-Compatible HTTP header to force IE to use the most recent
+ // rendering engine or use Chrome's frame rendering engine if available.
+ $response->headers->set('X-UA-Compatible', 'IE=edge,chrome=1', false);
+
+ // Set the Content-language header.
+ $response->headers->set('Content-language', drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode);
+
+ // Because pages are highly dynamic, set the last-modified time to now
+ // since the page is in fact being regenerated right now.
+ // @todo Remove this and use a more intelligent default so that HTTP
+ // caching can function properly.
+ $response->headers->set('Last-Modified', gmdate(DATE_RFC1123, REQUEST_TIME));
+
+ // Also give each page a unique ETag. This will force clients to include
+ // both an If-Modified-Since header and an If-None-Match header when doing
+ // conditional requests for the page (required by RFC 2616, section 13.3.4),
+ // making the validation more robust. This is a workaround for a bug in
+ // Mozilla Firefox that is triggered when Drupal's caching is enabled and
+ // the user accesses Drupal via an HTTP proxy (see
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=269303): When an
+ // authenticated user requests a page, and then logs out and requests the
+ // same page again, Firefox may send a conditional request based on the
+ // page that was cached locally when the user was logged in. If this page
+ // did not have an ETag header, the request only contains an
+ // If-Modified-Since header. The date will be recent, because with
+ // authenticated users the Last-Modified header always refers to the time
+ // of the request. If the user accesses Drupal via a proxy server, and the
+ // proxy already has a cached copy of the anonymous page with an older
+ // Last-Modified date, the proxy may respond with 304 Not Modified, making
+ // the client think that the anonymous and authenticated pageviews are
+ // identical.
+ // @todo Remove this line as no longer necessary per
+ // http://drupal.org/node/1573064
+ $response->headers->set('ETag', '"' . REQUEST_TIME . '"');
+
+ // Authenticated users are always given a 'no-cache' header, and will fetch
+ // a fresh page on every request. This prevents authenticated users from
+ // seeing locally cached pages.
+ // @todo Revisit whether or not this is still appropriate now that the
+ // Response object does its own cache control procesisng and we intend to
+ // use partial page caching more extensively.
+ $response->headers->set('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
+ $response->headers->set('Cache-Control', 'no-cache, must-revalidate, post-check=0, pre-check=0');
+ }
+
+ /**
+ * Registers the methods in this class that should be listeners.
+ *
+ * @return array
+ * An array of event listener definitions.
+ */
+ static function getSubscribedEvents() {
+ $events[KernelEvents::RESPONSE][] = array('onRespond');
+ return $events;
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/LegacyControllerSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/LegacyControllerSubscriber.php
new file mode 100644
index 0000000..f088f7e
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/LegacyControllerSubscriber.php
@@ -0,0 +1,62 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\LegacyControllerSubscriber.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Access subscriber for controller requests.
+ */
+class LegacyControllerSubscriber implements EventSubscriberInterface {
+
+ /**
+ * Wraps legacy controllers in a closure to handle old-style arguments.
+ *
+ * This is a backward compatibility layer only. This is a rather ugly way
+ * to piggyback Drupal's existing menu router items onto the Symfony model,
+ * but it works for now. If we did not do this, any menu router item with
+ * a variable number of arguments would fail to work. This bypasses Symfony's
+ * controller argument handling entirely and lets the old-style approach work.
+ *
+ * @todo Convert Drupal to use the IETF-draft-RFC style {placeholders}. That
+ * will allow us to use the native Symfony conversion, including
+ * out-of-order argument mapping, name-based mapping, and with another
+ * listener auto-conversion of parameters to full objects. That may
+ * necessitate not using func_get_args()-based controllers. That is likely
+ * for the best, as those are quite hard to document anyway.
+ *
+ * @param Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
+ * The Event to process.
+ */
+ public function onKernelControllerLegacy(FilterControllerEvent $event) {
+ $router_item = $event->getRequest()->attributes->get('drupal_menu_item');
+ $controller = $event->getController();
+
+ // This BC logic applies only to functions. Otherwise, skip it.
+ if (is_string($controller) && function_exists($controller)) {
+ $new_controller = function() use ($router_item) {
+ return call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
+ };
+ $event->setController($new_controller);
+ }
+ }
+
+ /**
+ * Registers the methods in this class that should be listeners.
+ *
+ * @return array
+ * An array of event listener definitions.
+ */
+ static function getSubscribedEvents() {
+ $events[KernelEvents::CONTROLLER][] = array('onKernelControllerLegacy', 30);
+
+ return $events;
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php
new file mode 100644
index 0000000..242f935
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php
@@ -0,0 +1,61 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\LegacyRequestSubscriber.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * KernelEvents::REQUEST event subscriber to initialize theme and modules.
+ *
+ * @todo Remove this subscriber when all of the code in it has been refactored.
+ */
+class LegacyRequestSubscriber implements EventSubscriberInterface {
+
+ /**
+ * Initializes the rest of the legacy Drupal subsystems.
+ *
+ * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onKernelRequestLegacy(GetResponseEvent $event) {
+ if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
+ // Prior to invoking hook_init(), initialize the theme (potentially a
+ // custom one for this page), so that:
+ // - Modules with hook_init() implementations that call theme() or
+ // theme_get_registry() don't initialize the incorrect theme.
+ // - The theme can have hook_*_alter() implementations affect page
+ // building (e.g., hook_form_alter(), hook_node_view_alter(),
+ // hook_page_alter()), ahead of when rendering starts.
+ menu_set_custom_theme();
+ drupal_theme_initialize();
+ module_invoke_all('init');
+
+ // Tell Drupal it is now fully bootstrapped (for the benefit of code that
+ // calls drupal_get_bootstrap_phase()), but without having
+ // _drupal_bootstrap_full() do anything, since we've already done the
+ // equivalent above and in earlier listeners.
+ _drupal_bootstrap_full(TRUE);
+ drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+ }
+ }
+
+ /**
+ * Registers the methods in this class that should be listeners.
+ *
+ * @return array
+ * An array of event listener definitions.
+ */
+ static function getSubscribedEvents() {
+ $events[KernelEvents::REQUEST][] = array('onKernelRequestLegacy', 90);
+
+ return $events;
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
new file mode 100644
index 0000000..daed1c9
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
@@ -0,0 +1,59 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\MaintenanceModeSubscriber.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Maintenance mode subscriber for controller requests.
+ */
+class MaintenanceModeSubscriber implements EventSubscriberInterface {
+
+ /**
+ * Response with the maintenance page when the site is offline.
+ *
+ * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onKernelRequestMaintenanceModeCheck(GetResponseEvent $event) {
+ // Check if the site is offline.
+ $status = _menu_site_is_offline() ? MENU_SITE_OFFLINE : MENU_SITE_ONLINE;
+
+ // Allow other modules to change the site status but not the path because
+ // that would not change the global variable. hook_url_inbound_alter() can
+ // be used to change the path. Code later will not use the $read_only_path
+ // variable.
+ $read_only_path = !empty($path) ? $path : $event->getRequest()->attributes->get('system_path');
+ drupal_alter('menu_site_status', $status, $read_only_path);
+
+ // Only continue if the site is online.
+ if ($status != MENU_SITE_ONLINE) {
+ // Deliver the 503 page.
+ drupal_maintenance_theme();
+ drupal_set_title(t('Site under maintenance'));
+ $content = theme('maintenance_page', array('content' => filter_xss_admin(variable_get('maintenance_mode_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))))));
+ $response = new Response('Service unavailable', 503);
+ $response->setContent($content);
+ $event->setResponse($response);
+ }
+ }
+
+ /**
+ * Registers the methods in this class that should be listeners.
+ *
+ * @return array
+ * An array of event listener definitions.
+ */
+ static function getSubscribedEvents() {
+ $events[KernelEvents::REQUEST][] = array('onKernelRequestMaintenanceModeCheck', 40);
+ return $events;
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/PathListenerBase.php b/core/lib/Drupal/Core/EventSubscriber/PathListenerBase.php
new file mode 100644
index 0000000..fd0a765
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/PathListenerBase.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\PathListenerBase.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Base class for listeners that are manipulating the path.
+ */
+abstract class PathListenerBase {
+
+ public function extractPath(Request $request) {
+ $path = $request->attributes->get('system_path');
+ return isset($path) ? $path : trim($request->getPathInfo(), '/');
+ }
+
+ public function setPath(Request $request, $path) {
+ $request->attributes->set('system_path', $path);
+
+ // @todo Remove this line once code has been refactored to use the request
+ // object directly.
+ _current_path($path);
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php
new file mode 100644
index 0000000..9104544
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php
@@ -0,0 +1,126 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\PathSubscriber.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Access subscriber for controller requests.
+ */
+class PathSubscriber extends PathListenerBase implements EventSubscriberInterface {
+
+ /**
+ * Resolve the system path.
+ *
+ * @todo The path system should be objectified to remove the function calls in
+ * this method.
+ *
+ * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onKernelRequestPathResolve(GetResponseEvent $event) {
+ $request = $event->getRequest();
+
+ $path = $this->extractPath($request);
+
+ $path = drupal_get_normal_path($path);
+
+ $this->setPath($request, $path);
+ }
+
+ /**
+ * Resolve the front-page default path.
+ *
+ * @todo The path system should be objectified to remove the function calls in
+ * this method.
+ *
+ * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onKernelRequestFrontPageResolve(GetResponseEvent $event) {
+ $request = $event->getRequest();
+ $path = $this->extractPath($request);
+
+ if (empty($path)) {
+ // @todo Temporary hack. Fix when configuration is injectable.
+ $path = variable_get('site_frontpage', 'user');
+ }
+
+ $this->setPath($request, $path);
+ }
+
+ /**
+ * Decode language information embedded in the request path.
+ *
+ * @todo Refactor this entire method to inline the relevant portions of
+ * drupal_language_initialize(). See the inline comment for more details.
+ *
+ * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onKernelRequestLanguageResolve(GetResponseEvent $event) {
+ $request = $event->getRequest();
+ $path = $this->extractPath($request);
+
+ // drupal_language_initialize() combines:
+ // - Determination of language from $request information (e.g., path).
+ // - Determination of language from other information (e.g., site default).
+ // - Population of determined language into drupal_container().
+ // - Removal of language code from _current_path().
+ // @todo Decouple the above, but for now, invoke it and update the path
+ // prior to front page and alias resolution. When above is decoupled, also
+ // add 'langcode' (determined from $request only) to $request->attributes.
+ _current_path($path);
+ drupal_language_initialize();
+ $path = _current_path();
+
+ $this->setPath($request, $path);
+ }
+
+ /**
+ * Decodes the path of the request.
+ *
+ * Parameters in the URL sometimes represent code-meaningful strings. It is
+ * therefore useful to always urldecode() those values so that individual
+ * controllers need not concern themselves with it. This is Drupal-specific
+ * logic and may not be familiar for developers used to other Symfony-family
+ * projects.
+ *
+ * @todo Revisit whether or not this logic is appropriate for here or if
+ * controllers should be required to implement this logic themselves. If we
+ * decide to keep this code, remove this TODO.
+ *
+ * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onKernelRequestDecodePath(GetResponseEvent $event) {
+ $request = $event->getRequest();
+ $path = $this->extractPath($request);
+
+ $path = urldecode($path);
+
+ $this->setPath($request, $path);
+ }
+
+ /**
+ * Registers the methods in this class that should be listeners.
+ *
+ * @return array
+ * An array of event listener definitions.
+ */
+ static function getSubscribedEvents() {
+ $events[KernelEvents::REQUEST][] = array('onKernelRequestDecodePath', 200);
+ $events[KernelEvents::REQUEST][] = array('onKernelRequestLanguageResolve', 150);
+ $events[KernelEvents::REQUEST][] = array('onKernelRequestFrontPageResolve', 101);
+ $events[KernelEvents::REQUEST][] = array('onKernelRequestPathResolve', 100);
+
+ return $events;
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php
new file mode 100644
index 0000000..9b3ef45
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\RequestCloseSubscriber.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\PostResponseEvent;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Subscriber for all responses.
+ */
+class RequestCloseSubscriber implements EventSubscriberInterface {
+
+ /**
+ * Performs end of request tasks.
+ *
+ * @todo The body of this function has just been copied almost verbatim from
+ * drupal_page_footer(). There's probably a lot in here that needs to get
+ * removed/changed.
+ *
+ * @param Symfony\Component\HttpKernel\Event\PostResponseEvent $event
+ * The Event to process.
+ */
+ public function onTerminate(PostResponseEvent $event) {
+ global $user;
+
+ module_invoke_all('exit');
+
+ // Commit the user session, if needed.
+ drupal_session_commit();
+ $response = $event->getResponse();
+ $config = config('system.performance');
+
+ if ($config->get('cache') && ($cache = drupal_page_set_cache())) {
+ drupal_serve_page_from_cache($cache);
+ }
+ else {
+ ob_flush();
+ }
+
+ _registry_check_code(REGISTRY_WRITE_LOOKUP_CACHE);
+ drupal_cache_system_paths();
+ module_implements_write_cache();
+ system_run_automated_cron();
+ }
+
+ /**
+ * Registers the methods in this class that should be listeners.
+ *
+ * @return array
+ * An array of event listener definitions.
+ */
+ static function getSubscribedEvents() {
+ $events[KernelEvents::TERMINATE][] = array('onTerminate');
+
+ return $events;
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/RouterListener.php b/core/lib/Drupal/Core/EventSubscriber/RouterListener.php
new file mode 100644
index 0000000..7b158fd
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/RouterListener.php
@@ -0,0 +1,96 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\RouterListener.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Symfony\Component\HttpKernel\EventListener\RouterListener as SymfonyRouterListener;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
+use Symfony\Component\HttpKernel\Log\LoggerInterface;
+use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
+use Symfony\Component\Routing\Exception\ResourceNotFoundException;
+
+/**
+ * Drupal-specific Router listener.
+ *
+ * This is the bridge from the kernel to the UrlMatcher.
+ */
+class RouterListener extends SymfonyRouterListener {
+
+ /**
+ * 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(UrlMatcherInterface $urlMatcher, LoggerInterface $logger = null) {
+ parent::__construct($urlMatcher, $logger);
+ $this->urlMatcher = $urlMatcher;
+ $this->logger = $logger;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * This method is nearly identical to the parent, except it passes the
+ * $request->attributes->get('system_path') variable to the matcher.
+ * That is where Drupal stores its processed, de-aliased, and sanitized
+ * internal path. We also pass the full request object to the URL Matcher,
+ * since we want attributes to be available to the matcher and to controllers.
+ */
+ public function onKernelRequest(GetResponseEvent $event) {
+ $request = $event->getRequest();
+
+ if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
+ $this->urlMatcher->getContext()->fromRequest($request);
+ $this->urlMatcher->setRequest($request);
+ }
+
+ if ($request->attributes->has('_controller')) {
+ // Routing is already done.
+ return;
+ }
+
+ // Add attributes based on the path info (routing).
+ try {
+ $parameters = $this->urlMatcher->match($request->attributes->get('system_path'));
+
+ if (null !== $this->logger) {
+ $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters)));
+ }
+
+ $request->attributes->add($parameters);
+ unset($parameters['_route']);
+ unset($parameters['_controller']);
+ $request->attributes->set('_route_params', $parameters);
+ }
+ catch (ResourceNotFoundException $e) {
+ $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
+
+ throw new NotFoundHttpException($message, $e);
+ }
+ catch (MethodNotAllowedException $e) {
+ $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
+
+ throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
+ }
+ }
+}
diff --git a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php
new file mode 100644
index 0000000..120ac7b
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php
@@ -0,0 +1,128 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\EventSubscriber\ViewSubscriber.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+use Drupal\Core\ContentNegotiation;
+
+/**
+ * Main subscriber for VIEW HTTP responses.
+ *
+ * @todo This needs to get refactored to be extensible so that we can handle
+ * more than just Html and Drupal-specific JSON requests. See
+ * http://drupal.org/node/1594870
+ */
+class ViewSubscriber implements EventSubscriberInterface {
+
+ protected $negotiation;
+
+ public function __construct(ContentNegotiation $negotiation) {
+ $this->negotiation = $negotiation;
+ }
+
+ /**
+ * Processes a successful controller into an HTTP 200 response.
+ *
+ * Some controllers may not return a response object but simply the body of
+ * one. The VIEW event is called in that case, to allow us to mutate that
+ * body into a Response object. In particular we assume that the return
+ * from an JSON-type response is a JSON string, so just wrap it into a
+ * Response object.
+ *
+ * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onView(GetResponseEvent $event) {
+
+ $request = $event->getRequest();
+
+ $method = 'on' . $this->negotiation->getContentType($request);
+
+ if (method_exists($this, $method)) {
+ $event->setResponse($this->$method($event));
+ }
+ else {
+ $event->setResponse(new Response('Unsupported Media Type', 415));
+ }
+ }
+
+ public function onJson(GetResponseEvent $event) {
+ $page_callback_result = $event->getControllerResult();
+
+ $response = new JsonResponse();
+ $response->setContent($page_callback_result);
+
+ return $response;
+ }
+
+ public function onAjax(GetResponseEvent $event) {
+ $page_callback_result = $event->getControllerResult();
+
+ // Construct the response content from the page callback result.
+ $commands = ajax_prepare_response($page_callback_result);
+ $json = ajax_render($commands);
+
+ // Build the actual response object.
+ $response = new JsonResponse();
+ $response->setContent($json);
+
+ return $response;
+ }
+
+ public function onIframeUpload(GetResponseEvent $event) {
+ $page_callback_result = $event->getControllerResult();
+
+ // Construct the response content from the page callback result.
+ $commands = ajax_prepare_response($page_callback_result);
+ $json = ajax_render($commands);
+
+ // Browser IFRAMEs expect HTML. Browser extensions, such as Linkification
+ // and Skype's Browser Highlighter, convert URLs, phone numbers, etc. into
+ // links. This corrupts the JSON response. Protect the integrity of the
+ // JSON data by making it the value of a textarea.
+ // @see http://malsup.com/jquery/form/#file-upload
+ // @see http://drupal.org/node/1009382
+ $html = '<textarea>' . $json . '</textarea>';
+
+ return new Response($html);
+ }
+
+ /**
+ * Processes a successful controller into an HTTP 200 response.
+ *
+ * Some controllers may not return a response object but simply the body of
+ * one. The VIEW event is called in that case, to allow us to mutate that
+ * body into a Response object. In particular we assume that the return from
+ * an HTML-type response is a render array from a legacy page callback and
+ * render it.
+ *
+ * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onHtml(GetResponseEvent $event) {
+ $page_callback_result = $event->getControllerResult();
+ return new Response(drupal_render_page($page_callback_result));
+ }
+
+ /**
+ * Registers the methods in this class that should be listeners.
+ *
+ * @return array
+ * An array of event listener definitions.
+ */
+ static function getSubscribedEvents() {
+ $events[KernelEvents::VIEW][] = array('onView');
+
+ return $events;
+ }
+}
diff --git a/core/lib/Drupal/Core/ExceptionController.php b/core/lib/Drupal/Core/ExceptionController.php
new file mode 100644
index 0000000..b163395
--- /dev/null
+++ b/core/lib/Drupal/Core/ExceptionController.php
@@ -0,0 +1,406 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\ExceptionController.
+ */
+
+namespace Drupal\Core;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Symfony\Component\HttpKernel\Exception\FlattenException;
+
+/**
+ * This controller handles HTTP errors generated by the routing system.
+ */
+class ExceptionController {
+
+ /**
+ * The kernel that spawned this controller.
+ *
+ * We will use this to fire subrequests as needed.
+ *
+ * @var Symfony\Component\HttpKernel\HttpKernelInterface
+ */
+ protected $kernel;
+
+ /**
+ * The content negotiation library.
+ *
+ * @var Drupal\Core\ContentNegotiation
+ */
+ protected $negotiation;
+
+ /**
+ * Constructor.
+ *
+ * @param Symfony\Component\HttpKernel\HttpKernelInterface $kernel
+ * The kernel that spawned this controller, so that it can be reused
+ * for subrequests.
+ * @param Drupal\Core\ContentNegotiation $negotiation
+ * The content negotiation library to use to determine the correct response
+ * format.
+ */
+ public function __construct(HttpKernelInterface $kernel, ContentNegotiation $negotiation) {
+ $this->kernel = $kernel;
+ $this->negotiation = $negotiation;
+ }
+
+ /**
+ * Handles an exception on a request.
+ *
+ * @param Symfony\Component\HttpKernel\Exception\FlattenException $exception
+ * The flattened exception.
+ * @param Symfony\Component\HttpFoundation\Request $request
+ * The request that generated the exception.
+ *
+ * @return Symfony\Component\HttpFoundation\Response
+ * A response object to be sent to the server.
+ */
+ public function execute(FlattenException $exception, Request $request) {
+ $method = 'on' . $exception->getStatusCode() . $this->negotiation->getContentType($request);
+
+ if (method_exists($this, $method)) {
+ return $this->$method($exception, $request);
+ }
+
+ return new Response('A fatal error occurred: ' . $exception->getMessage(), $exception->getStatusCode());
+ }
+
+ /**
+ * Processes a MethodNotAllowed exception into an HTTP 405 response.
+ *
+ * @param Symfony\Component\HttpKernel\Exception\FlattenException $exception
+ * The flattened exception.
+ * @param Symfony\Component\HttpFoundation\Request $request
+ * The request object that triggered this exception.
+ */
+ public function on405Html(FlattenException $exception, Request $request) {
+ $event->setResponse(new Response('Method Not Allowed', 405));
+ }
+
+ /**
+ * Processes an AccessDenied exception into an HTTP 403 response.
+ *
+ * @param Symfony\Component\HttpKernel\Exception\FlattenException $exception
+ * The flattened exception.
+ * @param Symfony\Component\HttpFoundation\Request $request
+ * The request object that triggered this exception.
+ */
+ public function on403Html(FlattenException $exception, Request $request) {
+ $system_path = $request->attributes->get('system_path');
+ watchdog('access denied', $system_path, NULL, WATCHDOG_WARNING);
+
+ $path = drupal_get_normal_path(variable_get('site_403', ''));
+ if ($path && $path != $system_path) {
+ // Keep old path for reference, and to allow forms to redirect to it.
+ if (!isset($_GET['destination'])) {
+ $_GET['destination'] = $system_path;
+ }
+
+ $subrequest = Request::create('/' . $path, 'get', array('destination' => $system_path), $request->cookies->all(), array(), $request->server->all());
+
+ // The active trail is being statically cached from the parent request to
+ // the subrequest, like any other static. Unfortunately that means the
+ // data in it is incorrect and does not get regenerated correctly for
+ // the subrequest. In this instance, that even causes a fatal error in
+ // some circumstances because menu_get_active_trail() ends up having
+ // a missing localized_options value. To work around that, reset the
+ // menu static variables and let them be regenerated as needed.
+ // @todo It is likely that there are other such statics that need to be
+ // reset that are not triggering test failures right now. If found,
+ // add them here.
+ // @todo Refactor the breadcrumb system so that it does not rely on static
+ // variables in the first place, which will eliminate the need for this
+ // hack.
+ drupal_static_reset('menu_set_active_trail');
+ menu_reset_static_cache();
+
+ $response = $this->kernel->handle($subrequest, DrupalKernel::SUB_REQUEST);
+ $response->setStatusCode(403, 'Access denied');
+ }
+ else {
+ $response = new Response('Access Denied', 403);
+
+ // @todo Replace this block with something cleaner.
+ $return = t('You are not authorized to access this page.');
+ drupal_set_title(t('Access denied'));
+ drupal_set_page_content($return);
+ $page = element_info('page');
+ $content = drupal_render_page($page);
+
+ $response->setContent($content);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Processes a NotFound exception into an HTTP 404 response.
+ *
+ * @param Symfony\Component\HttpKernel\Exception\FlattenException $exception
+ * The flattened exception.
+ * @param Sonfony\Component\HttpFoundation\Request $request
+ * The request object that triggered this exception.
+ */
+ public function on404Html(FlattenException $exception, Request $request) {
+ watchdog('page not found', check_plain($request->attributes->get('system_path')), NULL, WATCHDOG_WARNING);
+
+ // Check for and return a fast 404 page if configured.
+ // @todo Inline this rather than using a function.
+ drupal_fast_404();
+
+ $system_path = $request->attributes->get('system_path');
+
+ // Keep old path for reference, and to allow forms to redirect to it.
+ if (!isset($_GET['destination'])) {
+ $_GET['destination'] = $system_path;
+ }
+
+ $path = drupal_get_normal_path(variable_get('site_404', ''));
+ if ($path && $path != $system_path) {
+ // @todo Um, how do I specify an override URL again? Totally not clear. Do
+ // that and sub-call the kernel rather than using meah().
+ // @todo The create() method expects a slash-prefixed path, but we store a
+ // normal system path in the site_404 variable.
+ $subrequest = Request::create('/' . $path, 'get', array(), $request->cookies->all(), array(), $request->server->all());
+
+ // The active trail is being statically cached from the parent request to
+ // the subrequest, like any other static. Unfortunately that means the
+ // data in it is incorrect and does not get regenerated correctly for
+ // the subrequest. In this instance, that even causes a fatal error in
+ // some circumstances because menu_get_active_trail() ends up having
+ // a missing localized_options value. To work around that, reset the
+ // menu static variables and let them be regenerated as needed.
+ // @todo It is likely that there are other such statics that need to be
+ // reset that are not triggering test failures right now. If found,
+ // add them here.
+ // @todo Refactor the breadcrumb system so that it does not rely on static
+ // variables in the first place, which will eliminate the need for this
+ // hack.
+ drupal_static_reset('menu_set_active_trail');
+ menu_reset_static_cache();
+
+ $response = $this->kernel->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
+ $response->setStatusCode(404, 'Not Found');
+ }
+ else {
+ $response = new Response('Not Found', 404);
+
+ // @todo Replace this block with something cleaner.
+ $return = t('The requested page "@path" could not be found.', array('@path' => $request->getPathInfo()));
+ drupal_set_title(t('Page not found'));
+ drupal_set_page_content($return);
+ $page = element_info('page');
+ $content = drupal_render_page($page);
+
+ $response->setContent($content);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Processes a generic exception into an HTTP 500 response.
+ *
+ * @param Symfony\Component\HttpKernel\Exception\FlattenException $exception
+ * Metadata about the exception that was thrown.
+ * @param Symfony\Component\HttpFoundation\Request $request
+ * The request object that triggered this exception.
+ */
+ public function on500Html(FlattenException $exception, Request $request) {
+ $error = $this->decodeException($exception);
+
+ // Because the kernel doesn't run until full bootstrap, we know that
+ // most subsystems are already initialized.
+
+ $headers = array();
+
+ // When running inside the testing framework, we relay the errors
+ // to the tested site by the way of HTTP headers.
+ $test_info = &$GLOBALS['drupal_test_info'];
+ if (!empty($test_info['in_child_site']) && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) {
+ // $number does not use drupal_static as it should not be reset
+ // as it uniquely identifies each PHP error.
+ static $number = 0;
+ $assertion = array(
+ $error['!message'],
+ $error['%type'],
+ array(
+ 'function' => $error['%function'],
+ 'file' => $error['%file'],
+ 'line' => $error['%line'],
+ ),
+ );
+ $headers['X-Drupal-Assertion-' . $number] = rawurlencode(serialize($assertion));
+ $number++;
+ }
+
+ watchdog('php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);
+
+ // Display the message if the current error reporting level allows this type
+ // of message to be displayed, and unconditionnaly in update.php.
+ if (error_displayable($error)) {
+ $class = 'error';
+
+ // If error type is 'User notice' then treat it as debug information
+ // instead of an error message, see dd().
+ if ($error['%type'] == 'User notice') {
+ $error['%type'] = 'Debug';
+ $class = 'status';
+ }
+
+ drupal_set_message(t('%type: !message in %function (line %line of %file).', $error), $class);
+ }
+
+ drupal_set_title(t('Error'));
+ // We fallback to a maintenance page at this point, because the page
+ // generation itself can generate errors.
+ $output = theme('maintenance_page', array('content' => t('The website encountered an unexpected error. Please try again later.')));
+
+ $response = new Response($output, 500);
+ $response->setStatusCode(500, '500 Service unavailable (with message)');
+
+ return $response;
+ }
+
+ /**
+ * Processes an AccessDenied exception that occured on a JSON request.
+ *
+ * @param Symfony\Component\HttpKernel\Exception\FlattenException $exception
+ * The flattened exception.
+ * @param Symfony\Component\HttpFoundation\Request $request
+ * The request object that triggered this exception.
+ */
+ public function on403Json(FlattenException $exception, Request $request) {
+ $response = new JsonResponse();
+ $response->setStatusCode(403, 'Access Denied');
+ return $response;
+ }
+
+ /**
+ * Processes a NotFound exception that occured on a JSON request.
+ *
+ * @param Symfony\Component\HttpKernel\Exception\FlattenException $exception
+ * The flattened exception.
+ * @param Symfony\Component\HttpFoundation\Request $request
+ * The request object that triggered this exception.
+ */
+ public function on404Json(FlattenException $exception, Request $request) {
+ $response = new JsonResponse();
+ $response->setStatusCode(404, 'Not Found');
+ return $response;
+ }
+
+ /**
+ * Processes a MethodNotAllowed exception that occured on a JSON request.
+ *
+ * @param Symfony\Component\HttpKernel\Exception\FlattenException $exception
+ * The flattened exception.
+ * @param Symfony\Component\HttpFoundation\Request $request
+ * The request object that triggered this exception.
+ */
+ public function on405Json(FlattenException $exception, Request $request) {
+ $response = new JsonResponse();
+ $response->setStatusCode(405, 'Method Not Allowed');
+ return $response;
+ }
+
+
+ /**
+ * This method is a temporary port of _drupal_decode_exception().
+ *
+ * @todo This should get refactored. FlattenException could use some
+ * improvement as well.
+ *
+ * @return array
+ */
+ protected function decodeException(FlattenException $exception) {
+ $message = $exception->getMessage();
+
+ $backtrace = $exception->getTrace();
+
+ // This value is missing from the stack for some reason in the
+ // FlattenException version of the backtrace.
+ $backtrace[0]['line'] = $exception->getLine();
+
+ // For database errors, we try to return the initial caller,
+ // skipping internal functions of the database layer.
+ if (strpos($exception->getClass(), 'DatabaseExceptionWrapper') !== FALSE) {
+ // A DatabaseExceptionWrapper exception is actually just a courier for
+ // the original PDOException. It's the stack trace from that exception
+ // that we care about.
+ $backtrace = $exception->getPrevious()->getTrace();
+ $backtrace[0]['line'] = $exception->getLine();
+
+ // The first element in the stack is the call, the second element gives us the caller.
+ // We skip calls that occurred in one of the classes of the database layer
+ // or in one of its global functions.
+ $db_functions = array('db_query', 'db_query_range');
+ while (!empty($backtrace[1]) && ($caller = $backtrace[1]) &&
+ ((strpos($caller['namespace'], 'Drupal\Core\Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE)) ||
+ in_array($caller['function'], $db_functions)) {
+ // We remove that call.
+ array_shift($backtrace);
+ }
+ }
+ $caller = $this->getLastCaller($backtrace);
+
+ return array(
+ '%type' => $exception->getClass(),
+ // The standard PHP exception handler considers that the exception message
+ // is plain-text. We mimick this behavior here.
+ '!message' => check_plain($message),
+ '%function' => $caller['function'],
+ '%file' => $caller['file'],
+ '%line' => $caller['line'],
+ 'severity_level' => WATCHDOG_ERROR,
+ );
+ }
+
+ /**
+ * Gets the last caller from a backtrace.
+ *
+ * The last caller is not necessarily the first item in the backtrace. Rather,
+ * it is the first item in the backtrace that is a PHP userspace function,
+ * and not one of our debug functions.
+ *
+ * @param $backtrace
+ * A standard PHP backtrace.
+ *
+ * @return
+ * An associative array with keys 'file', 'line' and 'function'.
+ */
+ protected function getLastCaller($backtrace) {
+ // Ignore black listed error handling functions.
+ $blacklist = array('debug', '_drupal_error_handler', '_drupal_exception_handler');
+
+ // Errors that occur inside PHP internal functions do not generate
+ // information about file and line.
+ while (($backtrace && !isset($backtrace[0]['line'])) ||
+ (isset($backtrace[1]['function']) && in_array($backtrace[1]['function'], $blacklist))) {
+ array_shift($backtrace);
+ }
+
+ // The first trace is the call itself.
+ // It gives us the line and the file of the last call.
+ $call = $backtrace[0];
+
+ // The second call give us the function where the call originated.
+ if (isset($backtrace[1])) {
+ if (isset($backtrace[1]['class'])) {
+ $call['function'] = $backtrace[1]['class'] . $backtrace[1]['type'] . $backtrace[1]['function'] . '()';
+ }
+ else {
+ $call['function'] = $backtrace[1]['function'] . '()';
+ }
+ }
+ else {
+ $call['function'] = 'main()';
+ }
+ return $call;
+ }
+}
diff --git a/core/lib/Drupal/Core/LegacyUrlMatcher.php b/core/lib/Drupal/Core/LegacyUrlMatcher.php
new file mode 100644
index 0000000..8828f36
--- /dev/null
+++ b/core/lib/Drupal/Core/LegacyUrlMatcher.php
@@ -0,0 +1,164 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\LegacyUrlMatcher.
+ */
+
+namespace Drupal\Core;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Routing\Exception\ResourceNotFoundException;
+use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
+use Symfony\Component\Routing\RequestContext;
+
+/**
+ * UrlMatcher matches URL based on a set of routes.
+ */
+class LegacyUrlMatcher implements UrlMatcherInterface {
+
+ /**
+ * The request context for this matcher.
+ *
+ * @var Symfony\Component\Routing\RequestContext
+ */
+ protected $context;
+
+ /**
+ * The request object for this matcher.
+ *
+ * @var Symfony\Component\HttpFoundation\Request
+ */
+ protected $request;
+
+ /**
+ * Constructor.
+ */
+ public function __construct() {
+ // We will not actually use this object, but it's needed to conform to
+ // the interface.
+ $this->context = new RequestContext();
+ }
+
+ /**
+ * Sets the request context.
+ *
+ * This method is just to satisfy the interface, and is largely vestigial.
+ * The request context object does not contain the information we need, so
+ * we will use the original request object.
+ *
+ * @param Symfony\Component\Routing\RequestContext $context
+ * The context.
+ *
+ * @api
+ */
+ public function setContext(RequestContext $context) {
+ $this->context = $context;
+ }
+
+ /**
+ * Gets the request context.
+ *
+ * This method is just to satisfy the interface, and is largely vestigial.
+ * The request context object does not contain the information we need, so
+ * we will use the original request object.
+ *
+ * @return Symfony\Component\Routing\RequestContext
+ * The context.
+ */
+ public function getContext() {
+ return $this->context;
+ }
+
+ /**
+ * Sets the request object to use.
+ *
+ * This is used by the RouterListener to make additional request attributes
+ * available.
+ *
+ * @param Symfony\Component\HttpFoundation\Request $request
+ * The request object.
+ */
+ public function setRequest(Request $request) {
+ $this->request = $request;
+ }
+
+ /**
+ * Gets the request object.
+ *
+ * @return Symfony\Component\HttpFoundation\Request $request
+ * The request object.
+ */
+ public function getRequest() {
+ return $this->request;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @api
+ */
+ public function match($pathinfo) {
+ if ($router_item = $this->matchDrupalItem($pathinfo)) {
+ $ret = $this->convertDrupalItem($router_item);
+ // Stash the router item in the attributes while we're transitioning.
+ $ret['drupal_menu_item'] = $router_item;
+
+ // Most legacy controllers (aka page callbacks) are in a separate file,
+ // so we have to include that.
+ if ($router_item['include_file']) {
+ require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
+ }
+
+ return $ret;
+ }
+
+ // This matcher doesn't differentiate by method, so don't bother with those
+ // exceptions.
+ throw new ResourceNotFoundException();
+ }
+
+ /**
+ * Get a Drupal menu item.
+ *
+ * @todo Make this return multiple possible candidates for the resolver to
+ * consider.
+ *
+ * @param string $path
+ * The path being looked up by
+ */
+ protected function matchDrupalItem($path) {
+ // For now we can just proxy our procedural method. At some point this will
+ // become more complicated because we'll need to get back candidates for a
+ // path and them resolve them based on things like method and scheme which
+ // we currently can't do.
+ return menu_get_item($path);
+ }
+
+ /**
+ * Converts a Drupal menu item to a route array.
+ *
+ * @param array $router_item
+ * The Drupal menu item.
+ *
+ * @return
+ * An array of parameters.
+ */
+ protected function convertDrupalItem($router_item) {
+ $route = array(
+ '_controller' => $router_item['page_callback']
+ );
+
+ // @todo menu_get_item() does not unserialize page arguments when the access
+ // is denied. Remove this temporary hack that always does that.
+ if (!is_array($router_item['page_arguments'])) {
+ $router_item['page_arguments'] = unserialize($router_item['page_arguments']);
+ }
+
+ // Place argument defaults on the route.
+ foreach ($router_item['page_arguments'] as $k => $v) {
+ $route[$k] = $v;
+ }
+ return $route;
+ }
+}
diff --git a/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php b/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
index 6971d9f..d877dba 100644
--- a/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
+++ b/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
@@ -7,7 +7,7 @@
namespace Drupal\Core\Lock;
-use PDOException;
+use Drupal\Core\Database\DatabaseExceptionWrapper;
/**
* Defines the database lock backend. This is the default backend in Drupal.
@@ -53,7 +53,7 @@ class DatabaseLockBackend extends LockBackendAbstract {
// We never need to try again.
$retry = FALSE;
}
- catch (PDOException $e) {
+ catch (DatabaseExceptionWrapper $e) {
// Suppress the error. If this is our first pass through the loop,
// then $retry is FALSE. In this case, the insert must have failed
// meaning some other request acquired the lock but did not release it.
diff --git a/core/modules/aggregator/aggregator.admin.inc b/core/modules/aggregator/aggregator.admin.inc
index 9e5546f..c064e4f 100644
--- a/core/modules/aggregator/aggregator.admin.inc
+++ b/core/modules/aggregator/aggregator.admin.inc
@@ -406,9 +406,14 @@ function _aggregator_parse_opml($opml) {
* @see aggregator_menu()
*/
function aggregator_admin_refresh_feed($feed) {
- if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'aggregator/update/' . $feed->fid)) {
- return MENU_ACCESS_DENIED;
+ // @todo CSRF tokens are validated in page callbacks rather than access
+ // callbacks, because access callbacks are also invoked during menu link
+ // generation. Add token support to routing: http://drupal.org/node/755584.
+ $token = request()->query->get('token');
+ if (!isset($token) || !drupal_valid_token($token, 'aggregator/update/' . $feed->fid)) {
+ drupal_access_denied();
}
+
aggregator_refresh($feed);
drupal_goto('admin/config/services/aggregator');
}
diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc
index ccc307e..9eabe13 100644
--- a/core/modules/comment/comment.admin.inc
+++ b/core/modules/comment/comment.admin.inc
@@ -260,7 +260,7 @@ function comment_confirm_delete_page($cid) {
if ($comment = comment_load($cid)) {
return drupal_get_form('comment_confirm_delete', $comment);
}
- return MENU_NOT_FOUND;
+ drupal_not_found();
}
/**
diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc
index 0832eff..2986d13 100644
--- a/core/modules/comment/comment.pages.inc
+++ b/core/modules/comment/comment.pages.inc
@@ -107,9 +107,14 @@ function comment_reply(Node $node, $pid = NULL) {
* @see comment_menu()
*/
function comment_approve($cid) {
- if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], "comment/$cid/approve")) {
- return MENU_ACCESS_DENIED;
+ // @todo CSRF tokens are validated in page callbacks rather than access
+ // callbacks, because access callbacks are also invoked during menu link
+ // generation. Add token support to routing: http://drupal.org/node/755584.
+ $token = request()->query->get('token');
+ if (!isset($token) || !drupal_valid_token($token, "comment/$cid/approve")) {
+ drupal_access_denied();
}
+
if ($comment = comment_load($cid)) {
$comment->status = COMMENT_PUBLISHED;
comment_save($comment);
@@ -117,5 +122,5 @@ function comment_approve($cid) {
drupal_set_message(t('Comment approved.'));
drupal_goto('node/' . $comment->nid);
}
- return MENU_NOT_FOUND;
+ drupal_not_found();
}
diff --git a/core/modules/image/image.module b/core/modules/image/image.module
index 3edf83c..9d94ac2 100644
--- a/core/modules/image/image.module
+++ b/core/modules/image/image.module
@@ -5,6 +5,9 @@
* Exposes global functionality for creating image styles.
*/
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\StreamedResponse;
+
/**
* Image style constant for user presets in the database.
*/
@@ -726,13 +729,16 @@ function image_style_deliver($style, $scheme) {
if ($success) {
$image = image_load($derivative_uri);
- file_transfer($image->source, array('Content-Type' => $image->info['mime_type'], 'Content-Length' => $image->info['file_size']));
+ $uri = $image->source;
+ $headers = array(
+ 'Content-Type' => $image->info['mime_type'],
+ 'Content-Length' => $image->info['file_size'],
+ );
+ return file_transfer($uri, $headers);
}
else {
watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' => $derivative_uri));
- drupal_add_http_header('Status', '500 Internal Server Error');
- print t('Error generating image.');
- drupal_exit();
+ return new Response(t('Error generating image.'), 500);
}
}
diff --git a/core/modules/image/image.test b/core/modules/image/image.test
index f9a4ec1..0752c44 100644
--- a/core/modules/image/image.test
+++ b/core/modules/image/image.test
@@ -658,7 +658,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
// sent by Drupal.
$this->assertEqual($this->drupalGetHeader('Content-Type'), 'image/png; name="' . $test_image->filename . '"', t('Content-Type header was sent.'));
$this->assertEqual($this->drupalGetHeader('Content-Disposition'), 'inline; filename="' . $test_image->filename . '"', t('Content-Disposition header was sent.'));
- $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'private', t('Cache-Control header was sent.'));
+ $this->assertTrue(strstr($this->drupalGetHeader('Cache-Control'),'private') !== FALSE, t('Cache-Control header was sent.'));
// Log out and try to access the file.
$this->drupalLogout();
diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeFeedTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeFeedTest.php
index 29878fa..ca660e4 100644
--- a/core/modules/node/lib/Drupal/node/Tests/NodeFeedTest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/NodeFeedTest.php
@@ -25,10 +25,7 @@ class NodeFeedTest extends WebTestBase {
* Ensure that node_feed accepts and prints extra channel elements.
*/
function testNodeFeedExtraChannelElements() {
- ob_start();
- node_feed(array(), array('copyright' => 'Drupal is a registered trademark of Dries Buytaert.'));
- $output = ob_get_clean();
-
- $this->assertTrue(strpos($output, '<copyright>Drupal is a registered trademark of Dries Buytaert.</copyright>') !== FALSE);
+ $response = node_feed(array(), array('copyright' => 'Drupal is a registered trademark of Dries Buytaert.'));
+ $this->assertTrue(strpos($response->getContent(), '<copyright>Drupal is a registered trademark of Dries Buytaert.</copyright>') !== FALSE);
}
}
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index 11c05cc..d2d4bad 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -1,10 +1,5 @@
<?php
-use Drupal\Core\Database\Query\AlterableInterface;
-use Drupal\Core\Database\Query\SelectExtender;
-use Drupal\Core\Database\Query\SelectInterface;
-use Drupal\node\Node;
-
/**
* @file
* The core module that allows content to be submitted to the site.
@@ -13,6 +8,13 @@ use Drupal\node\Node;
* API pattern.
*/
+use Symfony\Component\HttpFoundation\Response;
+
+use Drupal\Core\Database\Query\AlterableInterface;
+use Drupal\Core\Database\Query\SelectExtender;
+use Drupal\Core\Database\Query\SelectInterface;
+use Drupal\node\Node;
+
/**
* Denotes that the node is not published.
*/
@@ -2442,8 +2444,7 @@ function node_feed($nids = FALSE, $channel = array()) {
$output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language'], $channel_extras);
$output .= "</rss>\n";
- drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
- print $output;
+ return new Response($output, 200, array('Content-Type' => 'application/rss+xml; charset=utf-8'));
}
/**
diff --git a/core/modules/openid/tests/openid_test.module b/core/modules/openid/tests/openid_test.module
index ac49dbd..4481818 100644
--- a/core/modules/openid/tests/openid_test.module
+++ b/core/modules/openid/tests/openid_test.module
@@ -20,6 +20,9 @@
* key is used for verifying the signed messages from the provider.
*/
+use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Response;
+
/**
* Implements hook_menu().
*/
@@ -97,8 +100,7 @@ function openid_test_yadis_xrds() {
if (arg(3) == 'xri' && (arg(4) != '@example*résumé;%25' || $_GET['_xrd_r'] != 'application/xrds xml')) {
drupal_not_found();
}
- drupal_add_http_header('Content-Type', 'application/xrds+xml');
- print '<?xml version="1.0" encoding="UTF-8"?>
+ $output = '<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)" xmlns:openid="http://openid.net/xmlns/1.0">
<XRD>
<Status cid="' . check_plain(variable_get('openid_test_canonical_id_status', 'verified')) . '"/>
@@ -127,7 +129,7 @@ function openid_test_yadis_xrds() {
</Service>
';
if (arg(3) == 'server') {
- print '
+ $output .= '
<Service>
<Type>http://specs.openid.net/auth/2.0/server</Type>
<URI>http://example.com/this-has-too-low-priority</URI>
@@ -138,7 +140,7 @@ function openid_test_yadis_xrds() {
</Service>';
}
elseif (arg(3) == 'delegate') {
- print '
+ $output .= '
<Service priority="0">
<Type>http://specs.openid.net/auth/2.0/signon</Type>
<Type>http://openid.net/srv/ax/1.0</Type>
@@ -146,9 +148,10 @@ function openid_test_yadis_xrds() {
<openid:Delegate>http://example.com/xrds-delegate</openid:Delegate>
</Service>';
}
- print '
+ $output .= '
</XRD>
</xrds:XRDS>';
+ return new Response($output, 200, array('Content-type' => 'application/xrds+xml; charset=utf-8'));
}
else {
return t('This is a regular HTML page. If the client sends an Accept: application/xrds+xml header when requesting this URL, an XRDS document is returned.');
@@ -207,11 +210,9 @@ function openid_test_html_openid2() {
function openid_test_endpoint() {
switch ($_REQUEST['openid_mode']) {
case 'associate':
- _openid_test_endpoint_associate();
- break;
+ return _openid_test_endpoint_associate();
case 'checkid_setup':
- _openid_test_endpoint_authenticate();
- break;
+ return _openid_test_endpoint_authenticate();
}
}
@@ -226,8 +227,7 @@ function openid_test_redirect($count = 0) {
$url = url('openid-test/redirect/' . --$count, array('absolute' => TRUE));
}
$http_response_code = variable_get('openid_test_redirect_http_reponse_code', 301);
- header('Location: ' . $url, TRUE, $http_response_code);
- exit();
+ return new RedirectResponse($url, $http_response_code);
}
/**
@@ -283,8 +283,7 @@ function _openid_test_endpoint_associate() {
// Respond to Relying Party in the special Key-Value Form Encoding (see OpenID
// Authentication 1.0, section 4.1.1).
- drupal_add_http_header('Content-Type', 'text/plain');
- print _openid_create_message($response);
+ return new Response(_openid_create_message($response), 200, array('Content-Type' => 'text/plain'));
}
/**
@@ -306,9 +305,7 @@ function _openid_test_endpoint_authenticate() {
'openid.mode' => 'error',
'openid.error' => 'Unexpted identity',
);
- drupal_add_http_header('Content-Type', 'text/plain');
- header('Location: ' . url($_REQUEST['openid_return_to'], array('query' => $response, 'external' => TRUE)));
- return;
+ return new RedirectResponse(url($_REQUEST['openid_return_to'], array('query' => $response, 'external' => TRUE)));
}
// Generate unique identifier for this authentication.
@@ -348,8 +345,7 @@ function _openid_test_endpoint_authenticate() {
// Put the signed message into the query string of a URL supplied by the
// Relying Party, and redirect the user.
- drupal_add_http_header('Content-Type', 'text/plain');
- header('Location: ' . url($_REQUEST['openid_return_to'], array('query' => $response, 'external' => TRUE)));
+ return new RedirectResponse(url($_REQUEST['openid_return_to'], array('query' => $response, 'external', TRUE)));
}
/**
diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module
index 02c0883..5fdd453 100644
--- a/core/modules/overlay/overlay.module
+++ b/core/modules/overlay/overlay.module
@@ -5,6 +5,8 @@
* Displays the Drupal administration interface in an overlay.
*/
+use Symfony\Component\HttpFoundation\Response;
+
/**
* Implements hook_help().
*/
@@ -19,7 +21,7 @@ function overlay_help($path, $arg) {
}
/**
- * Implements hook_menu().
+ * Implements hook_menu()
*/
function overlay_menu() {
$items['overlay-ajax/%'] = array(
@@ -32,7 +34,7 @@ function overlay_menu() {
$items['overlay/dismiss-message'] = array(
'title' => '',
'page callback' => 'overlay_user_dismiss_message',
- 'access arguments' => array('access overlay'),
+ 'access callback' => 'overlay_user_dismiss_message_access',
'type' => MENU_CALLBACK,
);
return $items;
@@ -299,25 +301,48 @@ function overlay_page_alter(&$page) {
}
/**
- * Menu callback; dismisses the overlay accessibility message for this user.
+ * Access callback; determines access to dismiss the overlay accessibility message.
+ *
+ * @see overlay_user_dismiss_message()
+ * @see overlay_menu()
*/
-function overlay_user_dismiss_message() {
+function overlay_user_dismiss_message_access() {
global $user;
+ if (!user_access('access overlay')) {
+ return FALSE;
+ }
// It's unlikely, but possible that "access overlay" permission is granted to
// the anonymous role. In this case, we do not display the message to disable
- // the overlay, so there is nothing to dismiss. Also, protect against
- // cross-site request forgeries by validating a token.
- if (empty($user->uid) || !isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'overlay')) {
- return MENU_ACCESS_DENIED;
+ // the overlay, so there is nothing to dismiss.
+ if (empty($user->uid)) {
+ return FALSE;
}
- else {
- $account = user_load($user->uid);
- $account->data['overlay_message_dismissed'] = 1;
- $account->save();
- drupal_set_message(t('The message has been dismissed. You can change your overlay settings at any time by visiting your profile page.'));
- // Destination is normally given. Go to the user profile as a fallback.
- drupal_goto('user/' . $user->uid . '/edit');
+ return TRUE;
+}
+
+/**
+ * Menu callback; dismisses the overlay accessibility message for this user.
+ *
+ * @see overlay_user_dismiss_message_access()
+ * @see overlay_menu()
+ */
+function overlay_user_dismiss_message() {
+ global $user;
+
+ // @todo CSRF tokens are validated in page callbacks rather than access
+ // callbacks, because access callbacks are also invoked during menu link
+ // generation. Add token support to routing: http://drupal.org/node/755584.
+ $token = request()->query->get('token');
+ if (!isset($token) || !drupal_valid_token($token, 'overlay')) {
+ drupal_access_denied();
}
+
+ $account = user_load($user->uid);
+ $account->data['overlay_message_dismissed'] = 1;
+ $account->save();
+ drupal_set_message(t('The message has been dismissed. You can change your overlay settings at any time by visiting your profile page.'));
+ // Destination is normally given. Go to the user profile as a fallback.
+ drupal_goto('user/' . $user->uid . '/edit');
}
/**
@@ -667,7 +692,8 @@ function overlay_overlay_child_initialize() {
// it to the same content rendered in overlay_exit(), at the end of the page
// request. This allows us to check if anything actually did change, and, if
// so, trigger an immediate Ajax refresh of the parent window.
- if (!empty($_POST) || isset($_GET['token'])) {
+ $token = request()->query->get('token');
+ if (!empty($_POST) || isset($token)) {
foreach (overlay_supplemental_regions() as $region) {
overlay_store_rendered_content($region, overlay_render_region($region));
}
@@ -979,5 +1005,5 @@ function overlay_trigger_refresh() {
* @see Drupal.overlay.refreshRegions()
*/
function overlay_ajax_render_region($region) {
- print overlay_render_region($region);
+ return new Response(overlay_render_region($region));
}
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index e6779f7..3bb1e0c 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -1006,6 +1006,7 @@ abstract class WebTestBase extends TestBase {
* Retrieve a Drupal path or an absolute path and JSON decode the result.
*/
protected function drupalGetAJAX($path, array $options = array(), array $headers = array()) {
+ $headers[] = 'X-Requested-With: XMLHttpRequest';
return drupal_json_decode($this->drupalGet($path, $options, $headers));
}
@@ -1213,6 +1214,7 @@ abstract class WebTestBase extends TestBase {
}
$content = $this->content;
$drupal_settings = $this->drupalSettings;
+ $headers[] = 'X-Requested-With: XMLHttpRequest';
// Get the Ajax settings bound to the triggering element.
if (!isset($ajax_settings)) {
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index fc0e8bb..a31e278 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -5,6 +5,8 @@
* Admin page callbacks for the system module.
*/
+use Symfony\Component\HttpFoundation\Response;
+
/**
* Menu callback; Provide the administration overview page.
*/
@@ -2303,6 +2305,9 @@ function system_batch_page() {
if ($output === FALSE) {
drupal_access_denied();
}
+ elseif ($output instanceof Response) {
+ return $output;
+ }
elseif (isset($output)) {
// Force a page without blocks or messages to
// display a list of collected messages later.
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index 6e60da8..4dfb6e4 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -5,6 +5,8 @@
* Configuration system that lets administrators modify the workings of the site.
*/
+use Symfony\Component\HttpFoundation\Response;
+
/**
* Maximum age of temporary files in seconds.
*/
@@ -1114,11 +1116,13 @@ function system_menu() {
*
* @see system_cron_access().
*/
+
function system_cron_page() {
drupal_page_is_cacheable(FALSE);
drupal_cron_run();
- // Returning nothing causes no output to be generated.
+ // HTTP 204 is "No content", meaning "I did what you asked and we're done."
+ return new Response('', 204);
}
/**
@@ -2008,8 +2012,11 @@ function system_add_module_assets() {
* Implements hook_custom_theme().
*/
function system_custom_theme() {
- if (user_access('view the administration theme') && path_is_admin(current_path())) {
- return variable_get('admin_theme');
+ if ($request = request()) {
+ $path = $request->attributes->get('system_path');
+ if (user_access('view the administration theme') && path_is_admin($path)) {
+ return variable_get('admin_theme');
+ }
}
}
diff --git a/core/modules/system/system.test b/core/modules/system/system.test
index ec1a9a6..9d25130 100644
--- a/core/modules/system/system.test
+++ b/core/modules/system/system.test
@@ -824,7 +824,7 @@ class CronRunTestCase extends WebTestBase {
// Run cron anonymously with the valid cron key.
$key = config('system.cron')->get('cron_key');
$this->drupalGet('cron/' . $key);
- $this->assertResponse(200);
+ $this->assertResponse(204);
}
/**
diff --git a/core/modules/system/tests/bootstrap.test b/core/modules/system/tests/bootstrap.test
index 098e12e..b3650bd 100644
--- a/core/modules/system/tests/bootstrap.test
+++ b/core/modules/system/tests/bootstrap.test
@@ -194,7 +194,7 @@ class BootstrapPageCacheTestCase extends WebTestBase {
$this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar')));
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), t('Caching was bypassed.'));
$this->assertTrue(strpos($this->drupalGetHeader('Vary'), 'Cookie') === FALSE, t('Vary: Cookie header was not sent.'));
- $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', t('Cache-Control header was sent.'));
+ $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', t('Cache-Control header was sent.'));
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.'));
$this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.'));
diff --git a/core/modules/system/tests/error.test b/core/modules/system/tests/error.test
index a088902..0a3b522 100644
--- a/core/modules/system/tests/error.test
+++ b/core/modules/system/tests/error.test
@@ -75,14 +75,14 @@ class DrupalErrorHandlerUnitTest extends WebTestBase {
'%type' => 'Exception',
'!message' => 'Drupal is awesome',
'%function' => 'error_test_trigger_exception()',
- '%line' => 57,
+ '%line' => 56,
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
);
$error_pdo_exception = array(
- '%type' => 'PDOException',
+ '%type' => 'DatabaseExceptionWrapper',
'!message' => 'SELECT * FROM bananas_are_awesome',
'%function' => 'error_test_trigger_pdo_exception()',
- '%line' => 65,
+ '%line' => 64,
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
);
diff --git a/core/modules/taxonomy/taxonomy.test b/core/modules/taxonomy/taxonomy.test
index 4a3db65..c7e87e8 100644
--- a/core/modules/taxonomy/taxonomy.test
+++ b/core/modules/taxonomy/taxonomy.test
@@ -769,9 +769,8 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
$path = 'taxonomy/autocomplete/taxonomy_';
$path .= $this->vocabulary->machine_name . '/' . $input;
// The result order is not guaranteed, so check each term separately.
- $url = url($path, array('absolute' => TRUE));
- $result = drupal_http_request($url);
- $data = drupal_json_decode($result->data);
+ $result = $this->drupalGet($path);
+ $data = drupal_json_decode($result);
$this->assertEqual($data[$first_term->name], check_plain($first_term->name), 'Autocomplete returned the first matching term');
$this->assertEqual($data[$second_term->name], check_plain($second_term->name), 'Autocomplete returned the second matching term');
diff --git a/core/modules/update/tests/modules/update_test/update_test.module b/core/modules/update/tests/modules/update_test/update_test.module
index ff5aad5..6254d25 100644
--- a/core/modules/update/tests/modules/update_test/update_test.module
+++ b/core/modules/update/tests/modules/update_test/update_test.module
@@ -1,5 +1,8 @@
<?php
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\StreamedResponse;
+
/**
* Implements hook_system_theme_info().
*/
@@ -105,13 +108,19 @@ function update_test_mock_page($project_name) {
// The test didn't specify (for example, the webroot has other modules and
// themes installed but they're disabled by the version of the site
// running the test. So, we default to a file we know won't exist, so at
- // least we'll get an empty page from readfile instead of a bunch of
- // Drupal page output.
+ // least we'll get an empty xml response instead of a bunch of Drupal page
+ // output.
$availability_scenario = '#broken#';
}
$path = drupal_get_path('module', 'update_test');
- readfile("$path/$project_name.$availability_scenario.xml");
+ $file = "$path/$project_name.$availability_scenario.xml";
+ $headers = array('Content-Type' => 'text/xml; charset=utf-8');
+ if (!is_file($file)) {
+ // Return an empty response.
+ return new Response('', 200, $headers);
+ }
+ return file_transfer($file, $headers);
}
/**
diff --git a/core/modules/update/update.fetch.inc b/core/modules/update/update.fetch.inc
index c6652a70..4d8e3c2 100644
--- a/core/modules/update/update.fetch.inc
+++ b/core/modules/update/update.fetch.inc
@@ -142,7 +142,7 @@ function _update_process_fetch_task($project) {
$project_name = $project['name'];
if (empty($fail[$fetch_url_base]) || $fail[$fetch_url_base] < $max_fetch_attempts) {
- $result = drupal_http_request($url);
+ $result = drupal_http_request($url, array('headers' => array('accept' => 'text/xml')));
if (isset($result->error)) {
watchdog('update', 'HTTP request to @url failed with error: @error.', array('@url' => $url, '@error' => $result->error));
}
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index cfde270..09ef3f5 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -2328,9 +2328,12 @@ function user_delete_multiple(array $uids) {
* Page callback wrapper for user_view().
*/
function user_view_page($account) {
+ if (is_object($account)) {
+ return user_view($account);
+ }
// An administrator may try to view a non-existent account,
// so we give them a 404 (versus a 403 for non-admins).
- return is_object($account) ? user_view($account) : MENU_NOT_FOUND;
+ drupal_not_found();
}
/**
diff --git a/core/update.php b/core/update.php
index 9797833..b47702e 100644
--- a/core/update.php
+++ b/core/update.php
@@ -14,6 +14,9 @@
* back to its original state!
*/
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
// Change the directory to the Drupal root.
chdir('..');
@@ -391,11 +394,24 @@ $default = language_default();
drupal_container()->register(LANGUAGE_TYPE_INTERFACE, 'Drupal\\Core\\Language\\Language')
->addMethodCall('extend', array($default));
+// A request object from the HTTPFoundation to tell us about the request.
+// @todo These two lines were copied from index.php which has its own todo about
+// a change required here. Revisit this when that change has been made.
+$request = Request::createFromGlobals();
+request($request);
+
+// There can be conflicting 'op' parameters because both update and batch use
+// this parameter name. We need the 'op' coming from a POST request to trump
+// that coming from a GET request.
+$op = $request->request->get('op');
+if (is_null($op)) {
+ $op = $request->query->get('op');
+}
+
// Only allow the requirements check to proceed if the current user has access
// to run updates (since it may expose sensitive information about the site's
// configuration).
-$op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
-if (empty($op) && update_access_allowed()) {
+if (is_null($op) && update_access_allowed()) {
require_once DRUPAL_ROOT . '/core/includes/install.inc';
require_once DRUPAL_ROOT . '/core/modules/system/system.install';
@@ -423,16 +439,10 @@ if (empty($op) && update_access_allowed()) {
install_goto('core/update.php?op=info');
}
-// update_fix_d8_requirements() needs to run before bootstrapping beyond path.
-// So bootstrap to DRUPAL_BOOTSTRAP_LANGUAGE then include unicode.inc.
-
-drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);
-include_once DRUPAL_ROOT . '/core/includes/unicode.inc';
-
+// Allow update_fix_d8_requirements() to run before code that can break on a
+// Drupal 7 database.
+drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
update_fix_d8_requirements();
-
-// Now proceed with a full bootstrap.
-
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
drupal_maintenance_theme();
@@ -440,6 +450,7 @@ drupal_maintenance_theme();
// not passed through the error handler) will cause a message to be printed.
ini_set('display_errors', TRUE);
+
// Only proceed with updates if the user is allowed to run them.
if (update_access_allowed()) {
@@ -453,27 +464,29 @@ if (update_access_allowed()) {
// no errors, skip reporting them if the user has provided a URL parameter
// acknowledging the warnings and indicating a desire to continue anyway. See
// drupal_requirements_url().
- $skip_warnings = !empty($_GET['continue']);
+ $continue = $request->query->get('continue');
+ $skip_warnings = !empty($continue);
update_check_requirements($skip_warnings);
- $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
switch ($op) {
// update.php ops.
case 'selection':
- if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) {
+ $token = $request->query->get('token');
+ if (isset($token) && drupal_valid_token($token, 'update')) {
$output = update_selection_page();
break;
}
case 'Apply pending updates':
- if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) {
+ $token = $request->query->get('token');
+ if (isset($token) && drupal_valid_token($token, 'update')) {
// Generate absolute URLs for the batch processing (using $base_root),
// since the batch API will pass them to url() which does not handle
// update.php correctly by default.
$batch_url = $base_root . drupal_current_script_url();
$redirect_url = $base_root . drupal_current_script_url(array('op' => 'results'));
- update_batch($_POST['start'], $redirect_url, $batch_url);
+ update_batch($request->request->get('start'), $redirect_url, $batch_url);
break;
}
@@ -500,5 +513,11 @@ if (isset($output) && $output) {
drupal_session_start();
// We defer the display of messages until all updates are done.
$progress_page = ($batch = batch_get()) && isset($batch['running']);
- print theme('update_page', array('content' => $output, 'show_messages' => !$progress_page));
+ if ($output instanceof Response) {
+ $output->send();
+ }
+ else {
+ print theme('update_page', array('content' => $output, 'show_messages' => !$progress_page));
+ }
+
}
diff --git a/index.php b/index.php
index b91fb1e..2f05bb3 100644
--- a/index.php
+++ b/index.php
@@ -11,11 +11,37 @@
* See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
*/
+use Drupal\Core\DrupalKernel;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\HttpKernel\Controller\ControllerResolver;
+
/**
* Root directory of Drupal installation.
*/
define('DRUPAL_ROOT', getcwd());
-
+// Bootstrap the lowest level of what we need.
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
-drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-menu_execute_active_handler();
+drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
+
+// Create a request object from the HTTPFoundation.
+$request = Request::createFromGlobals();
+
+// Set the global $request object. This is a temporary measure to keep legacy
+// utility functions working. It should be moved to a dependency injection
+// container at some point.
+request($request);
+
+// Bootstrap all of Drupal's subsystems, but do not initialize anything that
+// depends on the fully resolved Drupal path, because path resolution happens
+// during the REQUEST event of the kernel.
+// @see Drupal\Core\EventSubscriber\PathSubscriber;
+// @see Drupal\Core\EventSubscriber\LegacyRequestSubscriber;
+drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
+
+$dispatcher = new EventDispatcher();
+$resolver = new ControllerResolver();
+
+$kernel = new DrupalKernel($dispatcher, $resolver);
+$response = $kernel->handle($request)->prepare($request)->send();
+$kernel->terminate($request, $response);