InvalidOptionException.php 951 B

12345678910111213141516171819202122232425262728293031323334
  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\Exception;
  11. /**
  12. * Represents an incorrect option name or value typed in the console.
  13. *
  14. * @author Jérôme Tamarelle <jerome@tamarelle.net>
  15. */
  16. class InvalidOptionException extends \InvalidArgumentException implements ExceptionInterface
  17. {
  18. /**
  19. * @internal
  20. */
  21. public static function fromEnumValue(string $name, string $value, array|\Closure $suggestedValues): self
  22. {
  23. $error = \sprintf('The value "%s" is not valid for the "%s" option.', $value, $name);
  24. if (\is_array($suggestedValues)) {
  25. $error .= \sprintf(' Supported values are "%s".', implode('", "', $suggestedValues));
  26. }
  27. return new self($error);
  28. }
  29. }