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_profile() {
  28. return drupal_get_profile();
  29. }
  30. function add_logger() {
  31. // If we're running on Drupal 8 or later, we provide a logger which will send
  32. // output to drush_log(). This should catch every message logged through every
  33. // channel.
  34. \Drupal::getContainer()->get('logger.factory')->addLogger(new \Drush\Log\DrushLog);
  35. }
  36. function contrib_modules_paths() {
  37. return array(
  38. conf_path() . '/modules',
  39. 'sites/all/modules',
  40. 'modules',
  41. );
  42. }
  43. /**
  44. * @return array of strings - paths to directories where contrib
  45. * themes can be found
  46. */
  47. function contrib_themes_paths() {
  48. return array(
  49. conf_path() . '/themes',
  50. 'sites/all/themes',
  51. 'themes',
  52. );
  53. }
  54. function bootstrap_drupal_core($drupal_root) {
  55. $core = DRUPAL_ROOT . '/core';
  56. return $core;
  57. }
  58. function bootstrap_drupal_root_validate() {
  59. return drush_set_error('DRUSH_DRUPAL_VERSION_UNSUPPORTED', dt('Drush !drush_version does not support Drupal 8. You will need Drush version 8 or higher. See http://docs.drush.org/en/master/install/ for details.', array('!drush_version' => DRUSH_VERSION)));
  60. }
  61. function bootstrap_drupal_database() {
  62. // D8 omits this bootstrap level as nothing special needs to be done.
  63. parent::bootstrap_drupal_database();
  64. }
  65. function bootstrap_drupal_configuration() {
  66. $this->request = Request::createFromGlobals();
  67. $classloader = drush_drupal_load_autoloader(DRUPAL_ROOT);
  68. $this->kernel = DrupalKernel::createFromRequest($this->request, $classloader, 'prod');
  69. // Unset drupal error handler and restore drush's one.
  70. restore_error_handler();
  71. parent::bootstrap_drupal_configuration();
  72. }
  73. function bootstrap_drupal_full() {
  74. if (!drush_get_context('DRUSH_QUIET', FALSE)) {
  75. ob_start();
  76. }
  77. $this->kernel->boot();
  78. $this->kernel->prepareLegacyRequest($this->request);
  79. if (!drush_get_context('DRUSH_QUIET', FALSE)) {
  80. ob_end_clean();
  81. }
  82. parent::bootstrap_drupal_full();
  83. }
  84. /**
  85. * {@inheritdoc}
  86. */
  87. public function terminate() {
  88. parent::terminate();
  89. if ($this->kernel) {
  90. $response = Response::create('');
  91. $this->kernel->terminate($this->request, $response);
  92. }
  93. }
  94. }