class Input
Input is the base class for all concrete Input classes.
Three concrete classes are provided by default:
- `ArgvInput`: The input comes from the CLI arguments (argv)
- `StringInput`: The input is provided as a string
- `ArrayInput`: The input is provided as an array
@author Fabien Potencier <fabien@symfony.com>
Hierarchy
- class \Symfony\Component\Console\Input\Input implements \Symfony\Component\Console\Input\InputInterface, \Symfony\Component\Console\Input\StreamableInputInterface
Expanded class hierarchy of Input
14 string references to 'Input'
- BrowserKitDriver::canResetForm in vendor/
behat/ mink-browserkit-driver/ src/ BrowserKitDriver.php - BrowserKitDriver::canSubmitForm in vendor/
behat/ mink-browserkit-driver/ src/ BrowserKitDriver.php - ChoiceFormField::initialize in vendor/
symfony/ dom-crawler/ Field/ ChoiceFormField.php - Initializes the form field.
- CompleteCommand::createCompletionInput in vendor/
symfony/ console/ Command/ CompleteCommand.php - FileFormField::initialize in vendor/
symfony/ dom-crawler/ Field/ FileFormField.php - Initializes the form field.
File
-
vendor/
symfony/ console/ Input/ Input.php, line 28
Namespace
Symfony\Component\Console\InputView source
abstract class Input implements InputInterface, StreamableInputInterface {
protected InputDefinition $definition;
/** @var resource */
protected $stream;
protected array $options = [];
protected array $arguments = [];
protected bool $interactive = true;
public function __construct(?InputDefinition $definition = null) {
if (null === $definition) {
$this->definition = new InputDefinition();
}
else {
$this->bind($definition);
$this->validate();
}
}
public function bind(InputDefinition $definition) : void {
$this->arguments = [];
$this->options = [];
$this->definition = $definition;
$this->parse();
}
/**
* Processes command line arguments.
*/
protected abstract function parse() : void;
public function validate() : void {
$definition = $this->definition;
$givenArguments = $this->arguments;
$missingArguments = array_filter(array_keys($definition->getArguments()), fn($argument) => !\array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)
->isRequired());
if (\count($missingArguments) > 0) {
throw new RuntimeException(\sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments)));
}
}
public function isInteractive() : bool {
return $this->interactive;
}
public function setInteractive(bool $interactive) : void {
$this->interactive = $interactive;
}
public function getArguments() : array {
return array_merge($this->definition
->getArgumentDefaults(), $this->arguments);
}
public function getArgument(string $name) : mixed {
if (!$this->definition
->hasArgument($name)) {
throw new InvalidArgumentException(\sprintf('The "%s" argument does not exist.', $name));
}
return $this->arguments[$name] ?? $this->definition
->getArgument($name)
->getDefault();
}
public function setArgument(string $name, mixed $value) : void {
if (!$this->definition
->hasArgument($name)) {
throw new InvalidArgumentException(\sprintf('The "%s" argument does not exist.', $name));
}
$this->arguments[$name] = $value;
}
public function hasArgument(string $name) : bool {
return $this->definition
->hasArgument($name);
}
public function getOptions() : array {
return array_merge($this->definition
->getOptionDefaults(), $this->options);
}
public function getOption(string $name) : mixed {
if ($this->definition
->hasNegation($name)) {
if (null === ($value = $this->getOption($this->definition
->negationToName($name)))) {
return $value;
}
return !$value;
}
if (!$this->definition
->hasOption($name)) {
throw new InvalidArgumentException(\sprintf('The "%s" option does not exist.', $name));
}
return \array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition
->getOption($name)
->getDefault();
}
public function setOption(string $name, mixed $value) : void {
if ($this->definition
->hasNegation($name)) {
$this->options[$this->definition
->negationToName($name)] = !$value;
return;
}
elseif (!$this->definition
->hasOption($name)) {
throw new InvalidArgumentException(\sprintf('The "%s" option does not exist.', $name));
}
$this->options[$name] = $value;
}
public function hasOption(string $name) : bool {
return $this->definition
->hasOption($name) || $this->definition
->hasNegation($name);
}
/**
* Escapes a token through escapeshellarg if it contains unsafe chars.
*/
public function escapeToken(string $token) : string {
return preg_match('{^[\\w-]+$}', $token) ? $token : escapeshellarg($token);
}
/**
* @param resource $stream
*/
public function setStream($stream) : void {
$this->stream = $stream;
}
/**
* @return resource
*/
public function getStream() {
return $this->stream;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Input::$arguments | protected | property | |||
Input::$definition | protected | property | |||
Input::$interactive | protected | property | |||
Input::$options | protected | property | |||
Input::$stream | protected | property | @var resource | ||
Input::bind | public | function | Binds the current Input instance with the given arguments and options. | Overrides InputInterface::bind | 1 |
Input::escapeToken | public | function | Escapes a token through escapeshellarg if it contains unsafe chars. | ||
Input::getArgument | public | function | Returns the argument value for a given argument name. | Overrides InputInterface::getArgument | |
Input::getArguments | public | function | Returns all the given arguments merged with the default values. | Overrides InputInterface::getArguments | |
Input::getOption | public | function | Returns the option value for a given option name. | Overrides InputInterface::getOption | |
Input::getOptions | public | function | Returns all the given options merged with the default values. | Overrides InputInterface::getOptions | |
Input::getStream | public | function | Overrides StreamableInputInterface::getStream | ||
Input::hasArgument | public | function | Returns true if an InputArgument object exists by name or position. | Overrides InputInterface::hasArgument | |
Input::hasOption | public | function | Returns true if an InputOption object exists by name. | Overrides InputInterface::hasOption | |
Input::isInteractive | public | function | Is this input means interactive? | Overrides InputInterface::isInteractive | |
Input::parse | abstract protected | function | Processes command line arguments. | 2 | |
Input::setArgument | public | function | Sets an argument value by name. | Overrides InputInterface::setArgument | |
Input::setInteractive | public | function | Sets the input interactivity. | Overrides InputInterface::setInteractive | |
Input::setOption | public | function | Sets an option value by name. | Overrides InputInterface::setOption | |
Input::setStream | public | function | Overrides StreamableInputInterface::setStream | ||
Input::validate | public | function | Validates the input. | Overrides InputInterface::validate | |
Input::__construct | public | function | 2 | ||
InputInterface::getFirstArgument | public | function | Returns the first argument from the raw parameters (not parsed). | 2 | |
InputInterface::getParameterOption | public | function | Returns the value of a raw option (not parsed). | 2 | |
InputInterface::hasParameterOption | public | function | Returns true if the raw parameters (not parsed) contain a value. | 2 | |
InputInterface::__toString | public | function | Returns a stringified representation of the args passed to the command. | 2 |