InputInterface.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Input;
  11. use Symfony\Component\Console\Exception\InvalidArgumentException;
  12. use Symfony\Component\Console\Exception\RuntimeException;
  13. /**
  14. * InputInterface is the interface implemented by all input classes.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. interface InputInterface
  19. {
  20. /**
  21. * Returns the first argument from the raw parameters (not parsed).
  22. */
  23. public function getFirstArgument(): ?string;
  24. /**
  25. * Returns true if the raw parameters (not parsed) contain a value.
  26. *
  27. * This method is to be used to introspect the input parameters
  28. * before they have been validated. It must be used carefully.
  29. * Does not necessarily return the correct result for short options
  30. * when multiple flags are combined in the same option.
  31. *
  32. * @param string|array $values The values to look for in the raw parameters (can be an array)
  33. * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
  34. */
  35. public function hasParameterOption(string|array $values, bool $onlyParams = false): bool;
  36. /**
  37. * Returns the value of a raw option (not parsed).
  38. *
  39. * This method is to be used to introspect the input parameters
  40. * before they have been validated. It must be used carefully.
  41. * Does not necessarily return the correct result for short options
  42. * when multiple flags are combined in the same option.
  43. *
  44. * @param string|array $values The value(s) to look for in the raw parameters (can be an array)
  45. * @param string|bool|int|float|array|null $default The default value to return if no result is found
  46. * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
  47. */
  48. public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false): mixed;
  49. /**
  50. * Binds the current Input instance with the given arguments and options.
  51. *
  52. * @throws RuntimeException
  53. */
  54. public function bind(InputDefinition $definition): void;
  55. /**
  56. * Validates the input.
  57. *
  58. * @throws RuntimeException When not enough arguments are given
  59. */
  60. public function validate(): void;
  61. /**
  62. * Returns all the given arguments merged with the default values.
  63. *
  64. * @return array<string|bool|int|float|array|null>
  65. */
  66. public function getArguments(): array;
  67. /**
  68. * Returns the argument value for a given argument name.
  69. *
  70. * @throws InvalidArgumentException When argument given doesn't exist
  71. */
  72. public function getArgument(string $name): mixed;
  73. /**
  74. * Sets an argument value by name.
  75. *
  76. * @throws InvalidArgumentException When argument given doesn't exist
  77. */
  78. public function setArgument(string $name, mixed $value): void;
  79. /**
  80. * Returns true if an InputArgument object exists by name or position.
  81. */
  82. public function hasArgument(string $name): bool;
  83. /**
  84. * Returns all the given options merged with the default values.
  85. *
  86. * @return array<string|bool|int|float|array|null>
  87. */
  88. public function getOptions(): array;
  89. /**
  90. * Returns the option value for a given option name.
  91. *
  92. * @throws InvalidArgumentException When option given doesn't exist
  93. */
  94. public function getOption(string $name): mixed;
  95. /**
  96. * Sets an option value by name.
  97. *
  98. * @throws InvalidArgumentException When option given doesn't exist
  99. */
  100. public function setOption(string $name, mixed $value): void;
  101. /**
  102. * Returns true if an InputOption object exists by name.
  103. */
  104. public function hasOption(string $name): bool;
  105. /**
  106. * Is this input means interactive?
  107. */
  108. public function isInteractive(): bool;
  109. /**
  110. * Sets the input interactivity.
  111. */
  112. public function setInteractive(bool $interactive): void;
  113. /**
  114. * Returns a stringified representation of the args passed to the command.
  115. *
  116. * InputArguments MUST be escaped as well as the InputOption values passed to the command.
  117. */
  118. public function __toString(): string;
  119. }