Documentation

Package extends Base

Class Package.

Command package of the application. Build the Phar application from 3 sources (in order of importance):

  • Console arguments
  • composer.json file
  • User input
Tags
author

MacFJA

license

MIT

Table of Contents

Properties

$defaultName  : string|null
$ioStyle  : SymfonyStyle
The Symfony Style Input/Output
$aliases  : mixed
$application  : mixed
$applicationDefinitionMerged  : mixed
$applicationDefinitionMergedWithArgs  : mixed
$code  : mixed
$definition  : mixed
$description  : mixed
$help  : mixed
$helperSet  : mixed
$hidden  : mixed
$ignoreValidationErrors  : mixed
$name  : mixed
$processTitle  : mixed
$synopsis  : mixed
$usages  : mixed

Methods

__construct()  : mixed
addArgument()  : $this
Adds an argument.
addOption()  : $this
Adds an option.
addUsage()  : $this
Add a command usage example.
getAliases()  : array<string|int, mixed>
Returns the aliases for the command.
getApplication()  : Application|null
Gets the application instance for this command.
getDefaultName()  : string|null
getDefinition()  : InputDefinition
Gets the InputDefinition attached to this Command.
getDescription()  : string
Returns the description for the command.
getHelp()  : string
Returns the help for the command.
getHelper()  : mixed
Gets a helper instance by name.
getHelperSet()  : HelperSet|null
Gets the helper set.
getName()  : string|null
Returns the command name.
getNativeDefinition()  : InputDefinition
Gets the InputDefinition to be used to create representations of this Command.
getProcessedHelp()  : string
Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.
getSynopsis()  : string
Returns the synopsis for the command.
getUsages()  : array<string|int, mixed>
Returns alternative usages of the command.
ignoreValidationErrors()  : mixed
Ignores validation errors.
isEnabled()  : bool
Checks whether the command is enabled or not in the current environment.
isHidden()  : bool
mergeApplicationDefinition()  : mixed
Merges the application definition with the command definition.
run()  : int
Runs the command.
setAliases()  : $this
Sets the aliases for the command.
setApplication()  : mixed
setCode()  : $this
Sets the code to execute when running this command.
setDefinition()  : $this
Sets an array of argument and option instances.
setDescription()  : $this
Sets the description for the command.
setHelp()  : $this
Sets the help for the command.
setHelperSet()  : mixed
setHidden()  : $this
setIo()  : void
Set the Symfony Inout/Output style
setName()  : $this
Sets the name of the command.
setProcessTitle()  : $this
Sets the process title of the command.
askComposer()  : string
Prompt the user to select the project's composer.json
askCompression()  : string
Prompt to the user the compression option (default to None)
askEntryPoint()  : string
Prompt to the user the entry (stub) file. It's the file that launch the application
askInclude()  : array<string|int, mixed>
Do nothing.
askIncludeDev()  : string
Prompt to the user the compression option (default to None)
askOutputDir()  : string
Prompt to the user the path where to output the Phar archive
askPharName()  : string
Prompt to the user the file name of the Phar (default to "app.phar")
askSkipShebang()  : bool
Prompt to the user the skip shebang flag.
codeHelpParagraph()  : string
Format code to be displayed in CLI help
configure()  : void
Configure the command (name, arguments and descriptions)
execute()  : void
Execute the command.
getFunctionName()  : string
Get the function name for ask or validate action for a specific data
initialize()  : mixed
Initializes the command after the input has been bound and before the input is validated.
interact()  : mixed
Interacts with the user.
readParamComposerAsk()  : mixed
Read the CLI argument, if not found read the Composer.json file, if not provided in composer.json, ask the user
readSpecialParams()  : void
Read and transform special option
throwErrorForNoInteractiveMode()  : void
Display an error that indicate that the application is in a no interactive mode and require an input.
validateComposer()  : string
Validate if the value is a valid composer.json file path.
validateCompression()  : string
Validate if the value is a valid compression.
validateEntryPoint()  : string
Validate if the value is a valid file path.
validateInclude()  : array<string|int, mixed>
Validate if the value are valid directories
validateIncludeDev()  : bool
Validate if the value is a valid flag for including dev Do nothing because a flag as only 2 possible value which are, by definition, valid
validateOutputDir()  : string
Validate if the value is a valid output directory.
validatePharName()  : string
Validate if the value is a valid filename.
validateSkipShebang()  : bool
Validates the skip shebang flag by casting it bool.
readParamComposerAskName()  : mixed
Read the CLI argument for the phar name, if not found read the Composer.json file, if not provided in composer.json, ask the user
readParamComposerIncludeDev()  : bool
Read the CLI argument for the including dev code and dev packages, if not found read the Composer.json file.
readParamComposerSkipShebang()  : bool
Read the CLI argument for the skip shebang, if not found read the Composer.json file, if not provided in composer.json, choose "false"
validateName()  : mixed
Validates a command name.

Properties

$defaultName

protected static string|null $defaultName

The default command name

$aliases

private mixed $aliases = []

$application

private mixed $application

$applicationDefinitionMerged

private mixed $applicationDefinitionMerged = false

$applicationDefinitionMergedWithArgs

private mixed $applicationDefinitionMergedWithArgs = false

$definition

private mixed $definition

$description

private mixed $description = ''

$hidden

private mixed $hidden = false

$ignoreValidationErrors

private mixed $ignoreValidationErrors = false

$processTitle

private mixed $processTitle

$synopsis

private mixed $synopsis = []

Methods

__construct()

public __construct([string|null $name = null ]) : mixed
Parameters
$name : string|null = null

The name of the command; passing null means it must be set in configure()

Tags
throws
LogicException

When the command name is empty

addArgument()

Adds an argument.

public addArgument(string $name[, int|null $mode = null ][, string $description = '' ][, mixed $default = null ]) : $this
Parameters
$name : string

The argument name

$mode : int|null = null

The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL

$description : string = ''

A description text

$default : mixed = null

The default value (for InputArgument::OPTIONAL mode only)

Tags
throws
InvalidArgumentException

When argument mode is not valid

Return values
$this

addOption()

Adds an option.

public addOption(string $name[, string|array<string|int, mixed>|null $shortcut = null ][, int|null $mode = null ][, string $description = '' ][, mixed $default = null ]) : $this
Parameters
$name : string

The option name

$shortcut : string|array<string|int, mixed>|null = null

The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts

$mode : int|null = null

The option mode: One of the InputOption::VALUE_* constants

$description : string = ''

A description text

$default : mixed = null

The default value (must be null for InputOption::VALUE_NONE)

Tags
throws
InvalidArgumentException

If option mode is invalid or incompatible

Return values
$this

addUsage()

Add a command usage example.

public addUsage(string $usage) : $this
Parameters
$usage : string

The usage, it'll be prefixed with the command name

Return values
$this

getAliases()

Returns the aliases for the command.

public getAliases() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array of aliases for the command

getApplication()

Gets the application instance for this command.

public getApplication() : Application|null
Return values
Application|null

An Application instance

getDefaultName()

public static getDefaultName() : string|null
Return values
string|null

The default command name or null when no default name is set

getDescription()

Returns the description for the command.

public getDescription() : string
Return values
string

The description for the command

getHelp()

Returns the help for the command.

public getHelp() : string
Return values
string

The help for the command

getHelper()

Gets a helper instance by name.

public getHelper(string $name) : mixed
Parameters
$name : string

The helper name

Tags
throws
LogicException

if no HelperSet is defined

throws
InvalidArgumentException

if the helper is not defined

Return values
mixed

The helper value

getHelperSet()

Gets the helper set.

public getHelperSet() : HelperSet|null
Return values
HelperSet|null

A HelperSet instance

getName()

Returns the command name.

public getName() : string|null
Return values
string|null

getNativeDefinition()

Gets the InputDefinition to be used to create representations of this Command.

public getNativeDefinition() : InputDefinition

Can be overridden to provide the original command representation when it would otherwise be changed by merging with the application InputDefinition.

This method is not part of public API and should not be used directly.

Return values
InputDefinition

An InputDefinition instance

getProcessedHelp()

Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.

public getProcessedHelp() : string
Return values
string

The processed help for the command

getSynopsis()

Returns the synopsis for the command.

public getSynopsis([bool $short = false ]) : string
Parameters
$short : bool = false

Whether to show the short version of the synopsis (with options folded) or not

Return values
string

The synopsis

getUsages()

Returns alternative usages of the command.

public getUsages() : array<string|int, mixed>
Return values
array<string|int, mixed>

ignoreValidationErrors()

Ignores validation errors.

public ignoreValidationErrors() : mixed

This is mainly useful for the help command.

isEnabled()

Checks whether the command is enabled or not in the current environment.

public isEnabled() : bool

Override this to check for x or y and return false if the command can not run properly under the current conditions.

Return values
bool

isHidden()

public isHidden() : bool
Return values
bool

whether the command should be publicly shown or not

mergeApplicationDefinition()

Merges the application definition with the command definition.

public mergeApplicationDefinition([bool $mergeArgs = true ]) : mixed

This method is not part of public API and should not be used directly.

Parameters
$mergeArgs : bool = true

Whether to merge or not the Application definition arguments to Command definition arguments

run()

Runs the command.

public run(InputInterface $input, OutputInterface $output) : int

The code to execute is either defined directly with the setCode() method or by overriding the execute() method in a sub-class.

Parameters
$input : InputInterface
$output : OutputInterface
Tags
throws
ExceptionInterface

When input binding fails. Bypass this by calling .

see
setCode()
see
execute()
Return values
int

The command exit code

setAliases()

Sets the aliases for the command.

public setAliases(array<string|int, string> $aliases) : $this
Parameters
$aliases : array<string|int, string>

An array of aliases for the command

Tags
throws
InvalidArgumentException

When an alias is invalid

Return values
$this

setCode()

Sets the code to execute when running this command.

public setCode(callable $code) : $this

If this method is used, it overrides the code defined in the execute() method.

Parameters
$code : callable

A callable(InputInterface $input, OutputInterface $output)

Tags
throws
InvalidArgumentException
see
execute()
Return values
$this

setDefinition()

Sets an array of argument and option instances.

public setDefinition(array<string|int, mixed>|InputDefinition $definition) : $this
Parameters
$definition : array<string|int, mixed>|InputDefinition

An array of argument and option instances or a definition instance

Return values
$this

setDescription()

Sets the description for the command.

public setDescription(string $description) : $this
Parameters
$description : string

The description for the command

Return values
$this

setHelp()

Sets the help for the command.

public setHelp(string $help) : $this
Parameters
$help : string

The help for the command

Return values
$this

setHidden()

public setHidden(bool $hidden) : $this
Parameters
$hidden : bool

Whether or not the command should be hidden from the list of commands

Return values
$this

setIo()

Set the Symfony Inout/Output style

public setIo(SymfonyStyle $ioStyle) : void
Parameters
$ioStyle : SymfonyStyle

The Symfony Style Input/Output

setName()

Sets the name of the command.

public setName(string $name) : $this

This method can set both the namespace and the name if you separate them by a colon (:)

$command->setName('foo:bar');
Parameters
$name : string

The command name

Tags
throws
InvalidArgumentException

When the name is invalid

Return values
$this

setProcessTitle()

Sets the process title of the command.

public setProcessTitle(string $title) : $this

This feature should be used only when creating a long process command, like a daemon.

Parameters
$title : string

The process title

Return values
$this

askCompression()

Prompt to the user the compression option (default to None)

protected askCompression() : string
Return values
string

The compression of the Phar

askEntryPoint()

Prompt to the user the entry (stub) file. It's the file that launch the application

protected askEntryPoint(InputInterface $input, OutputInterface $output, string $baseDir) : string
Parameters
$input : InputInterface

The CLI input interface (reading user input)

$output : OutputInterface

The CLI output interface (display message)

$baseDir : string

The path to the directory that contains the composer.json file

Tags
throws
InvalidArgumentException
throws
RuntimeException
throws
Exception
Return values
string

The path to the entry point of the application

askInclude()

Do nothing.

protected askInclude(InputInterface $input, OutputInterface $output, string $baseDir) : array<string|int, mixed>

Normally prompt the user to add directory in the phar, but this option is only read in CLI param and composer.json.

Parameters
$input : InputInterface

The CLI input interface (reading user input)

$output : OutputInterface

The CLI output interface (display message)

$baseDir : string

The path to the directory that contains the composer.json file

Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter) -- Do nothing function

Return values
array<string|int, mixed>

An empty array

askIncludeDev()

Prompt to the user the compression option (default to None)

protected askIncludeDev() : string
Return values
string

The compression of the Phar

askOutputDir()

Prompt to the user the path where to output the Phar archive

protected askOutputDir(InputInterface $input, OutputInterface $output, string $baseDir) : string
Parameters
$input : InputInterface

The CLI input interface (reading user input)

$output : OutputInterface

The CLI output interface (display message)

$baseDir : string

The path to the directory that contains the composer.json file

Tags
throws
InvalidArgumentException
throws
RuntimeException
throws
Exception
Return values
string

The path to the output directory

askPharName()

Prompt to the user the file name of the Phar (default to "app.phar")

protected askPharName() : string
Return values
string

The name of the Phar file

askSkipShebang()

Prompt to the user the skip shebang flag.

protected askSkipShebang() : bool
Return values
bool

The skip shebang flag

codeHelpParagraph()

Format code to be displayed in CLI help

protected codeHelpParagraph(string $code) : string
Parameters
$code : string

The text to format

Return values
string

A formatted help text

configure()

Configure the command (name, arguments and descriptions)

protected configure() : void
Tags
throws
InvalidArgumentException

When the name is invalid

getFunctionName()

Get the function name for ask or validate action for a specific data

protected getFunctionName(string $type, string $dataName) : string
Parameters
$type : string

The function type to get (ask or validate)

$dataName : string

The name of the data (hyphen word separated)

Return values
string

The formatted function name

interact()

Interacts with the user.

protected interact(InputInterface $input, OutputInterface $output) : mixed

This method is executed before the InputDefinition is validated. This means that this is the only place where the command can interactively ask for values of missing required arguments.

Parameters
$input : InputInterface
$output : OutputInterface

readParamComposerAsk()

Read the CLI argument, if not found read the Composer.json file, if not provided in composer.json, ask the user

protected readParamComposerAsk(array<string|int, mixed> $composerData, InputInterface $input, OutputInterface $output, string $baseDir, string $dataName) : mixed
Parameters
$composerData : array<string|int, mixed>

The composer.json extra data content

$input : InputInterface

The CLI input interface (reading user input)

$output : OutputInterface

The CLI output interface (display message)

$baseDir : string

The path to the directory that contains the composer.json file

$dataName : string

The name of the data (hyphen word separated)

Return values
mixed

The value of $dataName

readSpecialParams()

Read and transform special option

protected readSpecialParams(InputInterface $input) : void
Parameters
$input : InputInterface

The CLI input interface (reading user input)

throwErrorForNoInteractiveMode()

Display an error that indicate that the application is in a no interactive mode and require an input.

protected throwErrorForNoInteractiveMode([string|null $missedOption = null ]) : void

Exit code: 6

Parameters
$missedOption : string|null = null

The name of the missing option

Tags
SuppressWarnings

(PHPMD.ExitExpression) -- Normal/Wanted behavior

validateComposer()

Validate if the value is a valid composer.json file path.

protected validateComposer(string $value) : string

Exit code: 1

Parameters
$value : string

A path to a composer file

Tags
SuppressWarnings

(PHPMD.ExitExpression) -- Normal/Wanted behavior

Return values
string

The validated path to composer.json

validateCompression()

Validate if the value is a valid compression.

protected validateCompression(string $value) : string

Do nothing because compression is valid in \MacFJA\PharBuilder\PharBuilder class

Parameters
$value : string

A compression format

Return values
string

The (not really) validated compression

validateEntryPoint()

Validate if the value is a valid file path.

protected validateEntryPoint(string $value) : string

Exit code: 2

Parameters
$value : string

A path to a file

Tags
SuppressWarnings

(PHPMD.ExitExpression) -- Normal/Wanted behavior

Return values
string

The validated path to the application entry point

validateInclude()

Validate if the value are valid directories

protected validateInclude(array<string|int, mixed> $value) : array<string|int, mixed>
Parameters
$value : array<string|int, mixed>

List of path to directories

Return values
array<string|int, mixed>

List of directory path to include

validateIncludeDev()

Validate if the value is a valid flag for including dev Do nothing because a flag as only 2 possible value which are, by definition, valid

protected validateIncludeDev(bool $value) : bool
Parameters
$value : bool

The flag about including dev code and packages

Return values
bool

The (not really) validated flag

validateOutputDir()

Validate if the value is a valid output directory.

protected validateOutputDir(string $value) : string

Exit code: 3

Parameters
$value : string

A path to a directory

Tags
SuppressWarnings

(PHPMD.ExitExpression) -- Normal/Wanted behavior

Return values
string

The validated output directory path

validatePharName()

Validate if the value is a valid filename.

protected validatePharName(string $value) : string

Exit code: 4

Parameters
$value : string

A filename

Tags
SuppressWarnings

(PHPMD.ExitExpression) -- Normal/Wanted behavior

Return values
string

A validated filename

validateSkipShebang()

Validates the skip shebang flag by casting it bool.

protected validateSkipShebang(bool $value) : bool
Parameters
$value : bool

The skip shebang flag

Return values
bool

skip shebang flag

readParamComposerAskName()

Read the CLI argument for the phar name, if not found read the Composer.json file, if not provided in composer.json, ask the user

private readParamComposerAskName(array<string|int, mixed> $composerData, InputInterface $input) : mixed
Parameters
$composerData : array<string|int, mixed>

The composer.json extra data content

$input : InputInterface

The CLI input interface (reading user input)

Tags
throws
InvalidArgumentException
throws
RuntimeException
Return values
mixed

The name of the phar

readParamComposerIncludeDev()

Read the CLI argument for the including dev code and dev packages, if not found read the Composer.json file.

private readParamComposerIncludeDev(array<string|int, mixed> $composerData, InputInterface $input) : bool
Parameters
$composerData : array<string|int, mixed>

The composer.json extra data content

$input : InputInterface

The CLI input interface (reading user input)

Return values
bool

The include-dev flag

readParamComposerSkipShebang()

Read the CLI argument for the skip shebang, if not found read the Composer.json file, if not provided in composer.json, choose "false"

private readParamComposerSkipShebang(array<string|int, mixed> $composerData, InputInterface $input) : bool
Parameters
$composerData : array<string|int, mixed>

The composer.json extra data content

$input : InputInterface

The CLI input interface (reading user input)

Return values
bool

The skip-shebang flag

validateName()

Validates a command name.

private validateName(string $name) : mixed

It must be non-empty and parts can optionally be separated by ":".

Parameters
$name : string
Tags
throws
InvalidArgumentException

When the name is invalid


        
On this page

Search results