Skip to content
Snippets Groups Projects
Commit d2527ed4 authored by catch's avatar catch
Browse files

Issue #1831998 by c4rl, effulgentsia: Reduce index.php for easier upgrading.

parent 80e1ff2c
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -2140,6 +2140,53 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
return $stored_phase;
}
/**
* Handles an entire PHP request.
*
* This function may be called by PHP scripts (e.g., Drupal's index.php) that
* want Drupal to take over the entire PHP processing of the request. The only
* expectation is that PHP's superglobals are initialized as desired (PHP does
* this automatically, but some scripts might want to alter them) and that the
* DRUPAL_ROOT constant is defined and set to the absolute server directory of
* Drupal's codebase.
*
* Scripts and applications that want to invoke multiple Drupal requests within
* a single PHP request, or Drupal request handling within some larger workflow,
* should not call this function, but instead instantiate and use
* \Drupal\Core\DrupalKernel as needed.
*
* @param boolean $test_only
* Whether to restrict handling to only requests invoked by SimpleTest.
*
* @see index.php
*/
function drupal_handle_request($test_only = FALSE) {
// Initialize the environment, load settings.php, and activate a PSR-0 class
// autoloader with required namespaces registered.
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
// Exit if we should be in a test environment but aren't.
if ($test_only && !drupal_valid_test_ua()) {
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
exit;
}
// @todo Figure out how best to handle the Kernel constructor parameters.
$kernel = new DrupalKernel('prod', FALSE, drupal_classloader(), !$test_only);
// @todo Remove this once everything in the bootstrap has been
// converted to services in the DIC.
$kernel->boot();
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
// Create a request object from the HttpFoundation.
$request = Request::createFromGlobals();
$response = $kernel->handle($request)->prepare($request)->send();
$kernel->terminate($request, $response);
exit;
}
/**
* Returns the time zone of the current user.
*/
......
......@@ -5,9 +5,6 @@
* Fake an HTTP request, for use during testing.
*/
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
// Set a global variable to indicate a mock HTTP request.
$is_http_mock = !empty($_SERVER['HTTPS']);
......@@ -21,21 +18,7 @@
// Change current directory to the Drupal root.
chdir('../../../..');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
// Make sure this file can only be used by simpletest.
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
if (!drupal_valid_test_ua()) {
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
exit;
}
// Continue with normal request handling.
$request = Request::createFromGlobals();
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
$kernel = new DrupalKernel('prod', FALSE, drupal_classloader(), FALSE);
$response = $kernel->handle($request)->prepare($request)->send();
$kernel->terminate($request, $response);
drupal_handle_request(TRUE);
......@@ -5,9 +5,6 @@
* Fake an HTTPS request, for use during testing.
*/
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
// Set a global variable to indicate a mock HTTPS request.
$is_https_mock = empty($_SERVER['HTTPS']);
......@@ -20,21 +17,7 @@
// Change current directory to the Drupal root.
chdir('../../../..');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
// Make sure this file can only be used by simpletest.
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
if (!drupal_valid_test_ua()) {
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
exit;
}
// Continue with normal request handling.
$request = Request::createFromGlobals();
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
$kernel = new DrupalKernel('prod', FALSE, drupal_classloader(), FALSE);
$response = $kernel->handle($request)->prepare($request)->send();
$kernel->terminate($request, $response);
drupal_handle_request(TRUE);
......@@ -4,39 +4,14 @@
* @file
* The PHP page that serves all page requests on a Drupal installation.
*
* The routines here dispatch control to the appropriate handler, which then
* prints the appropriate page.
*
* All Drupal code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
*/
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
/**
* Root directory of Drupal installation.
*/
define('DRUPAL_ROOT', getcwd());
// 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;
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
// @todo Figure out how best to handle the Kernel constructor parameters.
$kernel = new DrupalKernel('prod', FALSE, drupal_classloader());
// @todo Remove this once everything in the bootstrap has been
// converted to services in the DIC.
$kernel->boot();
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
// Create a request object from the HTTPFoundation.
$request = Request::createFromGlobals();
$response = $kernel->handle($request)->prepare($request)->send();
$kernel->terminate($request, $response);
drupal_handle_request();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment