diff --git a/Input/ArgvInput.php b/Input/ArgvInput.php index 63f40f27..c576fbf6 100644 --- a/Input/ArgvInput.php +++ b/Input/ArgvInput.php @@ -238,7 +238,7 @@ class ArgvInput extends Input /** * {@inheritdoc} */ - public function getFirstArgument() + public function getFirstArgument(): ?string { $isOption = false; foreach ($this->tokens as $i => $token) { @@ -273,7 +273,7 @@ class ArgvInput extends Input /** * {@inheritdoc} */ - public function hasParameterOption($values, $onlyParams = false) + public function hasParameterOption(string|array $values, bool $onlyParams = false): bool { $values = (array) $values; @@ -298,7 +298,7 @@ class ArgvInput extends Input /** * {@inheritdoc} */ - public function getParameterOption($values, $default = false, $onlyParams = false) + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false) { $values = (array) $values; $tokens = $this->tokens; diff --git a/Input/Input.php b/Input/Input.php index d7f29073..58cfd676 100644 --- a/Input/Input.php +++ b/Input/Input.php @@ -80,7 +80,7 @@ abstract class Input implements InputInterface, StreamableInputInterface /** * {@inheritdoc} */ - public function isInteractive() + public function isInteractive(): bool { return $this->interactive; } @@ -96,7 +96,7 @@ abstract class Input implements InputInterface, StreamableInputInterface /** * {@inheritdoc} */ - public function getArguments() + public function getArguments(): array { return array_merge($this->definition->getArgumentDefaults(), $this->arguments); } @@ -116,7 +116,7 @@ abstract class Input implements InputInterface, StreamableInputInterface /** * {@inheritdoc} */ - public function setArgument($name, $value) + public function setArgument(string $name, mixed $value) { if (!$this->definition->hasArgument((string) $name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); @@ -128,7 +128,7 @@ abstract class Input implements InputInterface, StreamableInputInterface /** * {@inheritdoc} */ - public function hasArgument($name) + public function hasArgument($name): bool { return $this->definition->hasArgument((string) $name); } @@ -136,7 +136,7 @@ abstract class Input implements InputInterface, StreamableInputInterface /** * {@inheritdoc} */ - public function getOptions() + public function getOptions(): array { return array_merge($this->definition->getOptionDefaults(), $this->options); } @@ -156,7 +156,7 @@ abstract class Input implements InputInterface, StreamableInputInterface /** * {@inheritdoc} */ - public function setOption($name, $value) + public function setOption(string $name, mixed $value) { if (!$this->definition->hasOption($name)) { throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name)); @@ -168,7 +168,7 @@ abstract class Input implements InputInterface, StreamableInputInterface /** * {@inheritdoc} */ - public function hasOption($name) + public function hasOption($name): bool { return $this->definition->hasOption($name); } diff --git a/Input/InputInterface.php b/Input/InputInterface.php index 8efc6232..a723a5ae 100644 --- a/Input/InputInterface.php +++ b/Input/InputInterface.php @@ -18,146 +18,133 @@ use Symfony\Component\Console\Exception\RuntimeException; * InputInterface is the interface implemented by all input classes. * * @author Fabien Potencier + * + * @method string __toString() Returns a stringified representation of the args passed to the command. + * InputArguments MUST be escaped as well as the InputOption values passed to the command. */ interface InputInterface { - /** - * Returns the first argument from the raw parameters (not parsed). - * - * @return string|null The value of the first argument or null otherwise - */ - public function getFirstArgument(); - - /** - * Returns true if the raw parameters (not parsed) contain a value. - * - * This method is to be used to introspect the input parameters - * before they have been validated. It must be used carefully. - * Does not necessarily return the correct result for short options - * when multiple flags are combined in the same option. - * - * @param string|array $values The values to look for in the raw parameters (can be an array) - * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal - * - * @return bool true if the value is contained in the raw parameters - */ - public function hasParameterOption($values, $onlyParams = false); - - /** - * Returns the value of a raw option (not parsed). - * - * This method is to be used to introspect the input parameters - * before they have been validated. It must be used carefully. - * Does not necessarily return the correct result for short options - * when multiple flags are combined in the same option. - * - * @param string|array $values The value(s) to look for in the raw parameters (can be an array) - * @param string|bool|int|float|array|null $default The default value to return if no result is found - * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal - * - * @return mixed The option value - */ - public function getParameterOption($values, $default = false, $onlyParams = false); - - /** - * Binds the current Input instance with the given arguments and options. - * - * @throws RuntimeException - */ - public function bind(InputDefinition $definition); - - /** - * Validates the input. - * - * @throws RuntimeException When not enough arguments are given - */ - public function validate(); - - /** - * Returns all the given arguments merged with the default values. - * - * @return array - */ - public function getArguments(); - - /** - * Returns the argument value for a given argument name. - * - * @param string $name The argument name - * - * @return mixed - * - * @throws InvalidArgumentException When argument given doesn't exist - */ - public function getArgument($name); - - /** - * Sets an argument value by name. - * - * @param string $name The argument name - * @param mixed $value The argument value - * - * @throws InvalidArgumentException When argument given doesn't exist - */ - public function setArgument($name, $value); - - /** - * Returns true if an InputArgument object exists by name or position. - * - * @param string $name The argument name - * - * @return bool true if the InputArgument object exists, false otherwise - */ - public function hasArgument($name); - - /** - * Returns all the given options merged with the default values. - * - * @return array - */ - public function getOptions(); - - /** - * Returns the option value for a given option name. - * - * @param string $name The option name - * - * @return mixed - * - * @throws InvalidArgumentException When option given doesn't exist - */ - public function getOption($name); - - /** - * Sets an option value by name. - * - * @param string $name The option name - * @param mixed $value The option value - * - * @throws InvalidArgumentException When option given doesn't exist - */ - public function setOption($name, $value); - - /** - * Returns true if an InputOption object exists by name. - * - * @param string $name The InputOption name - * - * @return bool true if the InputOption object exists, false otherwise - */ - public function hasOption($name); - - /** - * Is this input means interactive? - * - * @return bool - */ - public function isInteractive(); - - /** - * Sets the input interactivity. - * - * @param bool $interactive If the input should be interactive - */ - public function setInteractive($interactive); -} + /** + * Returns the first argument from the raw parameters (not parsed). + */ + public function getFirstArgument(): ?string; + + /** + * Returns true if the raw parameters (not parsed) contain a value. + * + * This method is to be used to introspect the input parameters + * before they have been validated. It must be used carefully. + * Does not necessarily return the correct result for short options + * when multiple flags are combined in the same option. + * + * @param string|array $values The values to look for in the raw parameters (can be an array) + * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal + */ + public function hasParameterOption(string|array $values, bool $onlyParams = false): bool; + + /** + * Returns the value of a raw option (not parsed). + * + * This method is to be used to introspect the input parameters + * before they have been validated. It must be used carefully. + * Does not necessarily return the correct result for short options + * when multiple flags are combined in the same option. + * + * @param string|array $values The value(s) to look for in the raw parameters (can be an array) + * @param string|bool|int|float|array|null $default The default value to return if no result is found + * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal + * + * @return mixed + */ + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false); + + /** + * Binds the current Input instance with the given arguments and options. + * + * @return void + * + * @throws RuntimeException + */ + public function bind(InputDefinition $definition); + + /** + * Validates the input. + * + * @return void + * + * @throws RuntimeException When not enough arguments are given + */ + public function validate(); + + /** + * Returns all the given arguments merged with the default values. + * + * @return array + */ + public function getArguments(): array; + + /** + * Returns the argument value for a given argument name. + * + * @return mixed + * + * @throws InvalidArgumentException When argument given doesn't exist + */ + public function getArgument(string $name); + + /** + * Sets an argument value by name. + * + * @return void + * + * @throws InvalidArgumentException When argument given doesn't exist + */ + public function setArgument(string $name, mixed $value); + + /** + * Returns true if an InputArgument object exists by name or position. + */ + public function hasArgument(string $name): bool; + + /** + * Returns all the given options merged with the default values. + * + * @return array + */ + public function getOptions(): array; + + /** + * Returns the option value for a given option name. + * + * @return mixed + * + * @throws InvalidArgumentException When option given doesn't exist + */ + public function getOption(string $name); + + /** + * Sets an option value by name. + * + * @return void + * + * @throws InvalidArgumentException When option given doesn't exist + */ + public function setOption(string $name, mixed $value); + + /** + * Returns true if an InputOption object exists by name. + */ + public function hasOption(string $name): bool; + + /** + * Is this input means interactive? + */ + public function isInteractive(): bool; + + /** + * Sets the input interactivity. + * + * @return void + */ + public function setInteractive(bool $interactive); +} \ No newline at end of file