CommandInfo
class CommandInfo (View source)
Given a class and method name, parse the annotations in the DocBlock comment, and provide accessor methods for all of the elements that are needed to create a Symfony Console Command.
Note that the name of this class is now somewhat of a misnomer, as we now use it to hold annotation data for hooks as well as commands. It would probably be better to rename this to MethodInfo at some point.
Constants
SERIALIZATION_SCHEMA_VERSION |
Serialization schema version. Incremented every time the serialization schema changes. |
Properties
protected ReflectionMethod | $reflection | ||
protected bool | $docBlockIsParsed | ||
protected bool | $parsingInProgress | ||
protected string | $name | ||
protected string | $description | ||
protected string | $help | ||
protected DefaultsWithDescriptions | $options | ||
protected DefaultsWithDescriptions | $arguments | ||
protected array | $exampleUsage | ||
protected AnnotationData | $otherAnnotations | ||
protected array | $aliases | ||
protected InputOption[] | $inputOptions | ||
protected string | $methodName | ||
protected string | $returnType | ||
protected string[] | $injectedClasses | ||
protected bool[] | $parameterMap | ||
protected bool | $simpleOptionParametersAllowed |
Methods
Create a new CommandInfo class for a particular method of a class.
No description
No description
No description
No description
Recover the method name provided to the constructor.
Return the primary name for this command.
Set the primary name for this command.
Return whether or not this method represents a valid command or hook.
If higher-level code decides that this CommandInfo is not interesting or useful (if it is not a command method or a hook method), then we will mark it as invalid to prevent it from being created as a command.
No description
No description
No description
No description
No description
Get any annotations included in the docblock comment for the implementation method of this command that are not already handled by the primary methods of this class.
Replace the annotation data.
Get any annotations included in the docblock comment, also including default values such as @command. We add in the default @command annotation late, and only in a copy of the annotation data because we use the existance of a @command to indicate that this CommandInfo is a command, and not a hook or anything else.
Return a specific named annotation for this command as a list.
Return a specific named annotation for this command as a string.
Check to see if the specified annotation exists for this command.
Save any tag that we do not explicitly recognize in the 'otherAnnotations' map.
Remove an annotation that was previoudly set.
Get the synopsis of the command (~first line).
Set the command description.
Determine if help was provided for this command info
Get the help text of the command (the description)
Set the help text for this command.
Return the list of aliases for this command.
Set aliases that can be used in place of the command's primary name.
Get hidden status for the command.
Set hidden status. List command omits hidden commands.
Return the examples for this command. This is @usage instead of
Add an example usage for this command.
Overwrite all example usages
Return the topics for this command.
Return the list of refleaction parameters.
Descriptions of commandline arguements for this command.
Descriptions of commandline options for this command.
Get the inputOptions for the options associated with this CommandInfo object, e.g. via @option annotations, or from $options = ['someoption' => 'defaultvalue'] in the command method parameter list.
No description
No description
An option might have a name such as 'silent|s'. In this instance, we will allow the @option or @default tag to reference the option only by name (e.g. 'silent' or 's' instead of 'silent|s').
No description
No description
No description
No description
No description
No description
No description
Examine the parameters of the method for this command, and build a list of commandline arguments for them.
Examine the provided parameter, and determine whether it is a parameter that will be filled in with a positional commandline argument.
Examine the parameters of the method for this command, and determine the disposition of the options from them.
Determine if the last argument contains $options.
Helper; determine if an array is associative or not. An array is not associative if its keys are numeric, and numbered sequentially from zero. All other arrays are considered to be associative.
Convert from a method name to the corresponding command name. A method 'fooBar' will become 'foo:bar', and 'fooBarBazBoz' will become 'foo:bar-baz-boz'.
Convert an argument name from snake_case or camelCase to a hyphenated-string.
Convert a camelCase string to a snake_case string.
Guard against invalid usage of CommandInfo during parsing.
Parse the docBlock comment for this command, and set the fields of this class with the data thereby obtained.
Given a list that might be 'a b c' or 'a, b, c' or 'a,b,c', convert the data into the last of these forms.
Details
__construct(string|mixed $classNameOrInstance, string $methodName, array $cache = [])
deprecated
deprecated
Create a new CommandInfo class for a particular method of a class.
static
create($classNameOrInstance, $methodName)
No description
static
deserialize($cache)
No description
cachedFileIsModified($cache)
No description
protected
constructFromClassAndMethod($classNameOrInstance, $methodName)
No description
string
getMethodName()
Recover the method name provided to the constructor.
string
getName()
Return the primary name for this command.
setName(string $name)
Set the primary name for this command.
valid()
Return whether or not this method represents a valid command or hook.
invalidate()
If higher-level code decides that this CommandInfo is not interesting or useful (if it is not a command method or a hook method), then we will mark it as invalid to prevent it from being created as a command.
We still cache a placeholder record for invalid methods, so that we do not need to re-parse the method again later simply to determine that it is invalid.
getParameterMap()
No description
getReturnType()
No description
getInjectedClasses()
No description
setInjectedClasses($injectedClasses)
No description
setReturnType($returnType)
No description
AnnotationData
getRawAnnotations()
Get any annotations included in the docblock comment for the implementation method of this command that are not already handled by the primary methods of this class.
replaceRawAnnotations($annotationData)
Replace the annotation data.
AnnotationData
getAnnotations()
Get any annotations included in the docblock comment, also including default values such as @command. We add in the default @command annotation late, and only in a copy of the annotation data because we use the existance of a @command to indicate that this CommandInfo is a command, and not a hook or anything else.
array|null
getAnnotationList(string $name)
Return a specific named annotation for this command as a list.
string|null
getAnnotation(string $name)
Return a specific named annotation for this command as a string.
bool
hasAnnotation(string $annotation)
Check to see if the specified annotation exists for this command.
addAnnotation($name, $content)
Save any tag that we do not explicitly recognize in the 'otherAnnotations' map.
removeAnnotation($name)
Remove an annotation that was previoudly set.
string
getDescription()
Get the synopsis of the command (~first line).
setDescription(string $description)
Set the command description.
hasHelp()
Determine if help was provided for this command info
getHelp()
Get the help text of the command (the description)
setHelp(string $help)
Set the help text for this command.
string[]
getAliases()
Return the list of aliases for this command.
setAliases(string|string[] $aliases)
Set aliases that can be used in place of the command's primary name.
bool
getHidden()
Get hidden status for the command.
setHidden(bool $hidden)
Set hidden status. List command omits hidden commands.
string[]
getExampleUsages()
Return the examples for this command. This is @usage instead of
setExampleUsage(string $usage, string $description)
Add an example usage for this command.
replaceExampleUsages($usages)
Overwrite all example usages
string[]
getTopics()
Return the topics for this command.
ReflectionParameter[]
getParameters()
Return the list of refleaction parameters.
DefaultsWithDescriptions
arguments()
Descriptions of commandline arguements for this command.
DefaultsWithDescriptions
options()
Descriptions of commandline options for this command.
InputOption[]
inputOptions()
Get the inputOptions for the options associated with this CommandInfo object, e.g. via @option annotations, or from $options = ['someoption' => 'defaultvalue'] in the command method parameter list.
protected
addImplicitNoOptions()
No description
protected
createInputOptions()
No description
string
findMatchingOption(string $optionName)
An option might have a name such as 'silent|s'. In this instance, we will allow the @option or @default tag to reference the option only by name (e.g. 'silent' or 's' instead of 'silent|s').
addArgumentDescription($name, $description, $suggestedValues = [])
No description
addOption($name, $description, $suggestedValues = [], $defaultValue = null)
No description
addOptionDescription($name, $description, $suggestedValues = [], $defaultValue = null)
deprecated
deprecated
No description
protected
addOptionOrArgumentDescription(DefaultsWithDescriptions $set, $variableName, $description, $suggestedValues = [], $defaultFromParameter = null)
No description
protected
splitOutDefault($description)
No description
protected string
findOptionAmongAlternatives(string $optionName)
No description
protected string|null
findExistingOption(string $optionName)
No description
protected array
determineAgumentClassifications()
Examine the parameters of the method for this command, and build a list of commandline arguments for them.
protected
addParameterToResult($result, $param)
Examine the provided parameter, and determine whether it is a parameter that will be filled in with a positional commandline argument.
protected array
determineOptionsFromParameters()
Examine the parameters of the method for this command, and determine the disposition of the options from them.
protected
lastParameterIsOptionsArray()
Determine if the last argument contains $options.
Two forms indicate options:
- $options = []
- $options = ['flag' => 'default-value']
Any other form, including array $foo
, is not options.
protected bool
isAssoc(array $arr)
Helper; determine if an array is associative or not. An array is not associative if its keys are numeric, and numbered sequentially from zero. All other arrays are considered to be associative.
protected string
convertName(string $camel)
Convert from a method name to the corresponding command name. A method 'fooBar' will become 'foo:bar', and 'fooBarBazBoz' will become 'foo:bar-baz-boz'.
protected
convertArgumentName($camel)
Convert an argument name from snake_case or camelCase to a hyphenated-string.
protected
camelToSnake($camel, $splitter = '_')
Convert a camelCase string to a snake_case string.
protected
requireConsistentState()
Guard against invalid usage of CommandInfo during parsing.
protected
parseDocBlock()
Parse the docBlock comment for this command, and set the fields of this class with the data thereby obtained.
static protected
convertListToCommaSeparated($text)
Given a list that might be 'a b c' or 'a, b, c' or 'a,b,c', convert the data into the last of these forms.