PHP Class Consolidation\Cgr\Application

Mostra file Open project: consolidation/cgr

Protected Properties

Property Type Description
$outputFile

Public Methods

Method Description
buildConfigCommand ( string $execPath, array $composerArgs, string $key, string $value, array $env, string $installLocation ) : CommandToExec Generate command string to call composer config KEY VALUE to install one project.
buildGlobalCommand ( $composerCommand, $execPath, array $composerArgs, string $projectWithVersion, array $env, string $installLocation ) : CommandToExec Generate command string to call composer COMMAND to install one project.
configureProjectStability ( string $execPath, array $composerArgs, array $projects, array $options ) : array If --stability VALUE is provided, then run a composer config minimum-stability VALUE command to configure composer.json appropriately.
flipProjectsArray ( string[] $projects ) : array Convert from an array of projects to an array where the key is the project name, and the value (version) is an empty string.
generalCommand ( string $composerCommand, string $execPath, array $composerArgs, array $projects, array $options ) : array General command handler.
getCommandsToExec ( $command, array $composerArgs, array $projects, array $options ) : CommandToExec Return an array containing a list of commands to execute. Depending on the composition of the aguments and projects parameters, this list will contain either a single command string to call through to composer (if cgr is being used as a composer alias), or it will contain a list of appropriate replacement 'composer global require' commands that install each project in its own installation directory, while installing each projects' binaries in the global Composer bin directory, ~/.composer/vendor/bin.
getDefaultOptionValues ( string $home ) : array Return our list of default option values, with paths relative to the provided home directory.
isComposerVersion ( string $arg ) : boolean Identify an argument that could be a Composer version string.
parseArgvAndGetCommandList ( $argv, $home ) Figure out everything we're going to do, but don't do any of it yet, just return the command objects to run.
parseOutOurOptions ( array $argv, array $optionDefaultValues ) : array We use our own special-purpose argv parser. The options that apply to this tool are identified by a simple associative array, where the key is the option name, and the value is its default value.
projectWithVersion ( string $project, string $version ) : string Return $project:$version, or just $project if there is no $version.
requireCommand ( string $execPath, array $composerArgs, array $projects, array $options ) : array Provide a safer version of composer global require. Each project listed in $projects will be installed into its own project directory.
run ( array $argv, string $home ) : integer Run the cgr tool, a safer alternative to composer global require.
runCommandList ( array $commandList, $options ) : integer Run all of the commands in a list. Abort early if any fail.
separateProjectAndGetCommandList ( $argv, $home, $options ) Figure out everything we're going to do, but don't do any of it yet, just return the command objects to run.
separateProjectsFromArgs ( array $argv, $options ) : array After our options are removed by parseOutOurOptions, those items remaining in $argv will be separated into a list of projects and versions, and anything else that is not a project:version. Returns an array of two items containing: - An associative array, where the key is the project name and the value is the version (or an empty string, if no version was specified) - The remaining $argv items not used to build the projects array.
setOutputFile ( $outputFile ) Set up output redirection. Used by tests.
updateCommand ( $execPath, array $composerArgs, array $projects, array $options ) : array Run composer global update. Not only do we want to update the "global" Composer project, we also want to update all of the "isolated" projects installed via cgr in ~/.composer/global.

Protected Methods

Method Description
overlayEnvironmentValues ( $defaults ) Replace option default values with the corresponding environment variable value, if it is set.

Method Details

buildConfigCommand() public method

Generate command string to call composer config KEY VALUE to install one project.
public buildConfigCommand ( string $execPath, array $composerArgs, string $key, string $value, array $env, string $installLocation ) : CommandToExec
$execPath string The path to composer
$composerArgs array The arguments to pass to composer
$key string The config item to set
$value string The value to set the config item to
$env array Environment to set prior to exec
$installLocation string Location to install the project
return CommandToExec

buildGlobalCommand() public method

Generate command string to call composer COMMAND to install one project.
public buildGlobalCommand ( $composerCommand, $execPath, array $composerArgs, string $projectWithVersion, array $env, string $installLocation ) : CommandToExec
$composerArgs array The arguments to pass to composer
$projectWithVersion string The project:version to install
$env array Environment to set prior to exec
$installLocation string Location to install the project
return CommandToExec

configureProjectStability() public method

If --stability VALUE is provided, then run a composer config minimum-stability VALUE command to configure composer.json appropriately.
public configureProjectStability ( string $execPath, array $composerArgs, array $projects, array $options ) : array
$execPath string The path to composer
$composerArgs array Anything from the global $argv to be passed on to Composer
$projects array A list of projects to install, with the key specifying the project name, and the value specifying its version.
$options array User options from the command line; see $optionDefaultValues in the main() function.
return array

flipProjectsArray() public method

Convert from an array of projects to an array where the key is the project name, and the value (version) is an empty string.
public flipProjectsArray ( string[] $projects ) : array
$projects string[]
return array

generalCommand() public method

General command handler.
public generalCommand ( string $composerCommand, string $execPath, array $composerArgs, array $projects, array $options ) : array
$composerCommand string The composer command to run e.g. require
$execPath string The path to composer
$composerArgs array Anything from the global $argv to be passed on to Composer
$projects array A list of projects to install, with the key specifying the project name, and the value specifying its version.
$options array User options from the command line; see $optionDefaultValues in the main() function.
return array

getCommandsToExec() public method

Return an array containing a list of commands to execute. Depending on the composition of the aguments and projects parameters, this list will contain either a single command string to call through to composer (if cgr is being used as a composer alias), or it will contain a list of appropriate replacement 'composer global require' commands that install each project in its own installation directory, while installing each projects' binaries in the global Composer bin directory, ~/.composer/vendor/bin.
public getCommandsToExec ( $command, array $composerArgs, array $projects, array $options ) : CommandToExec
$composerArgs array
$projects array
$options array
return CommandToExec

getDefaultOptionValues() public method

Return our list of default option values, with paths relative to the provided home directory.
public getDefaultOptionValues ( string $home ) : array
$home string The user's home directory
return array

isComposerVersion() public method

Identify an argument that could be a Composer version string.
public isComposerVersion ( string $arg ) : boolean
$arg string The argument to test
return boolean

overlayEnvironmentValues() protected method

Replace option default values with the corresponding environment variable value, if it is set.
protected overlayEnvironmentValues ( $defaults )

parseArgvAndGetCommandList() public method

Figure out everything we're going to do, but don't do any of it yet, just return the command objects to run.
public parseArgvAndGetCommandList ( $argv, $home )

parseOutOurOptions() public method

The result of this function is an array of two items containing: - An array of the items in $argv not used to set an option value - An array of options containing the user-specified or default values
public parseOutOurOptions ( array $argv, array $optionDefaultValues ) : array
$argv array The global $argv passed in by php
$optionDefaultValues array An associative array
return array

projectWithVersion() public method

Return $project:$version, or just $project if there is no $version.
public projectWithVersion ( string $project, string $version ) : string
$project string The project to install
$version string The version desired
return string

requireCommand() public method

The binaries from each project will still be placed in the global composer bin directory.
public requireCommand ( string $execPath, array $composerArgs, array $projects, array $options ) : array
$execPath string The path to composer
$composerArgs array Anything from the global $argv to be passed on to Composer
$projects array A list of projects to install, with the key specifying the project name, and the value specifying its version.
$options array User options from the command line; see $optionDefaultValues in the main() function.
return array

run() public method

Run the cgr tool, a safer alternative to composer global require.
public run ( array $argv, string $home ) : integer
$argv array The global $argv array passed in by PHP
$home string The path to the user's home directory
return integer

runCommandList() public method

Run all of the commands in a list. Abort early if any fail.
public runCommandList ( array $commandList, $options ) : integer
$commandList array An array of CommandToExec
return integer

separateProjectAndGetCommandList() public method

Figure out everything we're going to do, but don't do any of it yet, just return the command objects to run.
public separateProjectAndGetCommandList ( $argv, $home, $options )

separateProjectsFromArgs() public method

After our options are removed by parseOutOurOptions, those items remaining in $argv will be separated into a list of projects and versions, and anything else that is not a project:version. Returns an array of two items containing: - An associative array, where the key is the project name and the value is the version (or an empty string, if no version was specified) - The remaining $argv items not used to build the projects array.
public separateProjectsFromArgs ( array $argv, $options ) : array
$argv array The $argv array from parseOutOurOptions()
return array

setOutputFile() public method

Set up output redirection. Used by tests.
public setOutputFile ( $outputFile )

updateCommand() public method

Run composer global update. Not only do we want to update the "global" Composer project, we also want to update all of the "isolated" projects installed via cgr in ~/.composer/global.
public updateCommand ( $execPath, array $composerArgs, array $projects, array $options ) : array
$composerArgs array Anything from the global $argv to be passed on to Composer
$projects array A list of projects to update.
$options array User options from the command line; see $optionDefaultValues in the main() function.
return array

Property Details

$outputFile protected_oe property

protected $outputFile