DrupalBoot8.php

  1. 8.0.x lib/Drush/Boot/DrupalBoot8.php
  2. 7.x lib/Drush/Boot/DrupalBoot8.php
  3. master lib/Drush/Boot/DrupalBoot8.php

Namespace

Drush\Boot

Classes

Namesort descending Description
DrupalBoot8

File

lib/Drush/Boot/DrupalBoot8.php
View source
  1. <?php
  2. namespace Drush\Boot;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Drupal\Core\DrupalKernel;
  6. class DrupalBoot8 extends DrupalBoot {
  7. /**
  8. * @var \Drupal\Core\DrupalKernelInterface
  9. */
  10. protected $kernel;
  11. /**
  12. * @var \Symfony\Component\HttpFoundation\Request
  13. */
  14. protected $request;
  15. function valid_root($path) {
  16. if (!empty($path) && is_dir($path) && file_exists($path . '/index.php')) {
  17. // Additional check for the presence of core/composer.json to
  18. // grant it is not a Drupal 7 site with a base folder named "core".
  19. $candidate = 'core/includes/common.inc';
  20. if (file_exists($path . '/' . $candidate) && file_exists($path . '/core/core.services.yml')) {
  21. if (file_exists($path . '/core/misc/drupal.js') || file_exists($path . '/core/assets/js/drupal.js')) {
  22. return $candidate;
  23. }
  24. }
  25. }
  26. }
  27. function get_version($drupal_root) {
  28. // Load the autoloader so we can access the class constants.
  29. drush_drupal_load_autoloader($drupal_root);
  30. // Drush depends on bootstrap being loaded at this point.
  31. require_once $drupal_root .'/core/includes/bootstrap.inc';
  32. if (defined('Drupal::VERSION')) {
  33. return \Drupal::VERSION;
  34. }
  35. }
  36. function get_profile() {
  37. return drupal_get_profile();
  38. }
  39. function conf_path($require_settings = TRUE, $reset = FALSE, Request $request = NULL) {
  40. if (!isset($request)) {
  41. if (\Drupal::hasRequest()) {
  42. $request = \Drupal::request();
  43. }
  44. // @todo Remove once external CLI scripts (Drush) are updated.
  45. else {
  46. $request = Request::createFromGlobals();
  47. }
  48. }
  49. if (\Drupal::hasService('kernel')) {
  50. $site_path = \Drupal::service('kernel')->getSitePath();
  51. }
  52. if (!isset($site_path) || empty($site_path)) {
  53. $site_path = DrupalKernel::findSitePath($request, $require_settings);
  54. }
  55. return $site_path;
  56. }
  57. function add_logger() {
  58. // If we're running on Drupal 8 or later, we provide a logger which will send
  59. // output to drush_log(). This should catch every message logged through every
  60. // channel.
  61. $container = \Drupal::getContainer();
  62. $parser = $container->get('logger.log_message_parser');
  63. $logger = new \Drush\Log\DrushLog($parser);
  64. $container->get('logger.factory')->addLogger($logger);
  65. }
  66. function contrib_modules_paths() {
  67. return array(
  68. $this->conf_path() . '/modules',
  69. 'sites/all/modules',
  70. 'modules',
  71. );
  72. }
  73. /**
  74. * @return array of strings - paths to directories where contrib
  75. * themes can be found
  76. */
  77. function contrib_themes_paths() {
  78. return array(
  79. $this->conf_path() . '/themes',
  80. 'sites/all/themes',
  81. 'themes',
  82. );
  83. }
  84. function bootstrap_drupal_core($drupal_root) {
  85. $core = DRUPAL_ROOT . '/core';
  86. return $core;
  87. }
  88. function bootstrap_drupal_database_validate() {
  89. return parent::bootstrap_drupal_database_validate() && $this->bootstrap_drupal_database_has_table('key_value');
  90. }
  91. function bootstrap_drupal_database() {
  92. // D8 omits this bootstrap level as nothing special needs to be done.
  93. parent::bootstrap_drupal_database();
  94. }
  95. function bootstrap_drupal_configuration() {
  96. $this->request = Request::createFromGlobals();
  97. $classloader = drush_drupal_load_autoloader(DRUPAL_ROOT);
  98. $this->kernel = DrupalKernel::createFromRequest($this->request, $classloader, 'prod');
  99. // Unset drupal error handler and restore drush's one.
  100. restore_error_handler();
  101. parent::bootstrap_drupal_configuration();
  102. }
  103. function bootstrap_drupal_full() {
  104. if (!drush_get_context('DRUSH_QUIET', FALSE)) {
  105. ob_start();
  106. }
  107. $this->kernel->boot();
  108. $this->kernel->prepareLegacyRequest($this->request);
  109. if (!drush_get_context('DRUSH_QUIET', FALSE)) {
  110. ob_end_clean();
  111. }
  112. parent::bootstrap_drupal_full();
  113. }
  114. /**
  115. * {@inheritdoc}
  116. */
  117. public function terminate() {
  118. parent::terminate();
  119. if ($this->kernel) {
  120. $response = Response::create('');
  121. $this->kernel->terminate($this->request, $response);
  122. }
  123. }
  124. }