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