class RequestBuilder (View source)

Builds a CLI request object from the raw command call

Constants

ARGUMENT_MATCHING_EXPRESSION

This is used to parse the command line, when it's passed as a string

Properties

protected Environment $environment
protected ObjectManagerInterface $objectManager
protected PackageManager $packageManager
protected CommandManager $commandManager

Methods

void
injectEnvironment(Environment $environment)

No description

void
injectObjectManager(ObjectManagerInterface $objectManager)

No description

void
injectPackageManager(PackageManager $packageManager)

No description

void
injectCommandManager(CommandManager $commandManager)

No description

build(mixed $commandLine)

Builds a CLI request object from a command line.

array
parseRawCommandLineArguments(array $rawCommandLineArguments, string $controllerObjectName, string $controllerCommandName)

Takes an array of unparsed command line arguments and options and converts it separated by named arguments, options and unnamed arguments.

string
extractArgumentNameFromCommandLinePart(string $commandLinePart)

Extracts the option or argument name from the name / value pair of a command line.

mixed
getValueOfCurrentCommandLineOption(string $currentArgument, array $rawCommandLineArguments, string $expectedArgumentType)

Returns the value of the first argument of the given input array. Shifts the parsed argument off the array.

Details

void injectEnvironment(Environment $environment)

No description

Parameters

Environment $environment

Return Value

void

void injectObjectManager(ObjectManagerInterface $objectManager)

No description

Parameters

ObjectManagerInterface $objectManager

Return Value

void

void injectPackageManager(PackageManager $packageManager)

No description

Parameters

PackageManager $packageManager

Return Value

void

void injectCommandManager(CommandManager $commandManager)

No description

Parameters

CommandManager $commandManager

Return Value

void

Request build(mixed $commandLine)

Builds a CLI request object from a command line.

The given command line may be a string (e.g. "mypackage:foo do-that-thing --force") or an array consisting of the individual parts. The array must not include the script name (like in $argv) but start with command right away.

Parameters

mixed $commandLine

The command line, either as a string or as an array

Return Value

Request

The CLI request as an object

Exceptions

InvalidArgumentMixingException
InvalidArgumentNameException

protected array parseRawCommandLineArguments(array $rawCommandLineArguments, string $controllerObjectName, string $controllerCommandName)

Takes an array of unparsed command line arguments and options and converts it separated by named arguments, options and unnamed arguments.

Parameters

array $rawCommandLineArguments

The unparsed command parts (such as "--foo") as an array

string $controllerObjectName

Object name of the designated command controller

string $controllerCommandName

Command name of the recognized command (ie. method name without "Command" suffix)

Return Value

array

All and exceeding command line arguments

Exceptions

InvalidArgumentMixingException

protected string extractArgumentNameFromCommandLinePart(string $commandLinePart)

Extracts the option or argument name from the name / value pair of a command line.

Parameters

string $commandLinePart

Part of the command line, e.g. "my-important-option=SomeInterestingValue"

Return Value

string

The lowercased argument name, e.g. "myimportantoption"

protected mixed getValueOfCurrentCommandLineOption(string $currentArgument, array $rawCommandLineArguments, string $expectedArgumentType)

Returns the value of the first argument of the given input array. Shifts the parsed argument off the array.

Parameters

string $currentArgument

The current argument

array $rawCommandLineArguments

Array of the remaining command line arguments

string $expectedArgumentType

The expected type of the current argument, because booleans get special attention

Return Value

mixed

The value of the first argument