Commandfiles.php

  1. 8.0.x lib/Drush/Command/Commandfiles.php
  2. 7.x lib/Drush/Command/Commandfiles.php
  3. master lib/Drush/Command/Commandfiles.php

Definition of Drush\Command\Commandfiles.

Namespace

Drush\Command

Classes

Namesort descending Description
Commandfiles Default commandfiles implementation.

File

lib/Drush/Command/Commandfiles.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of Drush\Command\Commandfiles.
  5. */
  6. namespace Drush\Command;
  7. /**
  8. * Default commandfiles implementation.
  9. *
  10. * This class manages the list of commandfiles that are active
  11. * in Drush for the current command invocation.
  12. */
  13. class Commandfiles implements CommandfilesInterface {
  14. protected $cache;
  15. protected $deferred;
  16. function __construct() {
  17. $this->cache = array();
  18. $this->deferred = array();
  19. }
  20. function get() {
  21. return $this->cache;
  22. }
  23. function deferred() {
  24. return $this->deferred;
  25. }
  26. function sort() {
  27. ksort($this->cache);
  28. }
  29. function add($commandfile) {
  30. $load_command = FALSE;
  31. $module = basename($commandfile);
  32. $module = preg_replace('/\.*drush[0-9]*\.inc/', '', $module);
  33. $module_versionless = preg_replace('/\.d([0-9]+)$/', '', $module);
  34. if (!isset($this->cache[$module_versionless])) {
  35. $drupal_version = '';
  36. if (preg_match('/\.d([0-9]+)$/', $module, $matches)) {
  37. $drupal_version = $matches[1];
  38. }
  39. if (empty($drupal_version)) {
  40. $load_command = TRUE;
  41. }
  42. else {
  43. if (function_exists('drush_drupal_major_version') && ($drupal_version == drush_drupal_major_version())) {
  44. $load_command = TRUE;
  45. }
  46. else {
  47. // Signal that we should try again on
  48. // the next bootstrap phase.
  49. $this->deferred[$module] = $commandfile;
  50. }
  51. }
  52. if ($load_command) {
  53. $this->cache[$module_versionless] = $commandfile;
  54. require_once $commandfile;
  55. unset($this->deferred[$module]);
  56. }
  57. }
  58. return $load_command;
  59. }
  60. }