| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: devel.drush.inc,v 1.7.2.2 2010/11/19 03:46:13 weitzman Exp $ 3 4 /** 5 * @file 6 * Drush integration for the devel module. 7 */ 8 9 /** 10 * Implements hook_drush_command(). 11 */ 12 function devel_drush_command() { 13 $items['devel-download'] = array( 14 'description' => dt('Downloads the FirePHP library from http://firephp.org/.'), 15 'arguments' => array( 16 'path' => dt('Optional. A path to the download folder. If omitted Drush will use the default location (sites/all/libraries/firephp).'), 17 ), 18 ); 19 $items['devel-reinstall'] = array( 20 'description' => dt('Disable, Uninstall, and Install a list of projects.'), 21 'arguments' => array( 22 'path' => dt('A space separated list of project names.'), 23 ), 24 'aliases' => array('dre'), 25 ); 26 $items['fn-hook'] = array( 27 'description' => 'List implementations of a given hook and explore source of specified one.', 28 'arguments' => array( 29 'hook' => 'The name of the hook to explore.' 30 ), 31 'aliases' => array('fnh', 'hook'), 32 ); 33 $items['fn-view'] = array( 34 'description' => 'Show the source of specified function or method.', 35 'arguments' => array( 36 'function' => 'The name of the function or method to view.', 37 ), 38 'options' => array( 39 '--pipe' => 'Output just the filename of the function', 40 ), 41 'examples' => array( 42 'fn-view drupal_set_breadcrumb' => 'View the source code for function "drupal_set_breadcrumb"', 43 'vi `drush --pipe fn-view user_access`' => 'Edit the file that contains the function "user_access"', 44 'fn-view NodeController::load' => 'View the source code for method load in the class NodeController' 45 ), 46 'aliases' => array('fnv'), 47 ); 48 $items['devel-token'] = array( 49 'description' => dt('List available tokens'), 50 'aliases' => array('token'), 51 'core' => array(7), // Remove once 3.0 is released. 52 ); 53 return $items; 54 } 55 56 /** 57 * Implementation of hook_drush_help(). 58 */ 59 function devel_drush_help($section) { 60 switch ($section) { 61 case 'drush:devel-reinstall': 62 return dt('Disable, Uninstall, and Install a list of projects.'); 63 case 'drush:devel-download': 64 return dt("Downloads the FirePHP library from http://firephp.org/. Places it in the devel module directory. Skips download if library already present. This all happens automatically if you enable devel using drush."); 65 } 66 } 67 68 69 /** 70 * A command callback. This is faster than 3 separate bootstraps. 71 */ 72 function drush_devel_reinstall() { 73 $projects = func_get_args(); 74 75 $args = array_merge(array('pm-disable'), $projects); 76 call_user_func_array('drush_invoke', $args); 77 78 $args = array_merge(array('pm-uninstall'), $projects); 79 call_user_func_array('drush_invoke', $args); 80 81 $args = array_merge(array('pm-enable'), $projects); 82 call_user_func_array('drush_invoke', $args); 83 } 84 85 /** 86 * A command callback. 87 */ 88 function drush_devel_download() { 89 $args = func_get_args(); 90 if (isset($args[0])) { 91 $path = $args[0]; 92 } 93 else { 94 $path = drush_get_context('DRUSH_DRUPAL_ROOT'); 95 if (module_exists('libraries')) { 96 $path .= libraries_get_path('FirePHPCore') . '/FirePHPCore'; 97 } 98 else { 99 $path .= '/'. drupal_get_path('module', 'devel') . '/FirePHPCore'; 100 } 101 } 102 103 if (is_dir($path)) { 104 drush_log('FirePHP already present. No download required.', 'ok'); 105 } 106 elseif (drush_shell_exec('svn checkout http://firephp.googlecode.com/svn/branches/Library-FirePHPCore-0.3 ' . $path)) { 107 drush_log(dt('FirePHP has been downloaded to @path.', array('@path' => $path)), 'success'); 108 } 109 else { 110 drush_log(dt('Drush was unable to download FirePHP to @path.', array('@path' => $path)), 'error'); 111 } 112 } 113 114 /** 115 * Implements drush_MODULE_post_COMMAND(). 116 */ 117 function drush_devel_post_enable() { 118 $modules = func_get_args(); 119 if (in_array('devel', $modules)) { 120 drush_devel_download(); 121 } 122 } 123 124 /** 125 * Command handler. Show hook implementations 126 */ 127 function drush_devel_fn_hook($hook) { 128 // Get implementations in the .install files as well. 129 include_once './includes/install.inc'; 130 drupal_load_updates(); 131 132 if ($hook_implementations = module_implements($hook)) { 133 if ($choice = drush_choice(array_combine($hook_implementations, $hook_implementations), 'Enter the number of the hook implementation you wish to view.')) { 134 return drush_devel_fn_view($choice . "_$hook"); 135 } 136 } 137 else { 138 drush_log(dt('No implementations.'), 'ok'); 139 } 140 } 141 142 /** 143 * Command handler. Show source code of specified function or method. 144 */ 145 function drush_devel_fn_view($function_name) { 146 // Get implementations in the .install files as well. 147 include_once './includes/install.inc'; 148 drupal_load_updates(); 149 150 if (strpos($function_name, '::') === FALSE) { 151 if (!function_exists($function_name)) { 152 return drush_set_error(dt('Function not found')); 153 } 154 $reflect = new ReflectionFunction($function_name); 155 } 156 else { 157 list($class, $method) = explode('::', $function_name); 158 if (!method_exists($class, $method)) { 159 return drush_set_error(dt('Method not found')); 160 } 161 $reflect = new ReflectionMethod($class, $method); 162 } 163 $func_info = array('!file' => $reflect->getFileName(), '!startline' => $reflect->getStartLine(), '!endline' => $reflect->getEndLine()); 164 //drush_print_pipe(dt("!file -line !startline", $func_info)); 165 drush_print_pipe($reflect->getFileName()); 166 drush_print(dt("// file: !file, lines !startline-!endline", $func_info)); 167 168 _drush_devel_print_function($reflect->getFileName(), $reflect->getStartLine(), $reflect->getEndLine()); 169 } 170 171 /** 172 * Command callback. List available tokens. 173 */ 174 function drush_devel_token() { 175 $rows[] = array(dt('Group'), dt('Token'), dt('Name')); 176 $all = token_info(); 177 foreach ($all['tokens'] as $group => $tokens) { 178 foreach ($tokens as $key => $token) { 179 $rows[] = array($group, $key, $token['name']); 180 } 181 } 182 drush_print_table($rows, TRUE); 183 } 184 185 186 /** 187 * Print the specified function, including any 188 * doxygen-style comments that come before it. 189 */ 190 function _drush_devel_print_function($file, $start_line, $end_line) { 191 $line_num = 0; 192 $doxygen = NULL; 193 $fp = fopen( $file, 'r' ); 194 195 while (!feof($fp) && ($line_num < ($start_line - 1))) { 196 $line = fgets($fp); 197 ++$line_num; 198 199 if (substr($line,0,3) == '/**') { 200 $doxygen = $line; 201 } 202 elseif (isset($doxygen)) { 203 $doxygen .= $line; 204 if ($line_num + 1 == $start_line) { 205 drush_print(rtrim($doxygen)); 206 } 207 if (strstr($line, '*/') !== FALSE) { 208 $doxygen = NULL; 209 } 210 } 211 } 212 while (!feof($fp) && ($line_num < $end_line)) { 213 $line = fgets($fp); 214 ++$line_num; 215 drush_print(rtrim($line)); 216 } 217 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |