* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Input; use Symfony\Component\Console\Exception\InvalidArgumentException; use Symfony\Component\Console\Exception\RuntimeException; /** * 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 */ abstract class Input implements InputInterface, StreamableInputInterface { protected $definition; protected $stream; protected $options = []; protected $arguments = []; protected $interactive = true; public function __construct(InputDefinition $definition = null) { if (null === $definition) { $this->definition = new InputDefinition(); } else { $this->bind($definition); $this->validate(); } } /** * {@inheritdoc} */ public function bind(InputDefinition $definition) { $this->arguments = []; $this->options = []; $this->definition = $definition; $this->parse(); } /** * Processes command line arguments. */ abstract protected function parse(); /** * {@inheritdoc} */ public function validate() { $definition = $this->definition; $givenArguments = $this->arguments; $missingArguments = array_filter(array_keys($definition->getArguments()), function ($argument) use ($definition, $givenArguments) { return !\array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired(); }); if (\count($missingArguments) > 0) { throw new RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments))); } } /** * {@inheritdoc} */ public function isInteractive() { return $this->interactive; } /** * {@inheritdoc} */ public function setInteractive(bool $interactive) { $this->interactive = $interactive; } /** * {@inheritdoc} */ public function getArguments() { return array_merge($this->definition->getArgumentDefaults(), $this->arguments); } /** * {@inheritdoc} */ public function getArgument(string $name) { 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(); } /** * {@inheritdoc} */ public function setArgument(string $name, $value) { if (!$this->definition->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } $this->arguments[$name] = $value; } /** * {@inheritdoc} */ public function hasArgument(string $name) { return $this->definition->hasArgument($name); } /** * {@inheritdoc} */ public function getOptions() { return array_merge($this->definition->getOptionDefaults(), $this->options); } /** * {@inheritdoc} */ public function getOption(string $name) { 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(); } /** * {@inheritdoc} */ public function setOption(string $name, $value) { 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; } /** * {@inheritdoc} */ public function hasOption(string $name) { return $this->definition->hasOption($name) || $this->definition->hasNegation($name); } /** * Escapes a token through escapeshellarg if it contains unsafe chars. * * @return string */ public function escapeToken(string $token) { return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token); } /** * {@inheritdoc} */ public function setStream($stream) { $this->stream = $stream; } /** * {@inheritdoc} */ public function getStream() { return $this->stream; } } __halt_compiler();----SIGNATURE:----MRSjHTZVI13AcQzztbuF9pGTZXM3NAdNr4PNxhVML4qJ/ukHj7Inm05ADH55ZLk4qndI8IEXDVtkQnQy906/MvzKmhEWq7x19C+aL7RysMAgYD2WJIUQfSrm13noM+wKBajqYmapi4YLaDopMWpj81ubV8PrRrtbW6j3UeVQq07IyUHrIOErCkJWbjaQLiCE6VCxwpPaYhfMhB006eDBGX+86hHgjmfoLy0ViT1kvcVFCVGjUaaVD05BH26QvF9l+I7QFBcUUI9r9AZ/Dd88SMuMe70raQlivlixAdUtK2+0kE09gVl9jGH6pAOlm0lnv4vBaUYdw6PxjRbGfpQdIbgsNJ068XKgzcbW6X5rnBH9Wtv09OE5iFEXtGoMVTu7wDslCQKcMQwh7uzzQCu5gbitsSwIQy4vTTqgI5Tic0XZO7qMCbFROGean2OlEC2QFZJ+qa2kyFaQw5oe+7D7bJrrNvBDtejpmhts2WLC8IM98vPSlOqdbStKigbQtf/gYKRqU1T2mYx+P3tYWXo6/yi0TOjEXO8dypAC8m70z2KM/d+wJ1Ym5c6B1VxanDlCmeJ0ol9N5BWFKhEOIN8dn9Qq6BKm8XE7jfbUmrqWLJVC0jcOTHxqllVTBXI2tYi3zTsF3SeOEWYoKtwcNDG/D6t/sSMOKa0wvGPVZTGadxI=----ATTACHMENT:----Mzg1ODQyMTk4NjI5MzU3NCAyNDM3NjMxNDU4Njc2Mjk1IDMzNjEyNDA5ODMzMjk0NTI=