Documentation

OctoberEnv extends Command
in package

Console command to convert configuration to use .env files.

This creates an .env file with some default configuration values, it also converts the existing PHP-based configuration files to use the env function for values.

Tags
author

Alexey Bobkov, Samuel Georges

Table of Contents

$config  : mixed
The current config cursor.
$connection  : mixed
The current database connection cursor.
$defaultName  : string|null
$description  : string
The console command description.
$input  : InputInterface
The input interface implementation.
$laravel  : Application
The Laravel application instance.
$macros  : array<string|int, mixed>
The registered string macros.
$name  : string
The console command name.
$output  : OutputStyle
The output interface implementation.
$protectedKeys  : array<string|int, mixed>
$signature  : string
The name and signature of the console command.
$verbosity  : int
The default verbosity of output commands.
$verbosityMap  : array<string|int, mixed>
The mapping between human readable verbosity levels and Symfony's OutputInterface.
$aliases  : mixed
$application  : mixed
$applicationDefinitionMerged  : mixed
$applicationDefinitionMergedWithArgs  : mixed
$code  : mixed
$definition  : mixed
$help  : mixed
$helperSet  : mixed
$hidden  : mixed
$ignoreValidationErrors  : mixed
$processTitle  : mixed
$synopsis  : mixed
$usages  : mixed
__call()  : mixed
Dynamically handle calls to the class.
__callStatic()  : mixed
Dynamically handle calls to the class.
__construct()  : mixed
addArgument()  : $this
Adds an argument.
addOption()  : $this
Adds an option.
addUsage()  : $this
Add a command usage example.
alert()  : void
Write a string in an alert box.
anticipate()  : string
Prompt the user for input with auto completion.
argument()  : string|array<string|int, mixed>
Get the value of a command argument.
arguments()  : array<string|int, mixed>
Get all of the arguments passed to the command.
ask()  : string
Prompt the user for input.
askWithCompletion()  : string
Prompt the user for input with auto completion.
call()  : int
Call another console command.
callSilent()  : int
Call another console command silently.
choice()  : string
Give the user a single choice from an array of answers.
comment()  : void
Write a string as comment output.
confirm()  : bool
Confirm a question with the user.
error()  : void
Write a string as error output.
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.
getLaravel()  : Application
Get the Laravel application instance.
getName()  : string|null
Returns the command name.
getNativeDefinition()  : InputDefinition
Gets the InputDefinition to be used to create representations of this Command.
getOutput()  : OutputInterface
Get the output implementation.
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.
handle()  : mixed
Execute the console command.
hasArgument()  : bool
Determine if the given argument is present.
hasMacro()  : bool
Checks if macro is registered.
hasOption()  : bool
Determine if the given option is present.
ignoreValidationErrors()  : mixed
Ignores validation errors.
info()  : void
Write a string as information output.
isEnabled()  : bool
Checks whether the command is enabled or not in the current environment.
isHidden()  : bool
line()  : void
Write a string as standard output.
macro()  : void
Register a custom macro.
mergeApplicationDefinition()  : mixed
Merges the application definition with the command definition.
mixin()  : void
Mix another object into the class.
option()  : string|array<string|int, mixed>
Get the value of a command option.
options()  : array<string|int, mixed>
Get all of the options passed to the command.
question()  : void
Write a string as question output.
run()  : int
Runs the command.
secret()  : string
Prompt the user for input but hide the answer from the console.
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()  : Command
setLaravel()  : void
Set the Laravel application instance.
setName()  : $this
Sets the name of the command.
setProcessTitle()  : $this
Sets the process title of the command.
table()  : void
Format input to textual table.
warn()  : void
Write a string as warning output.
buildCallback()  : Closure
buildPattern()  : string
config()  : array<string|int, mixed>
configToEnv()  : mixed
Replace config values with env() syntax
configure()  : mixed
Configures the current command.
configureUsingFluentDefinition()  : void
Configure the console command using a fluent definition.
context()  : array<string|int, mixed>
Get all of the context passed to the command.
createInputFromArguments()  : ArrayInput
Create an input instance from the given arguments.
databaseConfigValue()  : string
dbConfig()  : array<string|int, mixed>
envKeyExists()  : bool
envValue()  : string
execute()  : int|null
Executes the current command.
getArguments()  : array<string|int, mixed>
Get the console command arguments.
getOptions()  : array<string|int, mixed>
Get the console command options.
initialize()  : mixed
Initializes the command after the input has been bound and before the input is validated.
interact()  : mixed
Interacts with the user.
isEnv()  : bool
lines()  : array<string|int, mixed>
normalizeForConfig()  : string
Normalizes a value to be inserted into config files.
normalizeForEnv()  : string
Normalizes a value to be inserted into the .env file
overwriteConfig()  : mixed
Overwrite config file
parseConfigFile()  : string
Parse config file line by line
parseLine()  : mixed
parseVerbosity()  : int
Get the verbosity level in terms of Symfony's OutputInterface level.
readEnvFile()  : string
replaceConfigLine()  : mixed
replaceDbConfigLine()  : mixed
saveEnvSettings()  : mixed
setCurrentConnection()  : mixed
setVerbosity()  : void
Set the verbosity level.
specifyParameters()  : void
Specify the arguments and options on the command.
writeDbEnvSettings()  : mixed
writeToConfigFile()  : mixed
writeToEnv()  : mixed
validateName()  : mixed
Validates a command name.

Properties

$config

The current config cursor.

protected mixed $config

$connection

The current database connection cursor.

protected mixed $connection

$defaultName

protected static string|null $defaultName

The default command name

$description

The console command description.

protected string $description = 'Creates .env file with default configuration values.'

$macros

The registered string macros.

protected static array<string|int, mixed> $macros = []

$name

The console command name.

protected string $name = 'october:env'

$protectedKeys

protected array<string|int, mixed> $protectedKeys = ['APP_KEY', 'DB_USERNAME', 'DB_PASSWORD', 'MAIL_USERNAME', 'MAIL_PASSWORD', 'REDIS_PASSWORD']

The env keys that need to have their original values removed from the config files

$signature

The name and signature of the console command.

protected string $signature

$verbosity

The default verbosity of output commands.

protected int $verbosity = SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_NORMAL

$verbosityMap

The mapping between human readable verbosity levels and Symfony's OutputInterface.

protected array<string|int, mixed> $verbosityMap = ['v' => SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_VERBOSE, 'vv' => SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_VERY_VERBOSE, 'vvv' => SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_DEBUG, 'quiet' => SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_QUIET, 'normal' => SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_NORMAL]

$aliases

private mixed $aliases = []

$application

private mixed $application

$applicationDefinitionMerged

private mixed $applicationDefinitionMerged = false

$applicationDefinitionMergedWithArgs

private mixed $applicationDefinitionMergedWithArgs = false

$definition

private mixed $definition

$hidden

private mixed $hidden = false

$ignoreValidationErrors

private mixed $ignoreValidationErrors = false

$processTitle

private mixed $processTitle

$synopsis

private mixed $synopsis = []

Methods

__call()

Dynamically handle calls to the class.

public __call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

__callStatic()

Dynamically handle calls to the class.

public static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

__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

Return values
mixed

addArgument()

Adds an argument.

public addArgument(string $name[, int|null $mode = null ][, string $description = '' ][, string|array<string|int, string>|null $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 : string|array<string|int, string>|null = 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 = '' ][, string|array<string|int, string>|int|bool|null $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 : string|array<string|int, string>|int|bool|null = 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

alert()

Write a string in an alert box.

public alert(string $string) : void
Parameters
$string : string
Return values
void

anticipate()

Prompt the user for input with auto completion.

public anticipate(string $question, array<string|int, mixed> $choices[, string $default = null ]) : string
Parameters
$question : string
$choices : array<string|int, mixed>
$default : string = null
Return values
string

argument()

Get the value of a command argument.

public argument([string|null $key = null ]) : string|array<string|int, mixed>
Parameters
$key : string|null = null
Return values
string|array<string|int, mixed>

arguments()

Get all of the arguments passed to the command.

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

ask()

Prompt the user for input.

public ask(string $question[, string $default = null ]) : string
Parameters
$question : string
$default : string = null
Return values
string

askWithCompletion()

Prompt the user for input with auto completion.

public askWithCompletion(string $question, array<string|int, mixed> $choices[, string $default = null ]) : string
Parameters
$question : string
$choices : array<string|int, mixed>
$default : string = null
Return values
string

call()

Call another console command.

public call(string $command[, array<string|int, mixed> $arguments = [] ]) : int
Parameters
$command : string
$arguments : array<string|int, mixed> = []
Return values
int

callSilent()

Call another console command silently.

public callSilent(string $command[, array<string|int, mixed> $arguments = [] ]) : int
Parameters
$command : string
$arguments : array<string|int, mixed> = []
Return values
int

choice()

Give the user a single choice from an array of answers.

public choice(string $question, array<string|int, mixed> $choices[, string $default = null ][, mixed $attempts = null ][, bool $multiple = null ]) : string
Parameters
$question : string
$choices : array<string|int, mixed>
$default : string = null
$attempts : mixed = null
$multiple : bool = null
Return values
string

comment()

Write a string as comment output.

public comment(string $string[, null|int|string $verbosity = null ]) : void
Parameters
$string : string
$verbosity : null|int|string = null
Return values
void

confirm()

Confirm a question with the user.

public confirm(string $question[, bool $default = false ]) : bool
Parameters
$question : string
$default : bool = false
Return values
bool

error()

Write a string as error output.

public error(string $string[, null|int|string $verbosity = null ]) : void
Parameters
$string : string
$verbosity : null|int|string = null
Return values
void

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>

handle()

Execute the console command.

public handle() : mixed
Return values
mixed

hasArgument()

Determine if the given argument is present.

public hasArgument(string|int $name) : bool
Parameters
$name : string|int
Return values
bool

hasMacro()

Checks if macro is registered.

public static hasMacro(string $name) : bool
Parameters
$name : string
Return values
bool

hasOption()

Determine if the given option is present.

public hasOption(string $name) : bool
Parameters
$name : string
Return values
bool

ignoreValidationErrors()

Ignores validation errors.

public ignoreValidationErrors() : mixed

This is mainly useful for the help command.

Return values
mixed

info()

Write a string as information output.

public info(string $string[, null|int|string $verbosity = null ]) : void
Parameters
$string : string
$verbosity : null|int|string = null
Return values
void

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

line()

Write a string as standard output.

public line(string $string[, string $style = null ][, null|int|string $verbosity = null ]) : void
Parameters
$string : string
$style : string = null
$verbosity : null|int|string = null
Return values
void

macro()

Register a custom macro.

public static macro(string $name, object|callable $macro) : void
Parameters
$name : string
$macro : object|callable
Return values
void

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

Return values
mixed

mixin()

Mix another object into the class.

public static mixin(object $mixin) : void
Parameters
$mixin : object
Return values
void

option()

Get the value of a command option.

public option([string $key = null ]) : string|array<string|int, mixed>
Parameters
$key : string = null
Return values
string|array<string|int, mixed>

options()

Get all of the options passed to the command.

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

question()

Write a string as question output.

public question(string $string[, null|int|string $verbosity = null ]) : void
Parameters
$string : string
$verbosity : null|int|string = null
Return values
void

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
Exception

When binding input fails. Bypass this by calling .

see
setCode()
see
execute()
Return values
int

The command exit code

secret()

Prompt the user for input but hide the answer from the console.

public secret(string $question[, bool $fallback = true ]) : string
Parameters
$question : string
$fallback : bool = true
Return values
string

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

setApplication()

public setApplication([Application $application = null ]) : mixed
Parameters
$application : Application = null
Return values
mixed

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) : Command
Parameters
$hidden : bool

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

Return values
Command

The current instance

setLaravel()

Set the Laravel application instance.

public setLaravel(Container $laravel) : void
Parameters
$laravel : Container
Return values
void

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

table()

Format input to textual table.

public table(array<string|int, mixed> $headers, Arrayable|array<string|int, mixed> $rows[, string $tableStyle = 'default' ][, array<string|int, mixed> $columnStyles = [] ]) : void
Parameters
$headers : array<string|int, mixed>
$rows : Arrayable|array<string|int, mixed>
$tableStyle : string = 'default'
$columnStyles : array<string|int, mixed> = []
Return values
void

warn()

Write a string as warning output.

public warn(string $string[, null|int|string $verbosity = null ]) : void
Parameters
$string : string
$verbosity : null|int|string = null
Return values
void

buildCallback()

protected buildCallback( $envKey,  $configKey) : Closure
Parameters
$envKey :
$configKey :
Return values
Closure

buildPattern()

protected buildPattern( $configKey) : string
Parameters
$configKey :
Return values
string

config()

protected config() : array<string|int, mixed>
Return values
array<string|int, mixed>

configToEnv()

Replace config values with env() syntax

protected configToEnv() : mixed
Return values
mixed

configure()

Configures the current command.

protected configure() : mixed
Return values
mixed

configureUsingFluentDefinition()

Configure the console command using a fluent definition.

protected configureUsingFluentDefinition() : void
Return values
void

context()

Get all of the context passed to the command.

protected context() : array<string|int, mixed>
Return values
array<string|int, mixed>

createInputFromArguments()

Create an input instance from the given arguments.

protected createInputFromArguments(array<string|int, mixed> $arguments) : ArrayInput
Parameters
$arguments : array<string|int, mixed>
Return values
ArrayInput

databaseConfigValue()

protected databaseConfigValue( $configKey) : string
Parameters
$configKey :
Return values
string

dbConfig()

protected dbConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>

envKeyExists()

protected envKeyExists( $key) : bool
Parameters
$key :
Return values
bool

envValue()

protected envValue( $configKey) : string
Parameters
$configKey :
Return values
string

execute()

Executes the current command.

protected execute(InputInterface $input, OutputInterface $output) : int|null

This method is not abstract because you can use this class as a concrete class. In this case, instead of defining the execute() method, you set the code to execute by passing a Closure to the setCode() method.

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

When this abstract method is not implemented

see
setCode()
Return values
int|null

null or 0 if everything went fine, or an error code

getArguments()

Get the console command arguments.

protected getArguments() : array<string|int, mixed>
Return values
array<string|int, mixed>

getOptions()

Get the console command options.

protected getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>

initialize()

Initializes the command after the input has been bound and before the input is validated.

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

This is mainly useful when a lot of commands extends one main command where some things need to be initialized based on the input arguments and options.

Parameters
$input : InputInterface
$output : OutputInterface
Tags
see
InputInterface::bind()
see
InputInterface::validate()
Return values
mixed

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
Return values
mixed

isEnv()

protected isEnv( $matches) : bool
Parameters
$matches :
Return values
bool

lines()

protected lines() : array<string|int, mixed>
Return values
array<string|int, mixed>

normalizeForConfig()

Normalizes a value to be inserted into config files.

protected normalizeForConfig( $value) : string
Parameters
$value :
Return values
string

normalizeForEnv()

Normalizes a value to be inserted into the .env file

protected normalizeForEnv( $value) : string
Parameters
$value :
Return values
string

overwriteConfig()

Overwrite config file

protected overwriteConfig() : mixed
Return values
mixed

parseConfigFile()

Parse config file line by line

protected parseConfigFile() : string
Return values
string

parseLine()

protected parseLine( $line,  $keys) : mixed
Parameters
$line :
$keys :
Return values
mixed

parseVerbosity()

Get the verbosity level in terms of Symfony's OutputInterface level.

protected parseVerbosity([string|int $level = null ]) : int
Parameters
$level : string|int = null
Return values
int

readEnvFile()

protected readEnvFile() : string
Return values
string

replaceConfigLine()

protected replaceConfigLine( $line,  $keys) : mixed
Parameters
$line :
$keys :
Return values
mixed

replaceDbConfigLine()

protected replaceDbConfigLine( $line) : mixed
Parameters
$line :
Return values
mixed

saveEnvSettings()

protected saveEnvSettings( $key,  $value) : mixed
Parameters
$key :
$value :
Return values
mixed

setCurrentConnection()

protected setCurrentConnection( $line,  $connection) : mixed
Parameters
$line :
$connection :
Return values
mixed

setVerbosity()

Set the verbosity level.

protected setVerbosity(string|int $level) : void
Parameters
$level : string|int
Return values
void

specifyParameters()

Specify the arguments and options on the command.

protected specifyParameters() : void
Return values
void

writeDbEnvSettings()

protected writeDbEnvSettings( $line) : mixed
Parameters
$line :
Return values
mixed

writeToConfigFile()

protected writeToConfigFile( $content) : mixed
Parameters
$content :
Return values
mixed

writeToEnv()

protected writeToEnv( $content) : mixed
Parameters
$content :
Return values
mixed

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

Return values
mixed

Search results