Parameter.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\ORM\Query;
  20. /**
  21. * Define a Query Parameter
  22. *
  23. * @link www.doctrine-project.org
  24. * @since 2.3
  25. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  26. */
  27. class Parameter
  28. {
  29. /**
  30. * @var string Parameter name
  31. */
  32. private $name;
  33. /**
  34. * @var mixed Parameter value
  35. */
  36. private $value;
  37. /**
  38. * @var mixed Parameter type
  39. */
  40. private $type;
  41. /**
  42. * Constructor.
  43. *
  44. * @param string $name Parameter name
  45. * @param mixed $value Parameter value
  46. * @param mixed $type Parameter type
  47. */
  48. public function __construct($name, $value, $type = null)
  49. {
  50. $this->name = trim($name, ':');
  51. $this->setValue($value, $type);
  52. }
  53. /**
  54. * Retrieve the Parameter name.
  55. *
  56. * @return string
  57. */
  58. public function getName()
  59. {
  60. return $this->name;
  61. }
  62. /**
  63. * Retrieve the Parameter value.
  64. *
  65. * @return mixed
  66. */
  67. public function getValue()
  68. {
  69. return $this->value;
  70. }
  71. /**
  72. * Retrieve the Parameter type.
  73. *
  74. * @return mixed
  75. */
  76. public function getType()
  77. {
  78. return $this->type;
  79. }
  80. /**
  81. * Define the Parameter value.
  82. *
  83. * @param mixed $value Parameter value
  84. * @param mixed $type Parameter type
  85. */
  86. public function setValue($value, $type = null)
  87. {
  88. $this->value = $value;
  89. $this->type = $type ?: ParameterTypeInferer::inferType($value);
  90. }
  91. }