1
0

CompositeExpression.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\DB\QueryBuilder;
  24. use OCP\DB\QueryBuilder\ICompositeExpression;
  25. class CompositeExpression implements ICompositeExpression, \Countable {
  26. /** @var \Doctrine\DBAL\Query\Expression\CompositeExpression */
  27. protected $compositeExpression;
  28. /**
  29. * Constructor.
  30. *
  31. * @param \Doctrine\DBAL\Query\Expression\CompositeExpression $compositeExpression
  32. */
  33. public function __construct(\Doctrine\DBAL\Query\Expression\CompositeExpression $compositeExpression) {
  34. $this->compositeExpression = $compositeExpression;
  35. }
  36. /**
  37. * Adds multiple parts to composite expression.
  38. *
  39. * @param array $parts
  40. *
  41. * @return \OCP\DB\QueryBuilder\ICompositeExpression
  42. */
  43. public function addMultiple(array $parts = []): ICompositeExpression {
  44. $this->compositeExpression->addMultiple($parts);
  45. return $this;
  46. }
  47. /**
  48. * Adds an expression to composite expression.
  49. *
  50. * @param mixed $part
  51. *
  52. * @return \OCP\DB\QueryBuilder\ICompositeExpression
  53. */
  54. public function add($part): ICompositeExpression {
  55. $this->compositeExpression->add($part);
  56. return $this;
  57. }
  58. /**
  59. * Retrieves the amount of expressions on composite expression.
  60. *
  61. * @return integer
  62. */
  63. public function count(): int {
  64. return $this->compositeExpression->count();
  65. }
  66. /**
  67. * Returns the type of this composite expression (AND/OR).
  68. *
  69. * @return string
  70. */
  71. public function getType(): string {
  72. return $this->compositeExpression->getType();
  73. }
  74. /**
  75. * Retrieves the string representation of this composite expression.
  76. *
  77. * @return string
  78. */
  79. public function __toString(): string {
  80. return (string) $this->compositeExpression;
  81. }
  82. }