Exemple #1
0
/**
 * Preprocessor for html.tpl.php
 * Adds meta tag to control viewport, and path to theme in JS.
 */
function plain_response_preprocess_html(&$vars)
{
    $meta = array('#tag' => 'meta', '#attributes' => array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1, minimum-scale=1'));
    drupal_add_html_head($meta, 'plain-response-viewport');
    $settings = array('base_url' => url('<front>', array('absolute' => 'true')), 'theme_path' => path_to_theme(), 'default_scheme' => file_default_scheme());
    foreach (file_get_stream_wrappers() as $name => $wrapper) {
        $settings[$name . '_files'] = file_create_url($name . '://');
    }
    $path = drupal_get_path('theme', 'plain_response');
    drupal_add_js(array('plain_response' => $settings), array('type' => 'setting'));
}
Exemple #2
0
 /**
  * Overrides LinkitSearchPluginEntity::createGroup().
  */
 function createGroup($entity)
 {
     // The the standard group name.
     $group = parent::createGroup($entity);
     // Add the scheme.
     if ($this->conf['group_by_scheme']) {
         // Get all stream wrappers.
         $stream_wrapper = file_get_stream_wrappers();
         $group .= ' - ' . $stream_wrapper[file_uri_scheme($entity->uri)]['name'];
     }
     return $group;
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array &$form, FormStateInterface $form_state, $has_data)
 {
     $element = array();
     $element['#attached']['library'][] = 'file/drupal.file';
     $element['display_field'] = array('#type' => 'checkbox', '#title' => t('Enable <em>Display</em> field'), '#default_value' => $this->getSetting('display_field'), '#description' => t('The display option allows users to choose if a file should be shown when viewing the content.'));
     $element['display_default'] = array('#type' => 'checkbox', '#title' => t('Files displayed by default'), '#default_value' => $this->getSetting('display_default'), '#description' => t('This setting only has an effect if the display option is enabled.'), '#states' => array('visible' => array(':input[name="field[settings][display_field]"]' => array('checked' => TRUE))));
     $scheme_options = array();
     foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) {
         $scheme_options[$scheme] = $stream_wrapper['name'];
     }
     $element['uri_scheme'] = array('#type' => 'radios', '#title' => t('Upload destination'), '#options' => $scheme_options, '#default_value' => $this->getSetting('uri_scheme'), '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), '#disabled' => $has_data);
     return $element;
 }
 /**
  * @param \Drufony\Bridge\Event\GetCallableForPhase $event
  */
 public function onBootstrapFull(GetCallableForPhase $event)
 {
     $event->setCallable(function () {
         require_once DRUPAL_ROOT . '/includes/common.inc';
         require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');
         require_once DRUPAL_ROOT . '/includes/theme.inc';
         require_once DRUPAL_ROOT . '/includes/pager.inc';
         require_once DRUPAL_ROOT . '/' . variable_get('menu_inc', 'includes/menu.inc');
         require_once DRUPAL_ROOT . '/includes/tablesort.inc';
         require_once DRUPAL_ROOT . '/includes/file.inc';
         require_once DRUPAL_ROOT . '/includes/unicode.inc';
         require_once DRUPAL_ROOT . '/includes/image.inc';
         require_once DRUPAL_ROOT . '/includes/form.inc';
         require_once DRUPAL_ROOT . '/includes/mail.inc';
         require_once DRUPAL_ROOT . '/includes/actions.inc';
         require_once DRUPAL_ROOT . '/includes/ajax.inc';
         require_once DRUPAL_ROOT . '/includes/token.inc';
         require_once DRUPAL_ROOT . '/includes/errors.inc';
         // Detect string handling method
         unicode_check();
         // Undo magic quotes
         fix_gpc_magic();
         // Load all enabled modules
         module_load_all();
         // Make sure all stream wrappers are registered.
         file_get_stream_wrappers();
         // Ensure mt_rand is reseeded, to prevent random values from one page load
         // being exploited to predict random values in subsequent page loads.
         $seed = unpack("L", drupal_random_bytes(4));
         mt_srand($seed[1]);
         $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');
         }
         // Initialize $_GET['q'] prior to invoking hook_init().
         drupal_path_initialize();
         // Remaining function calls from this phase of bootstrap must happen after
         // the user is authenticated because they initialize the theme and call
         // menu_get_item().
     });
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('system.file');
     $form['file_public_path'] = array('#type' => 'item', '#title' => t('Public file system path'), '#default_value' => PublicStream::basePath(), '#markup' => PublicStream::basePath(), '#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web. This must be changed in settings.php'));
     $form['file_private_path'] = array('#type' => 'textfield', '#title' => t('Private file system path'), '#default_value' => $config->get('path.private'), '#maxlength' => 255, '#description' => t('An existing local file system path for storing private files. It should be writable by Drupal and not accessible over the web. See the online handbook for <a href="@handbook">more information about securing private files</a>.', array('@handbook' => 'http://drupal.org/documentation/modules/file')), '#after_build' => array('system_check_directory'));
     $form['file_temporary_path'] = array('#type' => 'textfield', '#title' => t('Temporary directory'), '#default_value' => $config->get('path.temporary'), '#maxlength' => 255, '#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'), '#after_build' => array('system_check_directory'));
     // Any visible, writeable wrapper can potentially be used for the files
     // directory, including a remote file system that integrates with a CDN.
     foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $info) {
         $options[$scheme] = String::checkPlain($info['description']);
     }
     if (!empty($options)) {
         $form['file_default_scheme'] = array('#type' => 'radios', '#title' => t('Default download method'), '#default_value' => $config->get('default_scheme'), '#options' => $options, '#description' => t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'));
     }
     $intervals = array(0, 21600, 43200, 86400, 604800, 2419200, 7776000);
     $period = array_combine($intervals, array_map(array($this->dateFormatter, 'formatInterval'), $intervals));
     $period[0] = t('Never');
     $form['temporary_maximum_age'] = array('#type' => 'select', '#title' => t('Delete orphaned files after'), '#default_value' => $config->get('temporary_maximum_age'), '#options' => $period, '#description' => t('Orphaned files are not referenced from any content but remain in the file system and may appear in administrative listings. <strong>Warning:</strong> If enabled, orphaned files will be permanently deleted and may not be recoverable.'));
     return parent::buildForm($form, $form_state);
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  */
 public function save($destination)
 {
     $scheme = file_uri_scheme($destination);
     // Work around lack of stream wrapper support in imagejpeg() and imagepng().
     if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
         // If destination is not local, save image to temporary local file.
         $local_wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_LOCAL);
         if (!isset($local_wrappers[$scheme])) {
             $permanent_destination = $destination;
             $destination = drupal_tempnam('temporary://', 'gd_');
         }
         // Convert stream wrapper URI to normal path.
         $destination = drupal_realpath($destination);
     }
     switch ($this->getType()) {
         case GDToolkitWebP::IMAGETYPE_WEBP:
             $function = 'imagewebp';
             break;
         default:
             $function = 'image' . image_type_to_extension($this->getType(), FALSE);
             break;
     }
     if (!function_exists($function)) {
         return FALSE;
     }
     if ($this->getType() == IMAGETYPE_JPEG) {
         $success = $function($this->getResource(), $destination, $this->configFactory->get('system.image.gd')->get('jpeg_quality'));
     } else {
         // Always save PNG images with full transparency.
         if ($this->getType() == IMAGETYPE_PNG) {
             imagealphablending($this->getResource(), FALSE);
             imagesavealpha($this->getResource(), TRUE);
         }
         $success = $function($this->getResource(), $destination);
     }
     // Move temporary local file to remote destination.
     if (isset($permanent_destination) && $success) {
         return (bool) file_unmanaged_move($destination, $permanent_destination, FILE_EXISTS_REPLACE);
     }
     return $success;
 }
 /**
  * Tests whether module-provided stream wrappers are registered properly.
  */
 public function testModuleStreamWrappers()
 {
     // file_test.module provides (among others) a 'dummy' stream wrapper.
     // Verify that it is not registered yet to prevent false positives.
     $stream_wrappers = file_get_stream_wrappers();
     $this->assertFalse(isset($stream_wrappers['dummy']));
     $this->moduleHandler()->install(['file_test']);
     // Verify that the stream wrapper is available even without calling
     // file_get_stream_wrappers() again. If the stream wrapper is not available
     // file_exists() will raise a notice.
     file_exists('dummy://');
     $stream_wrappers = file_get_stream_wrappers();
     $this->assertTrue(isset($stream_wrappers['dummy']));
 }
Exemple #8
0
/**
 * Loads the requested module and executes the requested callback.
 *
 * @return
 *   The callback function's return value or one of the JS_* constants.
 */
function js_execute_callback()
{
    $args = explode('/', $_GET['q']);
    // If i18n is enabled and therefore the js module should boot
    // to DRUPAL_BOOTSTRAP_LANGUAGE.
    $i18n = FALSE;
    // Validate if there is a language prefix in the path.
    if (!empty($args[0]) && !empty($args[1]) && $args[1] == 'js_callback') {
        // Language string detected, strip off the language code.
        $language_code = array_shift($args);
        // Enable language detection to make sure i18n is enabled.
        $i18n = TRUE;
    }
    // Strip first argument 'js_callback'.
    if (!empty($args[0]) && $args[0] == 'js_callback') {
        array_shift($args);
    }
    // Determine module to load.
    $module = check_plain(array_shift($args));
    if (!$module || !drupal_load('module', $module)) {
        return JS_MENU_ACCESS_DENIED;
    }
    // Get info hook function name.
    $function = $module . '_js';
    if (!function_exists($function)) {
        return JS_MENU_NOT_FOUND;
    }
    // Get valid callbacks.
    $valid_callbacks = $function();
    // Get the callback.
    $callback = check_plain(array_shift($args));
    // Validate the callback.
    if (!isset($valid_callbacks[$callback])) {
        return JS_MENU_NOT_FOUND;
    }
    // If the callback function is located in another file, load that file now.
    if (isset($valid_callbacks[$callback]['file']) && ($filepath = drupal_get_path('module', $module) . '/' . $valid_callbacks[$callback]['file']) && file_exists($filepath)) {
        require_once $filepath;
    }
    // Validate the existance of the defined callback.
    if (!function_exists($valid_callbacks[$callback]['callback'])) {
        return JS_MENU_NOT_FOUND;
    }
    // Bootstrap to required level.
    $full_boostrap = FALSE;
    if (!empty($valid_callbacks[$callback]['bootstrap'])) {
        drupal_bootstrap($valid_callbacks[$callback]['bootstrap']);
        $full_boostrap = $valid_callbacks[$callback]['bootstrap'] == DRUPAL_BOOTSTRAP_FULL;
    }
    // Validate if the callback uses i18n.
    if (isset($valid_callbacks[$callback]['i18n'])) {
        $i18n = $valid_callbacks[$callback]['i18n'];
    }
    if (!$full_boostrap) {
        // The following mimics the behavior of _drupal_bootstrap_full().
        // The difference is that not all modules and includes are loaded.
        // @see _drupal_bootstrap_full().
        // If i18n is enabled, boot to the language phase and make
        // sure the required modules are enabled.
        if ($i18n) {
            // First boot to the variables to make sure drupal_multilingual() works.
            drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
            // As the variables bootstrap phase loads all core modules, we have to
            // add the user module and the path include as a dependencies because they
            // are required by some core modules.
            if (empty($valid_callbacks[$callback]['dependencies'])) {
                $valid_callbacks[$callback]['dependencies'] = array();
            }
            if (empty($valid_callbacks[$callback]['includes'])) {
                $valid_callbacks[$callback]['includes'] = array();
            }
            if (!in_array('user', $valid_callbacks[$callback]['dependencies'])) {
                $valid_callbacks[$callback]['dependencies'][] = 'user';
            }
            if (!in_array('path', $valid_callbacks[$callback]['includes'])) {
                $valid_callbacks[$callback]['includes'][] = 'path';
            }
            // Then check if it's a multilingual site. If so, boot to the language
            // phase.
            if (drupal_multilingual()) {
                drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);
            }
        }
        // Load required include files based on the callback.
        if (isset($valid_callbacks[$callback]['includes']) && is_array($valid_callbacks[$callback]['includes'])) {
            foreach ($valid_callbacks[$callback]['includes'] as $include) {
                if (file_exists("./includes/{$include}.inc")) {
                    require_once "./includes/{$include}.inc";
                }
            }
        }
        // Detect string handling method.
        unicode_check();
        // Undo magic quotes.
        fix_gpc_magic();
        // Make sure all stream wrappers are registered.
        file_get_stream_wrappers();
        // Load required modules.
        $modules = array($module => 0);
        if (isset($valid_callbacks[$callback]['dependencies']) && is_array($valid_callbacks[$callback]['dependencies'])) {
            foreach ($valid_callbacks[$callback]['dependencies'] as $dependency) {
                if (!drupal_load('module', $dependency)) {
                    // Do a boot up till SESSION to be sure the drupal_set_message()
                    // function works.
                    drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
                    // Create an error message with information for the user to be able
                    // to fix the dependency.
                    $error = t('The dependency :dependency for the callback :callback in :module is not installed.', array(':dependency' => $dependency, ':callback' => $callback, ':module' => $module));
                    // Let the user know what's wrong and throw an exception to stop the
                    // callback.
                    drupal_set_message($error, 'error');
                    throw new Exception($error);
                }
                $modules[$dependency] = 0;
            }
        }
        // Reset module list.
        module_list(FALSE, TRUE, FALSE, $modules);
        // Ensure the language variable is set, if not it might cause problems (e.g.
        // entity info).
        global $language;
        if (!isset($language)) {
            $language = language_default();
        }
        // If access arguments are passed, boot to SESSION and validate if the user
        // has access to this callback.
        if (!empty($valid_callbacks[$callback]['access arguments']) || !empty($valid_callbacks[$callback]['access callback'])) {
            drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
            // If no callback is provided, default to user_access.
            if (!isset($valid_callbacks[$callback]['access callback'])) {
                $valid_callbacks[$callback]['access callback'] = 'user_access';
            }
            if ($valid_callbacks[$callback]['access callback'] == 'user_access') {
                // Ensure the user module is available.
                drupal_load('module', 'user');
            }
            if (!call_user_func_array($valid_callbacks[$callback]['access callback'], !empty($valid_callbacks[$callback]['access arguments']) ? $valid_callbacks[$callback]['access arguments'] : array())) {
                return JS_MENU_ACCESS_DENIED;
            }
        }
        // Invoke implementations of hook_init() if the callback doesn't indicate it
        // should be skipped.
        if (!isset($valid_callbacks[$callback]['skip_hook_init']) || $valid_callbacks[$callback]['skip_hook_init'] == FALSE) {
            module_invoke_all('init');
        }
    }
    // If there are page arguments defined add them to the callback call.
    if (isset($valid_callbacks[$callback]['page arguments'])) {
        // Get the original args again and strip first arguments 'js_callback' and 'module'.
        $args = array_slice(explode('/', $_GET['q']), 2);
        // Overwrite the arguments
        $args = array_intersect_key($args, array_flip($valid_callbacks[$callback]['page arguments']));
    }
    // Invoke callback function.
    return call_user_func_array($valid_callbacks[$callback]['callback'], $args);
}
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function flush($path = NULL)
 {
     // A specific image path has been provided. Flush only that derivative.
     if (isset($path)) {
         $derivative_uri = $this->buildUri($path);
         if (file_exists($derivative_uri)) {
             file_unmanaged_delete($derivative_uri);
         }
         return $this;
     }
     // Delete the style directory in each registered wrapper.
     $wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE);
     foreach ($wrappers as $wrapper => $wrapper_data) {
         if (file_exists($directory = $wrapper . '://styles/' . $this->id())) {
             file_unmanaged_delete_recursive($directory);
         }
     }
     // Let other modules update as necessary on flush.
     $module_handler = \Drupal::moduleHandler();
     $module_handler->invokeAll('image_style_flush', array($this));
     // Clear caches so that formatters may be added for this style.
     drupal_theme_rebuild();
     Cache::invalidateTags($this->getCacheTag());
     return $this;
 }
Exemple #10
0
 /**
  * Returns available schemes.
  *
  * @return array
  *   The available schemes.
  */
 protected function getSchemes()
 {
     return array_keys(file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE));
 }
Exemple #11
0
 /**
  * Cleans up the test environment and restores the original environment.
  *
  * Deletes created files, database tables, and reverts environment changes.
  *
  * This method needs to be invoked for both unit and integration tests.
  *
  * @see TestBase::prepareDatabasePrefix()
  * @see TestBase::changeDatabasePrefix()
  * @see TestBase::prepareEnvironment()
  */
 private function restoreEnvironment()
 {
     // Destroy the session if one was started during the test-run.
     $_SESSION = array();
     if (PHP_SAPI !== 'cli' && session_status() === PHP_SESSION_ACTIVE) {
         session_destroy();
         $params = session_get_cookie_params();
         setcookie(session_name(), '', REQUEST_TIME - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
     }
     session_name($this->originalSessionName);
     // Reset all static variables.
     // Unsetting static variables will potentially invoke destruct methods,
     // which might call into functions that prime statics and caches again.
     // In that case, all functions are still operating on the test environment,
     // which means they may need to access its filesystem and database.
     drupal_static_reset();
     if ($this->container && $this->container->has('state') && ($state = $this->container->get('state'))) {
         $captured_emails = $state->get('system.test_mail_collector') ?: array();
         $emailCount = count($captured_emails);
         if ($emailCount) {
             $message = $emailCount == 1 ? '1 email was sent during this test.' : $emailCount . ' emails were sent during this test.';
             $this->pass($message, 'Email');
         }
     }
     // Sleep for 50ms to allow shutdown functions and terminate events to
     // complete. Further information: https://drupal.org/node/2194357.
     usleep(50000);
     // Remove all prefixed tables.
     $original_connection_info = Database::getConnectionInfo('simpletest_original_default');
     $original_prefix = $original_connection_info['default']['prefix']['default'];
     $test_connection_info = Database::getConnectionInfo('default');
     $test_prefix = $test_connection_info['default']['prefix']['default'];
     if ($original_prefix != $test_prefix) {
         $tables = Database::getConnection()->schema()->findTables($test_prefix . '%');
         $prefix_length = strlen($test_prefix);
         foreach ($tables as $table) {
             if (Database::getConnection()->schema()->dropTable(substr($table, $prefix_length))) {
                 unset($tables[$table]);
             }
         }
     }
     // In case a fatal error occurred that was not in the test process read the
     // log to pick up any fatal errors.
     simpletest_log_read($this->testId, $this->databasePrefix, get_class($this));
     // Delete test site directory.
     file_unmanaged_delete_recursive($this->siteDirectory, array($this, 'filePreDeleteCallback'));
     // Restore original database connection.
     Database::removeConnection('default');
     Database::renameConnection('simpletest_original_default', 'default');
     // Reset all static variables.
     // All destructors of statically cached objects have been invoked above;
     // this second reset is guaranteed to reset everything to nothing.
     drupal_static_reset();
     // Reset global theme variables.
     unset($GLOBALS['theme_key']);
     unset($GLOBALS['theme']);
     unset($GLOBALS['theme_info']);
     unset($GLOBALS['base_theme_info']);
     unset($GLOBALS['theme_engine']);
     unset($GLOBALS['theme_path']);
     // Restore original in-memory configuration.
     $GLOBALS['config'] = $this->originalConfig;
     $GLOBALS['conf'] = $this->originalConf;
     new Settings($this->originalSettings);
     // Restore original statics and globals.
     \Drupal::setContainer($this->originalContainer);
     $GLOBALS['config_directories'] = $this->originalConfigDirectories;
     if (isset($this->originalPrefix)) {
         drupal_valid_test_ua($this->originalPrefix);
     } else {
         drupal_valid_test_ua(FALSE);
     }
     conf_path(TRUE, TRUE);
     // Restore stream wrappers of the test runner.
     file_get_stream_wrappers();
     // Restore original shutdown callbacks.
     $callbacks =& drupal_register_shutdown_function();
     $callbacks = $this->originalShutdownCallbacks;
 }
Exemple #12
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array &$form, FormStateInterface $form_state, $has_data)
 {
     $element = array();
     // We need the field-level 'default_image' setting, and $this->getSettings()
     // will only provide the instance-level one, so we need to explicitly fetch
     // the field.
     $settings = $this->getFieldDefinition()->getFieldStorageDefinition()->getSettings();
     $scheme_options = array();
     foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) {
         $scheme_options[$scheme] = $stream_wrapper['name'];
     }
     $element['uri_scheme'] = array('#type' => 'radios', '#title' => t('Upload destination'), '#options' => $scheme_options, '#default_value' => $settings['uri_scheme'], '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'));
     // Add default_image element.
     static::defaultImageForm($element, $settings);
     $element['default_image']['#description'] = t('If no image is uploaded, this image will be shown on display.');
     return $element;
 }
Exemple #13
0
 /**
  * Helper method that does request related initialization.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  */
 protected function preHandle(Request $request)
 {
     // Load all enabled modules.
     $this->container->get('module_handler')->loadAll();
     // Initialize legacy request globals.
     $this->initializeRequestGlobals($request);
     // Initialize cookie globals.
     $this->initializeCookieGlobals($request);
     // Put the request on the stack.
     $this->container->get('request_stack')->push($request);
     // Make sure all stream wrappers are registered.
     file_get_stream_wrappers();
     // Set the allowed protocols once we have the config available.
     $allowed_protocols = $this->container->get('config.factory')->get('system.filter')->get('protocols');
     if (!isset($allowed_protocols)) {
         // \Drupal\Component\Utility\UrlHelper::filterBadProtocol() is called by
         // the installer and update.php, in which case the configuration may not
         // exist (yet). Provide a minimal default set of allowed protocols for
         // these cases.
         $allowed_protocols = array('http', 'https');
     }
     UrlHelper::setAllowedProtocols($allowed_protocols);
 }
Exemple #14
0
 /**
  * @param array $values
  */
 public function __construct(array $values = array())
 {
     // If this bootstrap object is used in a service, bootstrap.inc may
     // not have been included yet. If the file is not included, the
     // Drupal bootstrap constants are not available.
     require_once $values['DRUPAL_ROOT'] . '/includes/bootstrap.inc';
     parent::__construct($values);
     /**
      * Sets up the script environment and loads settings.php.
      *
      * @see _drupal_bootstrap_configuration()
      */
     $this[DRUPAL_BOOTSTRAP_CONFIGURATION] = $this->share(function () {
         // Start a page timer:
         timer_start('page');
         // Initialize the configuration, including variables from settings.php.
         // drupal_settings_initialize();
         global $base_url, $base_path, $base_root;
         // Export these settings.php variables to the global namespace.
         global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url;
         $conf = array();
         if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.php')) {
             include_once DRUPAL_ROOT . '/' . conf_path() . '/settings.php';
         }
         $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
         if (isset($base_url)) {
             // Parse fixed base URL from settings.php.
             $parts = parse_url($base_url);
             if (!isset($parts['path'])) {
                 $parts['path'] = '';
             }
             $base_path = $parts['path'] . '/';
             // Build $base_root (everything until first slash after "scheme://").
             $base_root = substr($base_url, 0, strlen($base_url) - strlen($parts['path']));
         } else {
             // Create base URL.
             $http_protocol = $is_https ? 'https' : 'http';
             $base_root = $http_protocol . '://' . $_SERVER['HTTP_HOST'];
             $base_url = $base_root;
             // $_SERVER['SCRIPT_NAME'] can, in contrast to $_SERVER['PHP_SELF'], not
             // be modified by a visitor.
             if ($dir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\\/')) {
                 $base_path = $dir;
                 $base_url .= $base_path;
                 $base_path .= '/';
             } else {
                 $base_path = '/';
             }
         }
         $base_secure_url = str_replace('http://', 'https://', $base_url);
         $base_insecure_url = str_replace('https://', 'http://', $base_url);
         // We do not mess with cookie or session settings in Drupal at all.
     });
     // DRUPAL_BOOTSTRAP_PAGE_CACHE only loads the cache handler.
     $this[DRUPAL_BOOTSTRAP_PAGE_CACHE] = $this->share(function () {
         // Allow specifying special cache handlers in settings.php, like
         // using memcached or files for storing cache information.
         require_once DRUPAL_ROOT . '/includes/cache.inc';
         foreach (variable_get('cache_backends', array()) as $include) {
             require_once DRUPAL_ROOT . '/' . $include;
         }
     });
     // DRUPAL_BOOTSTRAP_DATABASE - in parent class.
     $this[DRUPAL_BOOTSTRAP_VARIABLES] = $this->share($this->extend(DRUPAL_BOOTSTRAP_VARIABLES, function () {
         if (isset($GLOBALS['service_container']) && is_a($GLOBALS['service_container'], 'Symfony\\Component\\DependencyInjection\\ContainerInterface')) {
             /** @var \Symfony\Component\DependencyInjection\ContainerInterface $container */
             $container = $GLOBALS['service_container'];
             $GLOBALS['conf']['session_inc'] = $container->getParameter('bangpound_drupal.conf.session_inc');
             $GLOBALS['conf']['mail_system']['default-system'] = $container->getParameter('bangpound_drupal.conf.mail_system.default_system');
         }
     }));
     // DRUPAL_BOOTSTRAP_SESSION - in base class.
     $this[DRUPAL_BOOTSTRAP_PAGE_HEADER] = $this->share(function () {
         bootstrap_invoke_all('boot');
     });
     // DRUPAL_BOOTSTRAP_LANGUAGE
     $this[DRUPAL_BOOTSTRAP_FULL] = $this->share(function () {
         require_once DRUPAL_ROOT . '/includes/common.inc';
         require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');
         require_once DRUPAL_ROOT . '/includes/theme.inc';
         require_once DRUPAL_ROOT . '/includes/pager.inc';
         require_once DRUPAL_ROOT . '/' . variable_get('menu_inc', 'includes/menu.inc');
         require_once DRUPAL_ROOT . '/includes/tablesort.inc';
         require_once DRUPAL_ROOT . '/includes/file.inc';
         require_once DRUPAL_ROOT . '/includes/unicode.inc';
         require_once DRUPAL_ROOT . '/includes/image.inc';
         require_once DRUPAL_ROOT . '/includes/form.inc';
         require_once DRUPAL_ROOT . '/includes/mail.inc';
         require_once DRUPAL_ROOT . '/includes/actions.inc';
         require_once DRUPAL_ROOT . '/includes/ajax.inc';
         require_once DRUPAL_ROOT . '/includes/token.inc';
         require_once DRUPAL_ROOT . '/includes/errors.inc';
         // Detect string handling method
         unicode_check();
         // Undo magic quotes
         fix_gpc_magic();
         // Load all enabled modules
         module_load_all();
         // Make sure all stream wrappers are registered.
         file_get_stream_wrappers();
         // Ensure mt_rand is reseeded, to prevent random values from one page load
         // being exploited to predict random values in subsequent page loads.
         $seed = unpack("L", drupal_random_bytes(4));
         mt_srand($seed[1]);
         $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');
         }
         // Initialize $_GET['q'] prior to invoking hook_init().
         drupal_path_initialize();
         // Remaining function calls from this phase of bootstrap must happen after
         // the user is authenticated because they initialize the theme and call
         // menu_get_item().
     });
 }