TextConfigOption.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Setup\Option;
  7. /**
  8. * Text option in deployment config tool
  9. */
  10. class TextConfigOption extends AbstractConfigOption
  11. {
  12. /**#@+
  13. * Frontend input types
  14. */
  15. const FRONTEND_WIZARD_TEXT = 'text';
  16. const FRONTEND_WIZARD_PASSWORD = 'password';
  17. const FRONTEND_WIZARD_TEXTAREA = 'textarea';
  18. /**#@- */
  19. /**
  20. * Constructor
  21. *
  22. * @param string $name
  23. * @param string $frontendType
  24. * @param string $configPath
  25. * @param string $description
  26. * @param string|null $defaultValue
  27. * @param string|array|null $shortCut
  28. * @throws \InvalidArgumentException
  29. */
  30. public function __construct(
  31. $name,
  32. $frontendType,
  33. $configPath,
  34. $description = '',
  35. $defaultValue = null,
  36. $shortCut = null
  37. ) {
  38. if ($frontendType != self::FRONTEND_WIZARD_TEXT && $frontendType != self::FRONTEND_WIZARD_PASSWORD &&
  39. $frontendType != self::FRONTEND_WIZARD_TEXTAREA
  40. ) {
  41. throw new \InvalidArgumentException("Frontend input type has to be 'text', 'textarea' or 'password'.");
  42. }
  43. parent::__construct(
  44. $name,
  45. $frontendType,
  46. self::VALUE_REQUIRED,
  47. $configPath,
  48. $description,
  49. $defaultValue,
  50. $shortCut
  51. );
  52. }
  53. /**
  54. * Validates input data
  55. *
  56. * @param mixed $data
  57. * @return void
  58. * @throws \InvalidArgumentException
  59. */
  60. public function validate($data)
  61. {
  62. if (!is_string($data)) {
  63. throw new \InvalidArgumentException("'{$this->getName()}' must be a string");
  64. }
  65. parent::validate($data);
  66. }
  67. }