ExpressionBuilder.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYvalue 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 COPYvalue
  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\Common\Collections;
  20. use Doctrine\Common\Collections\Expr\Comparison;
  21. use Doctrine\Common\Collections\Expr\CompositeExpression;
  22. use Doctrine\Common\Collections\Expr\Value;
  23. /**
  24. * Builder for Expressions in the {@link Selectable} interface.
  25. *
  26. * @author Benjamin Eberlei <kontakt@beberlei.de>
  27. * @since 2.3
  28. */
  29. class ExpressionBuilder
  30. {
  31. /**
  32. * @return CompositeExpression
  33. */
  34. public function andX($x = null)
  35. {
  36. return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
  37. }
  38. /**
  39. * @return CompositeExpression
  40. */
  41. public function orX($x = null)
  42. {
  43. return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
  44. }
  45. /**
  46. * @param string $field
  47. * @param mixed $value
  48. *
  49. * @return Comparison
  50. */
  51. public function eq($field, $value)
  52. {
  53. return new Comparison($field, Comparison::EQ, new Value($value));
  54. }
  55. /**
  56. * @param string $field
  57. * @param mixed $value
  58. *
  59. * @return Comparison
  60. */
  61. public function gt($field, $value)
  62. {
  63. return new Comparison($field, Comparison::GT, new Value($value));
  64. }
  65. /**
  66. * @param string $field
  67. * @param mixed $value
  68. *
  69. * @return Comparison
  70. */
  71. public function lt($field, $value)
  72. {
  73. return new Comparison($field, Comparison::LT, new Value($value));
  74. }
  75. /**
  76. * @param string $field
  77. * @param mixed $value
  78. *
  79. * @return Comparison
  80. */
  81. public function gte($field, $value)
  82. {
  83. return new Comparison($field, Comparison::GTE, new Value($value));
  84. }
  85. /**
  86. * @param string $field
  87. * @param mixed $value
  88. *
  89. * @return Comparison
  90. */
  91. public function lte($field, $value)
  92. {
  93. return new Comparison($field, Comparison::LTE, new Value($value));
  94. }
  95. /**
  96. * @param string $field
  97. * @param mixed $value
  98. *
  99. * @return Comparison
  100. */
  101. public function neq($field, $value)
  102. {
  103. return new Comparison($field, Comparison::NEQ, new Value($value));
  104. }
  105. /**
  106. * @param string $field
  107. * @param mixed $value
  108. *
  109. * @return Comparison
  110. */
  111. public function isNull($field)
  112. {
  113. return new Comparison($field, Comparison::IS, new Value(null));
  114. }
  115. /**
  116. * @param string $field
  117. * @param mixed $value
  118. *
  119. * @return Comparison
  120. */
  121. public function in($field, array $values)
  122. {
  123. return new Comparison($field, Comparison::IN, new Value($values));
  124. }
  125. /**
  126. * @param string $field
  127. * @param mixed $value
  128. *
  129. * @return Comparison
  130. */
  131. public function notIn($field, array $values)
  132. {
  133. return new Comparison($field, Comparison::NIN, new Value($values));
  134. }
  135. }