1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149:
<?php
/*
* This file is part of the webmozart/console package.
*
* (c) Bernhard Schussek <bschussek@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Webmozart\Console\Api\Config;
/**
* The configuration of an console sub-command.
*
* A sub-command is defined within the scope of another command. For example,
* in the command `server add <host>`, the command "add" is a sub-command of the
* "server" command.
*
* @since 1.0
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see OptionCommandConfig
*/
class SubCommandConfig extends CommandConfig
{
/**
* @var CommandConfig
*/
private $parentConfig;
/**
* Creates a new configuration.
*
* @param string $name The name of the command.
* @param CommandConfig $parentConfig The command configuration that
* contains this configuration.
*/
public function __construct($name = null, CommandConfig $parentConfig = null)
{
parent::__construct($name);
if ($parentConfig) {
$this->setParentConfig($parentConfig);
}
}
/**
* Returns the parent command configuration.
*
* @return CommandConfig The parent command configuration.
*/
public function getParentConfig()
{
return $this->parentConfig;
}
/**
* Sets the parent command configuration.
*
* @param CommandConfig $parentConfig The parent command configuration.
*/
public function setParentConfig(CommandConfig $parentConfig)
{
$this->parentConfig = $parentConfig;
if ($parentConfig->getApplicationConfig()) {
$this->setApplicationConfig($parentConfig->getApplicationConfig());
}
}
/**
* Ends the block when dynamically configuring a nested configuration.
*
* This method is usually used together with
* {@link CommandConfig::beginSubCommand()},
* {@link CommandConfig::beginOptionCommand()} or
* {@link CommandConfig::beginDefaultCommand()}:
*
* ```php
* $config
* ->beginSubCommand('add')
* // ...
* ->end()
*
* // ...
* ;
* ```
*
* @return CommandConfig|SubCommandConfig|OptionCommandConfig The parent command configuration.
*/
public function end()
{
return $this->parentConfig;
}
/**
* {@inheritdoc}
*/
protected function getDefaultHelperSet()
{
return $this->parentConfig
? $this->parentConfig->getHelperSet()
: parent::getDefaultHelperSet();
}
/**
* {@inheritdoc}
*/
protected function getDefaultHandler()
{
return $this->parentConfig
? $this->parentConfig->getHandler()
: parent::getDefaultHandler();
}
/**
* {@inheritdoc}
*/
protected function getDefaultHandlerMethod()
{
return $this->parentConfig
? $this->parentConfig->getHandlerMethod()
: parent::getDefaultHandlerMethod();
}
/**
* {@inheritdoc}
*/
protected function getDefaultArgsParser()
{
return $this->parentConfig
? $this->parentConfig->getArgsParser()
: parent::getDefaultArgsParser();
}
/**
* {@inheritdoc}
*/
protected function getDefaultLenientArgsParsing()
{
return $this->parentConfig
? $this->parentConfig->isLenientArgsParsingEnabled()
: parent::getDefaultLenientArgsParsing();
}
}