Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / commands / pm / projectinfo.pm.inc
1 <?php
2
3 use Drush\Log\LogLevel;
4
5 /**
6  * Implementation of drush_hook_COMMAND_validate().
7  */
8 function drush_pm_projectinfo_validate() {
9   $status = drush_get_option('status');
10   if (!empty($status)) {
11     if (!in_array($status, array('enabled', 'disabled'), TRUE)) {
12       return drush_set_error('DRUSH_PM_INVALID_PROJECT_STATUS', dt('!status is not a valid project status.', array('!status' => $status)));
13     }
14   }
15 }
16
17 /**
18  * Implementation of drush_hook_COMMAND().
19  */
20 function drush_pm_projectinfo() {
21   // Get specific requests.
22   $requests = pm_parse_arguments(func_get_args(), FALSE);
23
24   // Get installed extensions and projects.
25   $extensions = drush_get_extensions();
26   $projects = drush_get_projects($extensions);
27
28   // If user did not specify any projects, return them all
29   if (empty($requests)) {
30     $result = $projects;
31   }
32   else {
33     $result = array();
34     foreach ($requests as $name) {
35       if (array_key_exists($name, $projects)) {
36         $result[$name] = $projects[$name];
37       }
38       else {
39         drush_log(dt('!project was not found.', array('!project' => $name)), LogLevel::WARNING);
40         continue;
41       }
42     }
43   }
44
45   // Find the Drush commands that belong with each project.
46   foreach ($result as $name => $project) {
47     $drush_commands = pm_projectinfo_commands_in_project($project);
48     if (!empty($drush_commands)) {
49       $result[$name]['drush'] = $drush_commands;
50     }
51   }
52
53   // If user specified --drush, remove projects with no drush extensions
54   if (drush_get_option('drush')) {
55     foreach ($result as $name => $project) {
56       if (!array_key_exists('drush', $project)) {
57         unset($result[$name]);
58       }
59     }
60   }
61
62   // If user specified --status=1|0, remove projects with a distinct status.
63   if (($status = drush_get_option('status', FALSE)) !== FALSE) {
64     $status_code = ($status == 'enabled') ? 1 : 0;
65     foreach ($result as $name => $project) {
66       if ($project['status'] != $status_code) {
67         unset($result[$name]);
68       }
69     }
70   }
71
72   return $result;
73 }
74
75 function pm_projectinfo_commands_in_project($project) {
76   $drush_commands = array();
77   if (array_key_exists('path', $project)) {
78     $commands = drush_get_commands();
79     foreach ($commands as $commandname => $command) {
80       if (!array_key_exists("is_alias", $command) && ($command['path'] == $project['path'])) {
81         $drush_commands[] = $commandname;
82       }
83     }
84   }
85   return $drush_commands;
86 }
87