diff -u b/core/core.services.yml b/core/core.services.yml --- b/core/core.services.yml +++ b/core/core.services.yml @@ -66,7 +66,7 @@ arguments: ['@database', '@cache_tags.invalidator.checksum'] cache.backend.apcu: class: Drupal\Core\Cache\ApcuBackendFactory - arguments: ['@app.root', '@kernel', '@cache_tags.invalidator.checksum'] + arguments: ['@app.root', '@cache_tags.invalidator.checksum'] cache.backend.php: class: Drupal\Core\Cache\PhpBackendFactory arguments: ['@cache_tags.invalidator.checksum'] @@ -136,7 +136,7 @@ arguments: ['@database', '@cache_tags.invalidator.checksum'] cache.backend.apcu: class: Drupal\Core\Cache\ApcuBackendFactory - arguments: ['@app.root', '@cache_tags.invalidator.checksum'] + arguments: ['@app.root', '@site.path', '@cache_tags.invalidator.checksum'] cache.backend.php: class: Drupal\Core\Cache\PhpBackendFactory arguments: ['@cache_tags.invalidator.checksum'] @@ -542,6 +542,16 @@ class: Drupal\Core\AppRootFactory arguments: ['@kernel'] public: false + site.path: + class: SplString + factory_service: 'site.path.factory' + factory_method: 'get' + tags: + - { name: parameter_service } + site.path.factory: + class: Drupal\Core\SitePathFactory + arguments: ['@kernel'] + public: false controller_resolver: class: Drupal\Core\Controller\ControllerResolver arguments: ['@class_resolver'] diff -u b/core/includes/install.core.inc b/core/includes/install.core.inc --- b/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1885,7 +1885,7 @@ $readable = FALSE; $writable = FALSE; // @todo: Make this configurable. - $conf_path = \Drupal::service('kernel')->getSitePath(); + $conf_path = \Drupal::service('site.path'); $files_directory = $conf_path . '/files'; $translations_directory = $conf_path . '/files/translations'; $translations_directory_exists = FALSE; @@ -2065,7 +2065,7 @@ foreach ($default_files as $default_file_info) { $readable = FALSE; $writable = FALSE; - $conf_path = './' . \Drupal::service('kernel')->getSitePath(); + $conf_path = './' . \Drupal::service('site.path'); $file = $conf_path . "/{$default_file_info['file']}"; $default_file = "./sites/default/{$default_file_info['file_default']}"; $exists = FALSE; diff -u b/core/includes/install.inc b/core/includes/install.inc --- b/core/includes/install.inc +++ b/core/includes/install.inc @@ -197,7 +197,7 @@ */ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { if (!isset($settings_file)) { - $settings_file = \Drupal::service('kernel')->getSitePath() . '/settings.php'; + $settings_file = \Drupal::service('site.path') . '/settings.php'; } // Build list of setting names and insert the values into the global namespace. $variable_names = array(); @@ -470,13 +470,13 @@ $config_directories_hash = Crypt::randomBytesBase64(55); if (empty($config_directories[CONFIG_ACTIVE_DIRECTORY])) { $settings['config_directories'][CONFIG_ACTIVE_DIRECTORY] = (object) [ - 'value' => \Drupal::service('kernel')->getSitePath() . '/files/config_' . $config_directories_hash . '/active', + 'value' => \Drupal::service('site.path') . '/files/config_' . $config_directories_hash . '/active', 'required' => TRUE, ]; } if (empty($config_directories[CONFIG_STAGING_DIRECTORY])) { $settings['config_directories'][CONFIG_STAGING_DIRECTORY] = (object) [ - 'value' => \Drupal::service('kernel')->getSitePath() . '/files/config_' . $config_directories_hash . '/staging', + 'value' => \Drupal::service('site.path') . '/files/config_' . $config_directories_hash . '/staging', 'required' => TRUE, ]; } diff -u b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php --- b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php @@ -20,13 +20,6 @@ protected $sitePrefix; /** - * The Drupal kernel. - * - * @var \Drupal\Core\DrupalKernelInterface - */ - protected $kernel; - - /** * The cache tags checksum provider. * * @var \Drupal\Core\Cache\CacheTagsChecksumInterface @@ -38,13 +31,13 @@ * * @param string $root * The app root. - * @param \Drupal\Core\DrupalKernelInterface $kernel - * The Drupal kernel. + * @param string $site_path + * The site path. * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider * The cache tags checksum provider. */ - public function __construct($root, DrupalKernelInterface $kernel, CacheTagsChecksumInterface $checksum_provider) { - $this->sitePrefix = Crypt::hashBase64($root . '/' . $kernel->getSitePath()); + public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider) { + $this->sitePrefix = Crypt::hashBase64($root . '/' . $site_path); $this->checksumProvider = $checksum_provider; } diff -u b/core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php --- b/core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php @@ -49,7 +49,7 @@ // Make the text more accurate for SQLite. $form['database']['#title'] = t('Database file'); $form['database']['#description'] = t('The absolute path to the file where @drupal data will be stored. This must be writable by the web server and should exist outside of the web root.', array('@drupal' => drupal_install_profile_distribution_name())); - $default_database = \Drupal::service('kernel')->getSitePath() . '/files/.ht.sqlite'; + $default_database = \Drupal::service('site.path') . '/files/.ht.sqlite'; $form['database']['#default_value'] = empty($database['database']) ? $default_database : $database['database']; return $form; } diff -u b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php --- b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php @@ -157,7 +157,7 @@ // Find the site-specific directory to search. Kernel service is not always // available at this point, but is preferred, when available. if (\Drupal::hasService('kernel')) { - $searchdirs[static::ORIGIN_SITE] = \Drupal::service('kernel')->getSitePath(); + $searchdirs[static::ORIGIN_SITE] = \Drupal::service('site.path'); } else { $searchdirs[static::ORIGIN_SITE] = DrupalKernel::findSitePath(Request::createFromGlobals()); diff -u b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php --- b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Installer\Form; -use Drupal\Core\DrupalKernelInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; @@ -22,11 +21,11 @@ class SiteConfigureForm extends ConfigFormBase { /** - * The Drupal kernel. + * The site path. * - * @var \Drupal\Core\DrupalKernelInterface + * @var string */ - protected $kernel; + protected $sitePath; /** * The user storage. @@ -68,8 +67,8 @@ * * @param string $root * The app root. - * @param \Drupal\Core\DrupalKernelInterface $kernel - * The Drupal kernel. + * @param string $site_path + * The site path. * @param \Drupal\user\UserStorageInterface $user_storage * The user storage. * @param \Drupal\Core\State\StateInterface $state @@ -79,9 +78,9 @@ * @param \Drupal\Core\Locale\CountryManagerInterface $country_manager * The country manager. */ - public function __construct($root, DrupalKernelInterface $kernel, UserStorageInterface $user_storage, StateInterface $state, ModuleInstallerInterface $module_installer, CountryManagerInterface $country_manager) { + public function __construct($root, $site_path, UserStorageInterface $user_storage, StateInterface $state, ModuleInstallerInterface $module_installer, CountryManagerInterface $country_manager) { $this->root = $root; - $this->kernel = $kernel; + $this->sitePath = $site_path; $this->userStorage = $user_storage; $this->state = $state; $this->moduleInstaller = $module_installer; @@ -94,7 +93,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('app.root'), - $container->get('kernel'), + $container->get('site.path'), $container->get('entity.manager')->getStorage('user'), $container->get('state'), $container->get('module_installer'), @@ -127,7 +126,7 @@ $form['#title'] = $this->t('Configure site'); // Warn about settings.php permissions risk - $settings_dir = $this->kernel->getSitePath(); + $settings_dir = $this->sitePath; $settings_file = $settings_dir . '/settings.php'; // Check that $_POST is empty so we only show this message when the form is // first displayed, not on the next page after it is submitted. (We do not diff -u b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php --- b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Installer\Form; -use Drupal\Core\DrupalKernelInterface; use Drupal\Component\Utility\Crypt; use Drupal\Core\Database\Database; use Drupal\Core\Form\FormBase; @@ -20,28 +19,28 @@ class SiteSettingsForm extends FormBase { /** - * The Drupal kernel. + * The site path. * - * @var \Drupal\Core\DrupalKernelInterface + * @var string */ - protected $kernel; + protected $sitePath; /** * Constructs a new SiteSettingsForm. * - * @param \Drupal\Core\DrupalKernelInterface $kernel - * The Drupal kernel. + * @param string $site_path + * The site path. */ - public function __construct(DrupalKernelInterface $kernel) { - $this->kernel = $kernel; - } + public function __construct($site_path) { + $this->sitePath = $site_path; +} /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( - $container->get('kernel') + $container->get('site.path') ); } @@ -56,7 +55,7 @@ * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { - $conf_path = './' . $this->kernel->getSitePath(); + $conf_path = './' . $this->sitePath; $settings_file = $conf_path . '/settings.php'; $form['#title'] = $this->t('Database configuration'); diff -u b/core/lib/Drupal/Core/StreamWrapper/PublicStream.php b/core/lib/Drupal/Core/StreamWrapper/PublicStream.php --- b/core/lib/Drupal/Core/StreamWrapper/PublicStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/PublicStream.php @@ -66,7 +66,7 @@ // Find the site path. Kernel service is not always available at this point, // but is preferred, when available. if (\Drupal::hasService('kernel')) { - $site_path = \Drupal::service('kernel')->getSitePath(); + $site_path = \Drupal::service('site.path'); } else { $site_path = DrupalKernel::findSitePath(Request::createFromGlobals()); diff -u b/core/modules/file/tests/file_test/src/StreamWrapper/DummyReadOnlyStreamWrapper.php b/core/modules/file/tests/file_test/src/StreamWrapper/DummyReadOnlyStreamWrapper.php --- b/core/modules/file/tests/file_test/src/StreamWrapper/DummyReadOnlyStreamWrapper.php +++ b/core/modules/file/tests/file_test/src/StreamWrapper/DummyReadOnlyStreamWrapper.php @@ -31,7 +31,7 @@ } function getDirectoryPath() { - return \Drupal::service('kernel')->getSitePath() . '/files'; + return \Drupal::service('site.path') . '/files'; } /** diff -u b/core/modules/file/tests/file_test/src/StreamWrapper/DummyStreamWrapper.php b/core/modules/file/tests/file_test/src/StreamWrapper/DummyStreamWrapper.php --- b/core/modules/file/tests/file_test/src/StreamWrapper/DummyStreamWrapper.php +++ b/core/modules/file/tests/file_test/src/StreamWrapper/DummyStreamWrapper.php @@ -31,7 +31,7 @@ } function getDirectoryPath() { - return \Drupal::service('kernel')->getSitePath() . '/files'; + return \Drupal::service('site.path') . '/files'; } /** diff -u b/core/modules/locale/locale.install b/core/modules/locale/locale.install --- b/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -15,7 +15,7 @@ function locale_install() { // Create the interface translations directory and ensure it's writable. if (!$directory = \Drupal::config('locale.settings')->get('translation.path')) { - $conf_path = \Drupal::service('kernel')->getSitePath(); + $conf_path = \Drupal::service('site.path'); $directory = $conf_path . '/files/translations'; \Drupal::configFactory()->getEditable('locale.settings')->set('translation.path', $directory)->save(); } diff -u b/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php --- b/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -1140,7 +1140,7 @@ } // Backup current in-memory configuration. - $site_path = \Drupal::service('kernel')->getSitePath(); + $site_path = \Drupal::service('site.path'); $this->originalSite = $site_path; $this->originalSettings = Settings::getAll(); $this->originalConfig = $GLOBALS['config']; diff -u b/core/modules/system/src/Tests/File/DirectoryTest.php b/core/modules/system/src/Tests/File/DirectoryTest.php --- b/core/modules/system/src/Tests/File/DirectoryTest.php +++ b/core/modules/system/src/Tests/File/DirectoryTest.php @@ -19,8 +19,8 @@ * Test local directory handling functions. */ function testFileCheckLocalDirectoryHandling() { - $kernel = $this->container->get('kernel'); - $directory = $kernel->getSitePath() . '/files'; + $site_path = $this->container->get('site.path'); + $directory = $site_path . '/files'; // Check a new recursively created local directory for correct file system // permissions. diff -u b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php --- b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php +++ b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php @@ -34,8 +34,8 @@ function testReadOnlyBehavior() { // Generate a test file $filename = $this->randomMachineName(); - $kernel = $this->container->get('kernel'); - $filepath = $kernel->getSitePath() . '/files/' . $filename; + $site_path = $this->container->get('site.path'); + $filepath = $site_path . '/files/' . $filename; file_put_contents($filepath, $filename); // Generate a read-only stream wrapper instance @@ -80,7 +80,7 @@ // Test the mkdir() function by attempting to create a directory. $dirname = $this->randomMachineName(); - $dir = $kernel->getSitePath() . '/files/' . $dirname; + $dir = $site_path . '/files/' . $dirname; $readonlydir = $this->scheme . '://' . $dirname; $this->assertFalse(@drupal_mkdir($readonlydir, 0775, 0), 'Unable to create directory with read-only stream wrapper.'); // Create a temporary directory for testing purposes diff -u b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php --- b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php @@ -55,7 +55,7 @@ // Find the site path. Kernel service is not always available at this point, // but is preferred, when available. if (\Drupal::hasService('kernel')) { - $conf_path = \Drupal::service('kernel')->getSitePath(); + $conf_path = \Drupal::service('site.path'); } else { $conf_path = DrupalKernel::findSitePath(Request::createFromGlobals()); diff -u b/core/modules/system/src/Tests/System/SettingsRewriteTest.php b/core/modules/system/src/Tests/System/SettingsRewriteTest.php --- b/core/modules/system/src/Tests/System/SettingsRewriteTest.php +++ b/core/modules/system/src/Tests/System/SettingsRewriteTest.php @@ -21,7 +21,7 @@ */ function testDrupalRewriteSettings() { include_once \Drupal::root() . '/core/includes/install.inc'; - $kernel = $this->container->get('kernel'); + $site_path = $this->container->get('site.path'); $tests = array( array( 'original' => '$no_index_value_scalar = TRUE;', @@ -100,7 +100,7 @@ ), ); foreach ($tests as $test) { - $filename = Settings::get('file_public_path', $kernel->getSitePath() . '/files') . '/mock_settings.php'; + $filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php'; file_put_contents(\Drupal::root() . '/' . $filename, "assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), " '$no_index = true;' ); // Make an empty file. - $filename = Settings::get('file_public_path', $kernel->getSitePath() . '/files') . '/mock_settings.php'; + $filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php'; file_put_contents(\Drupal::root() . '/' . $filename, ""); // Write the setting to the file. diff -u b/core/modules/system/system.install b/core/modules/system/system.install --- b/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -240,7 +240,7 @@ // Find the site path. Kernel service is not always available at this point, // but is preferred, when available. if (\Drupal::hasService('kernel')) { - $conf_path = \Drupal::service('kernel')->getSitePath(); + $conf_path = \Drupal::service('site.path'); } else { $conf_path = DrupalKernel::findSitePath(Request::createFromGlobals()); diff -u b/core/modules/update/src/Form/UpdateManagerInstall.php b/core/modules/update/src/Form/UpdateManagerInstall.php --- b/core/modules/update/src/Form/UpdateManagerInstall.php +++ b/core/modules/update/src/Form/UpdateManagerInstall.php @@ -7,7 +7,6 @@ namespace Drupal\update\Form; -use Drupal\Core\DrupalKernelInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\FileTransfer\Local; use Drupal\Core\Form\FormBase; @@ -35,11 +34,11 @@ protected $root; /** - * The Drupal kernel. + * The site path. * - * @var \Drupal\Core\DrupalKernelInterface + * @var string */ - protected $kernel; + protected $sitePath; /** * Constructs a new UpdateManagerInstall. @@ -48,13 +47,13 @@ * The app root. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. - * @param \Drupal\Core\DrupalKernelInterface $kernel - * The Drupal kernel. + * @param string $site_path + * The site path. */ - public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel) { + public function __construct($root, ModuleHandlerInterface $module_handler, $site_path) { $this->root = $root; $this->moduleHandler = $module_handler; - $this->kernel = $kernel; + $this->sitePath = $site_path; } /** @@ -71,7 +70,7 @@ return new static( $container->get('app.root'), $container->get('module_handler'), - $container->get('kernel') + $container->get('site.path') ); } @@ -228,7 +227,7 @@ // install the code, there's no need to prompt for FTP/SSH credentials. // Instead, we instantiate a Drupal\Core\FileTransfer\Local and invoke // update_authorize_run_install() directly. - if (fileowner($project_real_location) == fileowner($this->kernel->getSitePath())) { + if (fileowner($project_real_location) == fileowner($this->sitePath)) { $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize'); $filetransfer = new Local($this->root); call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments)); diff -u b/core/modules/update/src/Form/UpdateReady.php b/core/modules/update/src/Form/UpdateReady.php --- b/core/modules/update/src/Form/UpdateReady.php +++ b/core/modules/update/src/Form/UpdateReady.php @@ -7,7 +7,6 @@ namespace Drupal\update\Form; -use Drupal\Core\DrupalKernelInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\FileTransfer\Local; use Drupal\Core\Form\FormBase; @@ -43,11 +42,11 @@ protected $state; /** - * The Drupal kernel. + * The Site path. * - * @var \Drupal\Core\DrupalKernelInterface + * @var string */ - protected $kernel; + protected $sitePath; /** * Constructs a new UpdateReady object. @@ -58,14 +57,14 @@ * The object that manages enabled modules in a Drupal installation. * @param \Drupal\Core\State\StateInterface $state * The state key value store. - * @param \Drupal\Core\DrupalKernelInterface $kernel - * The Drupal kernel. + * @param string $site_path + * The site path. */ - public function __construct($root, ModuleHandlerInterface $module_handler, StateInterface $state, DrupalKernelInterface $kernel) { + public function __construct($root, ModuleHandlerInterface $module_handler, StateInterface $state, $site_path) { $this->root = $root; $this->moduleHandler = $module_handler; $this->state = $state; - $this->kernel = $kernel; + $this->sitePath = $site_path; } /** @@ -83,7 +82,7 @@ $container->get('app.root'), $container->get('module_handler'), $container->get('state'), - $container->get('kernel') + $container->get('site.path') ); } @@ -154,7 +153,7 @@ // trying to install the code, there's no need to prompt for FTP/SSH // credentials. Instead, we instantiate a Drupal\Core\FileTransfer\Local // and invoke update_authorize_run_update() directly. - if (fileowner($project_real_location) == fileowner($this->kernel->getSitePath())) { + if (fileowner($project_real_location) == fileowner($this->sitePath)) { $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize'); $filetransfer = new Local($this->root); update_authorize_run_update($filetransfer, $updates); diff -u b/core/modules/update/update.manager.inc b/core/modules/update/update.manager.inc --- b/core/modules/update/update.manager.inc +++ b/core/modules/update/update.manager.inc @@ -306,7 +306,7 @@ // the configuration directory to determine if local transfers will be // allowed. $temporary_file = drupal_tempnam('temporary://', 'update_'); - $conf_path = \Drupal::service('kernel')->getSitePath(); + $conf_path = \Drupal::service('site.path'); $local_transfers_allowed = fileowner($temporary_file) === fileowner($conf_path); // Clean up. If this fails, we can ignore it (since this is just a temporary only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/SitePathFactory.php @@ -0,0 +1,43 @@ +drupalKernel = $drupal_kernel; + } + + /** + * Gets the site path. + * + * @return string + * The site path. + */ + public function get() { + return $this->drupalKernel->getSitePath(); + } + +} +