expression-builder.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. Expression Builder
  2. ==================
  3. The Expression Builder is a convenient fluent interface for
  4. building expressions to be used with the ``Doctrine\Common\Collections\Criteria``
  5. class:
  6. .. code-block:: php
  7. $expressionBuilder = Criteria::expr();
  8. $criteria = new Criteria();
  9. $criteria->where($expressionBuilder->eq('name', 'jwage'));
  10. $criteria->orWhere($expressionBuilder->eq('name', 'romanb'));
  11. $collection->matching($criteria);
  12. The ``ExpressionBuilder`` has the following API:
  13. andX
  14. ----
  15. .. code-block:: php
  16. $expressionBuilder = Criteria::expr();
  17. $expression = $expressionBuilder->andX(
  18. $expressionBuilder->eq('foo', 1),
  19. $expressionBuilder->eq('bar', 1)
  20. );
  21. $collection->matching(new Criteria($expression));
  22. orX
  23. ---
  24. .. code-block:: php
  25. $expressionBuilder = Criteria::expr();
  26. $expression = $expressionBuilder->orX(
  27. $expressionBuilder->eq('foo', 1),
  28. $expressionBuilder->eq('bar', 1)
  29. );
  30. $collection->matching(new Criteria($expression));
  31. eq
  32. ---
  33. .. code-block:: php
  34. $expressionBuilder = Criteria::expr();
  35. $expression = $expressionBuilder->eq('foo', 1);
  36. $collection->matching(new Criteria($expression));
  37. gt
  38. ---
  39. .. code-block:: php
  40. $expressionBuilder = Criteria::expr();
  41. $expression = $expressionBuilder->gt('foo', 1);
  42. $collection->matching(new Criteria($expression));
  43. lt
  44. ---
  45. .. code-block:: php
  46. $expressionBuilder = Criteria::expr();
  47. $expression = $expressionBuilder->lt('foo', 1);
  48. $collection->matching(new Criteria($expression));
  49. gte
  50. ---
  51. .. code-block:: php
  52. $expressionBuilder = Criteria::expr();
  53. $expression = $expressionBuilder->gte('foo', 1);
  54. $collection->matching(new Criteria($expression));
  55. lte
  56. ---
  57. .. code-block:: php
  58. $expressionBuilder = Criteria::expr();
  59. $expression = $expressionBuilder->lte('foo', 1);
  60. $collection->matching(new Criteria($expression));
  61. neq
  62. ---
  63. .. code-block:: php
  64. $expressionBuilder = Criteria::expr();
  65. $expression = $expressionBuilder->neq('foo', 1);
  66. $collection->matching(new Criteria($expression));
  67. isNull
  68. ------
  69. .. code-block:: php
  70. $expressionBuilder = Criteria::expr();
  71. $expression = $expressionBuilder->isNull('foo');
  72. $collection->matching(new Criteria($expression));
  73. in
  74. ---
  75. .. code-block:: php
  76. $expressionBuilder = Criteria::expr();
  77. $expression = $expressionBuilder->in('foo', ['value1', 'value2']);
  78. $collection->matching(new Criteria($expression));
  79. notIn
  80. -----
  81. .. code-block:: php
  82. $expressionBuilder = Criteria::expr();
  83. $expression = $expressionBuilder->notIn('foo', ['value1', 'value2']);
  84. $collection->matching(new Criteria($expression));
  85. contains
  86. --------
  87. .. code-block:: php
  88. $expressionBuilder = Criteria::expr();
  89. $expression = $expressionBuilder->contains('foo', 'value1');
  90. $collection->matching(new Criteria($expression));
  91. memberOf
  92. --------
  93. .. code-block:: php
  94. $expressionBuilder = Criteria::expr();
  95. $expression = $expressionBuilder->memberOf('foo', ['value1', 'value2']);
  96. $collection->matching(new Criteria($expression));
  97. startsWith
  98. ----------
  99. .. code-block:: php
  100. $expressionBuilder = Criteria::expr();
  101. $expression = $expressionBuilder->startsWith('foo', 'hello');
  102. $collection->matching(new Criteria($expression));
  103. endsWith
  104. --------
  105. .. code-block:: php
  106. $expressionBuilder = Criteria::expr();
  107. $expression = $expressionBuilder->endsWith('foo', 'world');
  108. $collection->matching(new Criteria($expression));