Parameter.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\DB\Statement;
  7. /**
  8. * Magento DB Statement Parameter
  9. *
  10. * Used to transmit specific information about parameter value binding to be bound the right
  11. * way to the query.
  12. * Most used properties and methods are defined in interface. Specific things for concrete DB adapter can be
  13. * transmitted using 'addtional' property (\Magento\Framework\DataObject) as a container.
  14. *
  15. * @author Magento Core Team <core@magentocommerce.com>
  16. */
  17. class Parameter
  18. {
  19. /**
  20. * Actual parameter value
  21. *
  22. * @var mixed
  23. */
  24. protected $_value = null;
  25. /**
  26. * Value is a BLOB.
  27. *
  28. * A shortcut setting to notify DB adapter, that value must be bound in a default way, as adapter binds
  29. * BLOB data to query placeholders. If FALSE, then specific settings from $_dataType, $_length,
  30. * $_driverOptions will be used.
  31. * @var bool
  32. */
  33. protected $_isBlob = false;
  34. /**
  35. * Data type to set to DB driver during parameter bind
  36. * @var mixed
  37. */
  38. protected $_dataType = null;
  39. /**
  40. * Length to set to DB driver during parameter bind
  41. * @var mixed
  42. */
  43. protected $_length = null;
  44. /**
  45. * Specific driver options to set to DB driver during parameter bind
  46. * @var mixed
  47. */
  48. protected $_driverOptions = null;
  49. /**
  50. * Additional information to be used by DB adapter internally
  51. * @var \Magento\Framework\DataObject
  52. */
  53. protected $_additional = null;
  54. /**
  55. * Inits instance
  56. *
  57. * @param mixed $value
  58. */
  59. public function __construct($value)
  60. {
  61. $this->_value = $value;
  62. $this->_additional = new \Magento\Framework\DataObject();
  63. return $this;
  64. }
  65. /**
  66. * Sets parameter value.
  67. *
  68. * @param mixed $value
  69. * @return $this
  70. */
  71. public function setValue($value)
  72. {
  73. $this->_value = $value;
  74. return $this;
  75. }
  76. /**
  77. * Gets parameter value.
  78. *
  79. * @return mixed
  80. */
  81. public function getValue()
  82. {
  83. return $this->_value;
  84. }
  85. /**
  86. * Sets, whether parameter is a BLOB.
  87. *
  88. * FALSE (default) means, that concrete binding options come in dataType, length and driverOptions properties.
  89. * TRUE means that DB adapter must ignore other options and use adapter's default options to bind this parameter
  90. * as a BLOB value.
  91. *
  92. * @param bool $isBlob
  93. * @return $this
  94. */
  95. public function setIsBlob($isBlob)
  96. {
  97. $this->_isBlob = $isBlob;
  98. return $this;
  99. }
  100. /**
  101. * Gets, whether parameter is a BLOB.
  102. * See setIsBlob() for returned value explanation.
  103. *
  104. * @return bool
  105. *
  106. * @see setIsBlob
  107. * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  108. */
  109. public function getIsBlob()
  110. {
  111. return $this->_isBlob;
  112. }
  113. /**
  114. * Sets data type option to be used during binding parameter value.
  115. *
  116. * @param mixed $dataType
  117. * @return $this
  118. */
  119. public function setDataType($dataType)
  120. {
  121. $this->_dataType = $dataType;
  122. return $this;
  123. }
  124. /**
  125. * Gets data type option to be used during binding parameter value.
  126. *
  127. * @return mixed
  128. */
  129. public function getDataType()
  130. {
  131. return $this->_dataType;
  132. }
  133. /**
  134. * Sets length option to be used during binding parameter value.
  135. *
  136. * @param mixed $length
  137. * @return $this
  138. */
  139. public function setLength($length)
  140. {
  141. $this->_length = $length;
  142. return $this;
  143. }
  144. /**
  145. * Gets length option to be used during binding parameter value.
  146. *
  147. * @return mixed
  148. */
  149. public function getLength()
  150. {
  151. return $this->_length;
  152. }
  153. /**
  154. * Sets specific driver options to be used during binding parameter value.
  155. *
  156. * @param mixed $driverOptions
  157. * @return $this
  158. */
  159. public function setDriverOptions($driverOptions)
  160. {
  161. $this->_driverOptions = $driverOptions;
  162. return $this;
  163. }
  164. /**
  165. * Gets driver options to be used during binding parameter value.
  166. *
  167. * @return mixed
  168. */
  169. public function getDriverOptions()
  170. {
  171. return $this->_driverOptions;
  172. }
  173. /**
  174. * Sets additional information for concrete DB adapter.
  175. * Set there any data you want to pass along with query parameter.
  176. *
  177. * @param \Magento\Framework\DataObject $additional
  178. * @return $this
  179. */
  180. public function setAdditional($additional)
  181. {
  182. $this->_additional = $additional;
  183. return $this;
  184. }
  185. /**
  186. * Gets additional information for concrete DB adapter.
  187. *
  188. * @return \Magento\Framework\DataObject
  189. */
  190. public function getAdditional()
  191. {
  192. return $this->_additional;
  193. }
  194. /**
  195. * Returns representation of a object to be used in string contexts
  196. *
  197. * @return string
  198. */
  199. public function __toString()
  200. {
  201. return (string)$this->_value;
  202. }
  203. /**
  204. * Returns representation of a object to be used in string contexts
  205. *
  206. * @return string
  207. */
  208. public function toString()
  209. {
  210. return $this->__toString();
  211. }
  212. }