function annotationcommand_adapter_get_commands_for_commandhandler

master annotationcommand_adapter.inc annotationcommand_adapter_get_commands_for_commandhandler($commandhandler, $commandfile_path)

Convert an annotated command command handler object into a Drush $command record.

Parameters

object $commandhandler Command handler object:

string $commandfile_path:

boolean $includeAllPublicMethods TODO remove this, make it 'false' always:

Return value

array Drush $command record

2 calls to annotationcommand_adapter_get_commands_for_commandhandler()
annotationcommand_adapter_cache_module_service_commands in includes/annotationcommand_adapter.inc
TODO: document
annotationcommand_adapter_get_commands in includes/annotationcommand_adapter.inc
Internal function called by annotationcommand_adapter_commands, which is called by drush_get_commands().

File

includes/annotationcommand_adapter.inc, line 361
annotationcommand_adapter.inc

Code

function annotationcommand_adapter_get_commands_for_commandhandler($commandhandler, $commandfile_path) {
  $cache = &drush_get_context('DRUSH_ANNOTATION_COMMANDS_FOR_COMMANDFILE');
  if (isset($cache[$commandfile_path])) {
    return $cache[$commandfile_path];
  }
  $factory = \Drush::commandFactory();
  $commands =[];
  $commandfile = basename($commandfile_path, '.php');

  $commandinfo_list = $factory->getCommandInfoListFromClass($commandhandler);

  foreach ($commandinfo_list as $commandinfo) {
    $factory->registerCommandHook($commandinfo, $commandhandler);
    // Skip anything that is not a command
    if (!AnnotatedCommandFactory::isCommandMethod($commandinfo, false)) {
      continue;
    }

    $aliases = $commandinfo->getAliases();
    $command_name = strtolower($commandinfo->getName());
    $standard_alias = str_replace(':', '-', $command_name);
    if ($command_name != $standard_alias) {
      $aliases[] = $standard_alias;
    }
    $handle_remote_commands = strtolower($commandinfo->getAnnotation('handle-remote-commands')) == 'true';
    $hidden = $commandinfo->hasAnnotation('hidden');
    // If there is no 'bootstrap' annotation, default to NONE.
    $bootstrap = DRUSH_BOOTSTRAP_NONE;
    if ($bootstrap = $commandinfo->getAnnotation('bootstrap')) {
      $bootstrap = constant($bootstrap);
    }
    $command =['name' $command_name
    //'callback' => [$commandhandler, $commandinfo->getMethodName()],
    'callback' 'annotationcommand_adapter_process_command' 'annotated-command-callback'[$commandhandler $commandinfo->getMethodName()] 'commandfile' $commandfile 'category' $commandfile 'options'[] 'arguments'[] 'description' $commandinfo->getDescription() 'examples' $commandinfo->getExampleUsages() 'bootstrap' $bootstrap 'handle-remote-commands' $handle_remote_commands 'hidden' $hidden 'aliases' $aliases 'add-options-to-arguments' TRUE 'consolidation-output-formatters' TRUE 'consolidation-option-defaults' $commandinfo->options()->getValues() 'consolidation-arg-defaults' $commandinfo->arguments()->getValues()];
    $required_arguments = 0;
    foreach ($commandinfo->arguments()->getValues() as $arg => $default) {
      $command['arguments'][$arg] = $commandinfo->arguments()->getDescription($arg);
      if (!$commandinfo->arguments()->hasDefault($arg)) {
        ++$required_arguments;
      }
    }
    $command['required-arguments'] = $required_arguments;
    foreach ($commandinfo->options()->getValues() as $option => $default) {
      $description = $commandinfo->options()->getDescription($option);
      $command['options'][$option] =['description' $description];
      if (!empty($default)) {
        $command['options'][$option]['example-value'] = $default;
      }
      $fn = 'annotationcommand_adapter_alter_option_description_' . $option;
      if (function_exists($fn)) {
        $command['options'][$option] = $fn($command['options'][$option], $commandinfo, $default);
      }
      if ($commandinfo->getAnnotation('hidden-option') == $option) {
        $command['options'][$option]['hidden'] = TRUE;
      }
    }
    $command['annotations'] = $commandinfo->getAnnotations();
    // If the command has a '@return' annotation, then
    // remember information we will need to use the output formatter.
    $returnType = $commandinfo->getReturnType();
    if (isset($returnType)) {
      $command['return-type'] = $returnType;
    }
    if ($commandinfo->getAnnotation('allow-additional-options') !== null) {
      $command['allow-additional-options'] = TRUE;
    }
    $command += drush_command_defaults($command_name, $commandfile, $commandfile_path);
    $commands[$command_name] = $command;
  }
  $cache[$commandfile_path] = $commands;
  return $commands;
}