Request.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Console request
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\App\Console;
  9. class Request implements \Magento\Framework\App\RequestInterface
  10. {
  11. /**
  12. * @var array
  13. */
  14. protected $params;
  15. /**
  16. * @param array $parameters
  17. */
  18. public function __construct(array $parameters = [])
  19. {
  20. $data = getopt(null, $parameters);
  21. // It can happen that request comes from http (e.g. pub/cron.php), but it runs the console
  22. if ($data) {
  23. $this->setParams($data);
  24. } else {
  25. $this->setParams([]);
  26. }
  27. }
  28. /**
  29. * Retrieve module name
  30. *
  31. * @return void
  32. */
  33. public function getModuleName()
  34. {
  35. return;
  36. }
  37. /**
  38. * Set Module name
  39. *
  40. * @param string $name
  41. * @return void
  42. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  43. */
  44. public function setModuleName($name)
  45. {
  46. }
  47. /**
  48. * Retrieve action name
  49. *
  50. * @return void
  51. */
  52. public function getActionName()
  53. {
  54. return;
  55. }
  56. /**
  57. * Set action name
  58. *
  59. * @param string $name
  60. * @return void
  61. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  62. */
  63. public function setActionName($name)
  64. {
  65. }
  66. /**
  67. * Retrieve param by key
  68. *
  69. * @param string $key
  70. * @param mixed $defaultValue
  71. * @return mixed
  72. */
  73. public function getParam($key, $defaultValue = null)
  74. {
  75. if (isset($this->params[$key])) {
  76. return $this->params[$key];
  77. }
  78. return $defaultValue;
  79. }
  80. /**
  81. * Retrieve all params as array
  82. *
  83. * @return array
  84. */
  85. public function getParams()
  86. {
  87. return $this->params;
  88. }
  89. /**
  90. * Set params from key value array
  91. *
  92. * @param array $data
  93. * @return $this
  94. */
  95. public function setParams(array $data)
  96. {
  97. $this->params = $data;
  98. return $this;
  99. }
  100. /**
  101. * Stub to satisfy RequestInterface
  102. *
  103. * @param null|string $name
  104. * @param null|string $default
  105. * @return null|string|void
  106. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  107. */
  108. public function getCookie($name, $default)
  109. {
  110. }
  111. /**
  112. * Stub to satisfy RequestInterface
  113. *
  114. * @return bool
  115. */
  116. public function isSecure()
  117. {
  118. return false;
  119. }
  120. }