class AnnotatedCommandFactory implements AutomaticOptionsProviderInterface (View source)

The AnnotatedCommandFactory creates commands for your application.

Use with a Dependency Injection Container and the CommandFactory. Alternately, use the CommandFileDiscovery to find commandfiles, and then use AnnotatedCommandFactory::createCommandsFromClass() to create commands. See the README for more information.

Properties

static protected $ignoreCommandsInTraits

var bool

static protected $ignoreCommandsInParentClasses

var bool

protected $commandProcessor

var CommandProcessor

protected $listeners

var CommandCreationListenerInterface[]

protected $automaticOptionsProviderList

var AutomaticOptionsProvider[]

protected $includeAllPublicMethods

var boolean

protected $commandInfoAlterers

var CommandInfoAltererInterface

protected $dataStore

var SimpleCacheInterface

protected $ignoredCommandsRegexps

var string[]

Methods

static 
setIgnoreCommandsInTraits(bool $skipTraitFiles)

Typically, traits should not contain commands; however, some applications make use of this feature to package commands in libraries, so we must allow command files in traits to maintain backwards compatibility. Call this method to skip the parsing of trait files for a performance boost.

static 
setIgnoreCommandsInParentClasses(bool $ignoreCommandsInParentClasses)

Typically, commands should not be inherited from parent classes; however, some applications make use of this feature to package commands in libraries, so we must allow command files in traits to maintain backwards compatibility. Call this method to skip the parsing of trait files for a performance boost.

__construct()

No description

setCommandProcessor(CommandProcessor $commandProcessor)

No description

setIncludeAllPublicMethods($includeAllPublicMethods)

Set the 'include all public methods flag'. If true (the default), then every public method of each commandFile will be used to create commands.

getIncludeAllPublicMethods()

No description

hookManager()

No description

addListener(CommandCreationListenerInterface $listener)

Add a listener that is notified immediately before the command factory creates commands from a commandFile instance. This listener can use this opportunity to do more setup for the commandFile, and so on.

addListernerCallback(callable $listener)

Add a listener that's just a simple 'callable'.

addIgnoredCommandsRegexp(string $regex)

Add a regular expresion used to match methods names that will not be part of the final set of commands.

notify(object $commandFileInstance)

Call all command creation listeners

createCommandsFromClass($commandFileInstance, $includeAllPublicMethods = null)

n.b. This registers all hooks from the commandfile instance as a side-effect.

getCommandInfoListFromClass($commandFileInstance)

No description

storeCommandInfoListInCache($commandFileInstance, $commandInfoList)

No description

array
getCommandInfoListFromCache(mixed $commandFileInstance)

Get the command info list from the cache

bool
hasDataStore()

Check to see if this factory has a cache datastore.

type
setDataStore(mixed $dataStore)

Set a cache datastore for this factory. Any object with 'set' and 'get' methods is acceptable. The key is the classname being cached, and the value is a nested associative array of strings.

getDataStore()

Get the data store attached to this factory.

createCommandInfoListFromClass($commandFileInstance, $cachedCommandInfoList)

No description

createCommandInfo($commandFileInstance, $commandMethodName)

No description

createCommandsFromClassInfo($commandInfoList, $commandFileInstance, $includeAllPublicMethods = null)

No description

createSelectedCommandsFromClassInfo($commandInfoList, $commandFileInstance, callable $commandSelector)

No description

isMethodRecognizedAsCommand($commandInfo, $includeAllPublicMethods)

No description

isMethodRecognizedAsHook($commandInfo)

No description

filterCommandInfoList($commandInfoList, callable $commandSelector)

No description

static 
isCommandOrHookMethod($commandInfo, $includeAllPublicMethods)

No description

static 
isHookMethod($commandInfo)

No description

static 
isCommandMethod($commandInfo, $includeAllPublicMethods)

No description

registerCommandHooksFromClassInfo($commandInfoList, $commandFileInstance)

No description

registerCommandHook(CommandInfo $commandInfo, object $commandFileInstance)

Register a command hook given the CommandInfo for a method.

getNthWord($string, $n, $default = '', $delimiter = ' ')

No description

createCommand(CommandInfo $commandInfo, $commandFileInstance)

No description

alterCommandInfo(CommandInfo $commandInfo, $commandFileInstance)

Give plugins an opportunity to update the commandInfo

InputOption[]
callAutomaticOptionsProviders(CommandInfo $commandInfo)

Get the options that are implied by annotations, e.g.

InputOption[]
automaticOptions(CommandInfo $commandInfo)

Get the options that are implied by annotations, e.g.

Details

static setIgnoreCommandsInTraits(bool $skipTraitFiles)

Typically, traits should not contain commands; however, some applications make use of this feature to package commands in libraries, so we must allow command files in traits to maintain backwards compatibility. Call this method to skip the parsing of trait files for a performance boost.

In future versions, this property be removed, and commands will not be parsed from traits. Use Robo plugins as the preferred method of distributing shared commands.

Parameters

bool $skipTraitFiles

static setIgnoreCommandsInParentClasses(bool $ignoreCommandsInParentClasses)

Typically, commands should not be inherited from parent classes; however, some applications make use of this feature to package commands in libraries, so we must allow command files in traits to maintain backwards compatibility. Call this method to skip the parsing of trait files for a performance boost.

In future versions, this property be removed, and commands will not be parsed from traits. Use Robo plugins as the preferred method of distributing shared commands.

Parameters

bool $ignoreCommandsInParentClasses

__construct()

No description

setCommandProcessor(CommandProcessor $commandProcessor)

No description

Parameters

CommandProcessor $commandProcessor

CommandProcessor commandProcessor()

No description

Return Value

CommandProcessor

setIncludeAllPublicMethods($includeAllPublicMethods)

Set the 'include all public methods flag'. If true (the default), then every public method of each commandFile will be used to create commands.

If it is false, then only those public methods annotated with @command or @name (deprecated) will be used to create commands.

Parameters

$includeAllPublicMethods

getIncludeAllPublicMethods()

No description

HookManager hookManager()

No description

Return Value

HookManager

addListener(CommandCreationListenerInterface $listener)

Add a listener that is notified immediately before the command factory creates commands from a commandFile instance. This listener can use this opportunity to do more setup for the commandFile, and so on.

Parameters

CommandCreationListenerInterface $listener

addListernerCallback(callable $listener)

Add a listener that's just a simple 'callable'.

Parameters

callable $listener

addIgnoredCommandsRegexp(string $regex)

Add a regular expresion used to match methods names that will not be part of the final set of commands.

Parameters

string $regex

protected notify(object $commandFileInstance)

Call all command creation listeners

Parameters

object $commandFileInstance

addAutomaticOptionProvider(AutomaticOptionsProviderInterface $optionsProvider)

No description

Parameters

AutomaticOptionsProviderInterface $optionsProvider

addCommandInfoAlterer(CommandInfoAltererInterface $alterer)

No description

Parameters

CommandInfoAltererInterface $alterer

createCommandsFromClass($commandFileInstance, $includeAllPublicMethods = null)

n.b. This registers all hooks from the commandfile instance as a side-effect.

Parameters

$commandFileInstance
$includeAllPublicMethods

getCommandInfoListFromClass($commandFileInstance)

No description

Parameters

$commandFileInstance

protected storeCommandInfoListInCache($commandFileInstance, $commandInfoList)

No description

Parameters

$commandFileInstance
$commandInfoList

protected array getCommandInfoListFromCache(mixed $commandFileInstance)

Get the command info list from the cache

Parameters

mixed $commandFileInstance

Return Value

array

bool hasDataStore()

Check to see if this factory has a cache datastore.

Return Value

bool

type setDataStore(mixed $dataStore)

Set a cache datastore for this factory. Any object with 'set' and 'get' methods is acceptable. The key is the classname being cached, and the value is a nested associative array of strings.

TODO: Typehint this to SimpleCacheInterface

This is not done currently to allow clients to use a generic cache store that does not itself depend on the annotated-command library.

Parameters

mixed $dataStore

Return Value

type

getDataStore()

Get the data store attached to this factory.

protected createCommandInfoListFromClass($commandFileInstance, $cachedCommandInfoList)

No description

Parameters

$commandFileInstance
$cachedCommandInfoList

createCommandInfo($commandFileInstance, $commandMethodName)

No description

Parameters

$commandFileInstance
$commandMethodName

createCommandsFromClassInfo($commandInfoList, $commandFileInstance, $includeAllPublicMethods = null)

No description

Parameters

$commandInfoList
$commandFileInstance
$includeAllPublicMethods

createSelectedCommandsFromClassInfo($commandInfoList, $commandFileInstance, callable $commandSelector)

No description

Parameters

$commandInfoList
$commandFileInstance
callable $commandSelector

protected isMethodRecognizedAsCommand($commandInfo, $includeAllPublicMethods)

No description

Parameters

$commandInfo
$includeAllPublicMethods

protected isMethodRecognizedAsHook($commandInfo)

No description

Parameters

$commandInfo

protected filterCommandInfoList($commandInfoList, callable $commandSelector)

No description

Parameters

$commandInfoList
callable $commandSelector

static isCommandOrHookMethod($commandInfo, $includeAllPublicMethods)

No description

Parameters

$commandInfo
$includeAllPublicMethods

static isHookMethod($commandInfo)

No description

Parameters

$commandInfo

static isCommandMethod($commandInfo, $includeAllPublicMethods)

No description

Parameters

$commandInfo
$includeAllPublicMethods

registerCommandHooksFromClassInfo($commandInfoList, $commandFileInstance)

No description

Parameters

$commandInfoList
$commandFileInstance

registerCommandHook(CommandInfo $commandInfo, object $commandFileInstance)

Register a command hook given the CommandInfo for a method.

The hook format is:

Parameters

CommandInfo $commandInfo

Information about the command hook method.

object $commandFileInstance

An instance of the CommandFile class.

protected getNthWord($string, $n, $default = '', $delimiter = ' ')

No description

Parameters

$string
$n
$default
$delimiter

createCommand(CommandInfo $commandInfo, $commandFileInstance)

No description

Parameters

CommandInfo $commandInfo
$commandFileInstance

alterCommandInfo(CommandInfo $commandInfo, $commandFileInstance)

Give plugins an opportunity to update the commandInfo

Parameters

CommandInfo $commandInfo
$commandFileInstance

InputOption[] callAutomaticOptionsProviders(CommandInfo $commandInfo)

Get the options that are implied by annotations, e.g.

@fields implies that there should be a --fields and a --format option.

Parameters

CommandInfo $commandInfo

Return Value

InputOption[]

InputOption[] automaticOptions(CommandInfo $commandInfo)

Get the options that are implied by annotations, e.g.

@fields implies that there should be a --fields and a --format option.

Parameters

CommandInfo $commandInfo

Return Value

InputOption[]