PHP Class CraftCli\Application

Inheritance: extends Symfony\Component\Console\Application
Show file Open project: rsanchez/craft-cli

Protected Properties

Property Type Description
$addonAuthorName string Author name for generated addons
$addonAuthorUrl string Author url for generated addons
$config array Configuration items
$craftPath string Path to the craft folder
$hasValidCraftPath boolean Whether the craft folder has been set/guessed correctly
$userDefinedCommandDirs array A list of Command dirs
$userDefinedCommands array A list of Command objects
$vendorPath string Path to the Composer vendor folder

Public Methods

Method Description
__construct ( $vendorPath = null )
addComposerCommands ( ) : void Find any Command plugins installed via composer or supplied by the main composer.json and add them to the Application
addComposerPlugins ( ) : void Find any Command plugins installed via composer and add them to the Application
addCustomComposerCommands ( ) : void Find any Command plugins upplied by the main composer.json and add them to the Application
addUserDefinedCommands ( ) : void Find any user-defined Commands in the config and add them to the Application
bootstrap ( ) : Craft\ConsoleApp Boot up craft
canBeBootstrapped ( ) : boolean Whether or not a valid system folder was found
findClassInDir ( string $subclassOf, string $dir, string $namespace = null ) : array Get a list of classes in the specified directory
findCommandsInDir ( string $dir, string $namespace = null ) : array Get a list of Symfony Console Commands classes in the specified directory
getAddonAuthorName ( ) : string Get the default addon author name
getAddonAuthorUrl ( ) : string Get the default addon author URL
getComposerConfig ( ) : array Get craft-cli configuration stored in the root composer.json
getConfig ( ) : array Get all configuration items
getConfigItem ( string $key ) : mixed Get the specified config item
getCraftFolder ( ) : string Get the name of the craft folder
getCraftPath ( ) : string Get the path to the craft folder
onCommand ( Symfony\Component\Console\Event\ConsoleCommandEvent $event ) : void On Command Event Handler
registerCommand ( string | callable $class ) : void Add a command to the Application by class name or callback that return a Command class
setVendorPath ( string $vendorPath ) Set the path to the Composer vendor folder

Protected Methods

Method Description
findConfigFile ( string | null $dir = null ) : string | null Traverse up a directory to find a config file
getEnvironmentOption ( ) : string | null Get the environment from the --environment option or from the CRAFT_ENVIRONMENT env variable
isCommandExemptFromBootstrap ( Command $command ) : boolean Check whether a command should be exempt from bootstrapping
loadConfig ( ) : void Looks for ~/.craft-cli.php and ./.craft-cli.php and combines them into an array

Method Details

__construct() public method

public __construct ( $vendorPath = null )

addComposerCommands() public method

Find any Command plugins installed via composer or supplied by the main composer.json and add them to the Application
public addComposerCommands ( ) : void
return void

addComposerPlugins() public method

Find any Command plugins installed via composer and add them to the Application
public addComposerPlugins ( ) : void
return void

addCustomComposerCommands() public method

Find any Command plugins upplied by the main composer.json and add them to the Application
public addCustomComposerCommands ( ) : void
return void

addUserDefinedCommands() public method

Find any user-defined Commands in the config and add them to the Application
public addUserDefinedCommands ( ) : void
return void

bootstrap() public method

Boot up craft
public bootstrap ( ) : Craft\ConsoleApp
return Craft\ConsoleApp

canBeBootstrapped() public method

Whether or not a valid system folder was found
public canBeBootstrapped ( ) : boolean
return boolean

findClassInDir() public method

Get a list of classes in the specified directory
public findClassInDir ( string $subclassOf, string $dir, string $namespace = null ) : array
$subclassOf string
$dir string
$namespace string
return array

findCommandsInDir() public method

Get a list of Symfony Console Commands classes in the specified directory
public findCommandsInDir ( string $dir, string $namespace = null ) : array
$dir string
$namespace string
return array

findConfigFile() protected method

Traverse up a directory to find a config file
protected findConfigFile ( string | null $dir = null ) : string | null
$dir string | null defaults to getcwd if null
return string | null

getAddonAuthorName() public method

Get the default addon author name
public getAddonAuthorName ( ) : string
return string

getAddonAuthorUrl() public method

Get the default addon author URL
public getAddonAuthorUrl ( ) : string
return string

getComposerConfig() public method

Get craft-cli configuration stored in the root composer.json
public getComposerConfig ( ) : array
return array

getConfig() public method

Get all configuration items
public getConfig ( ) : array
return array

getConfigItem() public method

Get the specified config item
public getConfigItem ( string $key ) : mixed
$key string
return mixed

getCraftFolder() public method

Get the name of the craft folder
public getCraftFolder ( ) : string
return string

getCraftPath() public method

Get the path to the craft folder
public getCraftPath ( ) : string
return string

getEnvironmentOption() protected method

Get the environment from the --environment option or from the CRAFT_ENVIRONMENT env variable
protected getEnvironmentOption ( ) : string | null
return string | null

isCommandExemptFromBootstrap() protected method

Check whether a command should be exempt from bootstrapping
protected isCommandExemptFromBootstrap ( Command $command ) : boolean
$command Symfony\Component\Console\Command\Command
return boolean

loadConfig() protected method

Looks for ~/.craft-cli.php and ./.craft-cli.php and combines them into an array
protected loadConfig ( ) : void
return void

onCommand() public method

Check if the current command requires EE bootstrapping and throw an exception if EE is not bootstrapped
public onCommand ( Symfony\Component\Console\Event\ConsoleCommandEvent $event ) : void
$event Symfony\Component\Console\Event\ConsoleCommandEvent
return void

registerCommand() public method

Add a command to the Application by class name or callback that return a Command class
public registerCommand ( string | callable $class ) : void
$class string | callable class name or callback that returns a command
return void

setVendorPath() public method

Set the path to the Composer vendor folder
public setVendorPath ( string $vendorPath )
$vendorPath string

Property Details

$addonAuthorName protected property

Author name for generated addons
protected string $addonAuthorName
return string

$addonAuthorUrl protected property

Author url for generated addons
protected string $addonAuthorUrl
return string

$config protected property

Configuration items
protected array $config
return array

$craftPath protected property

Path to the craft folder
protected string $craftPath
return string

$hasValidCraftPath protected property

Whether the craft folder has been set/guessed correctly
protected bool $hasValidCraftPath
return boolean

$userDefinedCommandDirs protected property

A list of Command dirs
protected array $userDefinedCommandDirs
return array

$userDefinedCommands protected property

A list of Command objects
protected array $userDefinedCommands
return array

$vendorPath protected property

Path to the Composer vendor folder
protected string $vendorPath
return string