/usr/share/php/Doctrine/ORM/Query/Expr.php is in php-doctrine-orm 2.5.14+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | <?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Query;
/**
* This class is used to generate DQL expressions via a set of PHP static functions.
*
* @link www.doctrine-project.org
* @since 2.0
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @todo Rename: ExpressionBuilder
*/
class Expr
{
/**
* Creates a conjunction of the given boolean expressions.
*
* Example:
*
* [php]
* // (u.type = ?1) AND (u.role = ?2)
* $expr->andX($expr->eq('u.type', ':1'), $expr->eq('u.role', ':2'));
*
* @param \Doctrine\ORM\Query\Expr\Comparison |
* \Doctrine\ORM\Query\Expr\Func |
* \Doctrine\ORM\Query\Expr\Orx
* $x Optional clause. Defaults to null, but requires at least one defined when converting to string.
*
* @return Expr\Andx
*/
public function andX($x = null)
{
return new Expr\Andx(func_get_args());
}
/**
* Creates a disjunction of the given boolean expressions.
*
* Example:
*
* [php]
* // (u.type = ?1) OR (u.role = ?2)
* $q->where($q->expr()->orX('u.type = ?1', 'u.role = ?2'));
*
* @param mixed $x Optional clause. Defaults to null, but requires
* at least one defined when converting to string.
*
* @return Expr\Orx
*/
public function orX($x = null)
{
return new Expr\Orx(func_get_args());
}
/**
* Creates an ASCending order expression.
*
* @param mixed $expr
*
* @return Expr\OrderBy
*/
public function asc($expr)
{
return new Expr\OrderBy($expr, 'ASC');
}
/**
* Creates a DESCending order expression.
*
* @param mixed $expr
*
* @return Expr\OrderBy
*/
public function desc($expr)
{
return new Expr\OrderBy($expr, 'DESC');
}
/**
* Creates an equality comparison expression with the given arguments.
*
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> = <right expr>. Example:
*
* [php]
* // u.id = ?1
* $expr->eq('u.id', '?1');
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Comparison
*/
public function eq($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::EQ, $y);
}
/**
* Creates an instance of Expr\Comparison, with the given arguments.
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> <> <right expr>. Example:
*
* [php]
* // u.id <> ?1
* $q->where($q->expr()->neq('u.id', '?1'));
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Comparison
*/
public function neq($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::NEQ, $y);
}
/**
* Creates an instance of Expr\Comparison, with the given arguments.
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> < <right expr>. Example:
*
* [php]
* // u.id < ?1
* $q->where($q->expr()->lt('u.id', '?1'));
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Comparison
*/
public function lt($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::LT, $y);
}
/**
* Creates an instance of Expr\Comparison, with the given arguments.
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> <= <right expr>. Example:
*
* [php]
* // u.id <= ?1
* $q->where($q->expr()->lte('u.id', '?1'));
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Comparison
*/
public function lte($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::LTE, $y);
}
/**
* Creates an instance of Expr\Comparison, with the given arguments.
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> > <right expr>. Example:
*
* [php]
* // u.id > ?1
* $q->where($q->expr()->gt('u.id', '?1'));
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Comparison
*/
public function gt($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::GT, $y);
}
/**
* Creates an instance of Expr\Comparison, with the given arguments.
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> >= <right expr>. Example:
*
* [php]
* // u.id >= ?1
* $q->where($q->expr()->gte('u.id', '?1'));
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Comparison
*/
public function gte($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::GTE, $y);
}
/**
* Creates an instance of AVG() function, with the given argument.
*
* @param mixed $x Argument to be used in AVG() function.
*
* @return Expr\Func
*/
public function avg($x)
{
return new Expr\Func('AVG', array($x));
}
/**
* Creates an instance of MAX() function, with the given argument.
*
* @param mixed $x Argument to be used in MAX() function.
*
* @return Expr\Func
*/
public function max($x)
{
return new Expr\Func('MAX', array($x));
}
/**
* Creates an instance of MIN() function, with the given argument.
*
* @param mixed $x Argument to be used in MIN() function.
*
* @return Expr\Func
*/
public function min($x)
{
return new Expr\Func('MIN', array($x));
}
/**
* Creates an instance of COUNT() function, with the given argument.
*
* @param mixed $x Argument to be used in COUNT() function.
*
* @return Expr\Func
*/
public function count($x)
{
return new Expr\Func('COUNT', array($x));
}
/**
* Creates an instance of COUNT(DISTINCT) function, with the given argument.
*
* @param mixed $x Argument to be used in COUNT(DISTINCT) function.
*
* @return string
*/
public function countDistinct($x)
{
return 'COUNT(DISTINCT ' . implode(', ', func_get_args()) . ')';
}
/**
* Creates an instance of EXISTS() function, with the given DQL Subquery.
*
* @param mixed $subquery DQL Subquery to be used in EXISTS() function.
*
* @return Expr\Func
*/
public function exists($subquery)
{
return new Expr\Func('EXISTS', array($subquery));
}
/**
* Creates an instance of ALL() function, with the given DQL Subquery.
*
* @param mixed $subquery DQL Subquery to be used in ALL() function.
*
* @return Expr\Func
*/
public function all($subquery)
{
return new Expr\Func('ALL', array($subquery));
}
/**
* Creates a SOME() function expression with the given DQL subquery.
*
* @param mixed $subquery DQL Subquery to be used in SOME() function.
*
* @return Expr\Func
*/
public function some($subquery)
{
return new Expr\Func('SOME', array($subquery));
}
/**
* Creates an ANY() function expression with the given DQL subquery.
*
* @param mixed $subquery DQL Subquery to be used in ANY() function.
*
* @return Expr\Func
*/
public function any($subquery)
{
return new Expr\Func('ANY', array($subquery));
}
/**
* Creates a negation expression of the given restriction.
*
* @param mixed $restriction Restriction to be used in NOT() function.
*
* @return Expr\Func
*/
public function not($restriction)
{
return new Expr\Func('NOT', array($restriction));
}
/**
* Creates an ABS() function expression with the given argument.
*
* @param mixed $x Argument to be used in ABS() function.
*
* @return Expr\Func
*/
public function abs($x)
{
return new Expr\Func('ABS', array($x));
}
/**
* Creates a product mathematical expression with the given arguments.
*
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> * <right expr>. Example:
*
* [php]
* // u.salary * u.percentAnnualSalaryIncrease
* $q->expr()->prod('u.salary', 'u.percentAnnualSalaryIncrease')
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Math
*/
public function prod($x, $y)
{
return new Expr\Math($x, '*', $y);
}
/**
* Creates a difference mathematical expression with the given arguments.
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> - <right expr>. Example:
*
* [php]
* // u.monthlySubscriptionCount - 1
* $q->expr()->diff('u.monthlySubscriptionCount', '1')
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Math
*/
public function diff($x, $y)
{
return new Expr\Math($x, '-', $y);
}
/**
* Creates a sum mathematical expression with the given arguments.
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> + <right expr>. Example:
*
* [php]
* // u.numChildren + 1
* $q->expr()->diff('u.numChildren', '1')
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Math
*/
public function sum($x, $y)
{
return new Expr\Math($x, '+', $y);
}
/**
* Creates a quotient mathematical expression with the given arguments.
* First argument is considered the left expression and the second is the right expression.
* When converted to string, it will generated a <left expr> / <right expr>. Example:
*
* [php]
* // u.total / u.period
* $expr->quot('u.total', 'u.period')
*
* @param mixed $x Left expression.
* @param mixed $y Right expression.
*
* @return Expr\Math
*/
public function quot($x, $y)
{
return new Expr\Math($x, '/', $y);
}
/**
* Creates a SQRT() function expression with the given argument.
*
* @param mixed $x Argument to be used in SQRT() function.
*
* @return Expr\Func
*/
public function sqrt($x)
{
return new Expr\Func('SQRT', array($x));
}
/**
* Creates an IN() expression with the given arguments.
*
* @param string $x Field in string format to be restricted by IN() function.
* @param mixed $y Argument to be used in IN() function.
*
* @return Expr\Func
*/
public function in($x, $y)
{
if (is_array($y)) {
foreach ($y as &$literal) {
if ( ! ($literal instanceof Expr\Literal)) {
$literal = $this->_quoteLiteral($literal);
}
}
}
return new Expr\Func($x . ' IN', (array) $y);
}
/**
* Creates a NOT IN() expression with the given arguments.
*
* @param string $x Field in string format to be restricted by NOT IN() function.
* @param mixed $y Argument to be used in NOT IN() function.
*
* @return Expr\Func
*/
public function notIn($x, $y)
{
if (is_array($y)) {
foreach ($y as &$literal) {
if ( ! ($literal instanceof Expr\Literal)) {
$literal = $this->_quoteLiteral($literal);
}
}
}
return new Expr\Func($x . ' NOT IN', (array) $y);
}
/**
* Creates an IS NULL expression with the given arguments.
*
* @param string $x Field in string format to be restricted by IS NULL.
*
* @return string
*/
public function isNull($x)
{
return $x . ' IS NULL';
}
/**
* Creates an IS NOT NULL expression with the given arguments.
*
* @param string $x Field in string format to be restricted by IS NOT NULL.
*
* @return string
*/
public function isNotNull($x)
{
return $x . ' IS NOT NULL';
}
/**
* Creates a LIKE() comparison expression with the given arguments.
*
* @param string $x Field in string format to be inspected by LIKE() comparison.
* @param mixed $y Argument to be used in LIKE() comparison.
*
* @return Expr\Comparison
*/
public function like($x, $y)
{
return new Expr\Comparison($x, 'LIKE', $y);
}
/**
* Creates a NOT LIKE() comparison expression with the given arguments.
*
* @param string $x Field in string format to be inspected by LIKE() comparison.
* @param mixed $y Argument to be used in LIKE() comparison.
*
* @return Expr\Comparison
*/
public function notLike($x, $y)
{
return new Expr\Comparison($x, 'NOT LIKE', $y);
}
/**
* Creates a CONCAT() function expression with the given arguments.
*
* @param mixed $x First argument to be used in CONCAT() function.
* @param mixed $y Second argument to be used in CONCAT() function.
*
* @return Expr\Func
*/
public function concat($x, $y)
{
return new Expr\Func('CONCAT', array($x, $y));
}
/**
* Creates a SUBSTRING() function expression with the given arguments.
*
* @param mixed $x Argument to be used as string to be cropped by SUBSTRING() function.
* @param int $from Initial offset to start cropping string. May accept negative values.
* @param int|null $len Length of crop. May accept negative values.
*
* @return Expr\Func
*/
public function substring($x, $from, $len = null)
{
$args = array($x, $from);
if (null !== $len) {
$args[] = $len;
}
return new Expr\Func('SUBSTRING', $args);
}
/**
* Creates a LOWER() function expression with the given argument.
*
* @param mixed $x Argument to be used in LOWER() function.
*
* @return Expr\Func A LOWER function expression.
*/
public function lower($x)
{
return new Expr\Func('LOWER', array($x));
}
/**
* Creates an UPPER() function expression with the given argument.
*
* @param mixed $x Argument to be used in UPPER() function.
*
* @return Expr\Func An UPPER function expression.
*/
public function upper($x)
{
return new Expr\Func('UPPER', array($x));
}
/**
* Creates a LENGTH() function expression with the given argument.
*
* @param mixed $x Argument to be used as argument of LENGTH() function.
*
* @return Expr\Func A LENGTH function expression.
*/
public function length($x)
{
return new Expr\Func('LENGTH', array($x));
}
/**
* Creates a literal expression of the given argument.
*
* @param mixed $literal Argument to be converted to literal.
*
* @return Expr\Literal
*/
public function literal($literal)
{
return new Expr\Literal($this->_quoteLiteral($literal));
}
/**
* Quotes a literal value, if necessary, according to the DQL syntax.
*
* @param mixed $literal The literal value.
*
* @return string
*/
private function _quoteLiteral($literal)
{
if (is_numeric($literal) && !is_string($literal)) {
return (string) $literal;
} else if (is_bool($literal)) {
return $literal ? "true" : "false";
} else {
return "'" . str_replace("'", "''", $literal) . "'";
}
}
/**
* Creates an instance of BETWEEN() function, with the given argument.
*
* @param mixed $val Valued to be inspected by range values.
* @param integer $x Starting range value to be used in BETWEEN() function.
* @param integer $y End point value to be used in BETWEEN() function.
*
* @return Expr\Func A BETWEEN expression.
*/
public function between($val, $x, $y)
{
return $val . ' BETWEEN ' . $x . ' AND ' . $y;
}
/**
* Creates an instance of TRIM() function, with the given argument.
*
* @param mixed $x Argument to be used as argument of TRIM() function.
*
* @return Expr\Func a TRIM expression.
*/
public function trim($x)
{
return new Expr\Func('TRIM', $x);
}
/**
* Creates an instance of MEMBER OF function, with the given arguments.
*
* @param string $x Value to be checked
* @param string $y Value to be checked against
*
* @return Expr\Comparison
*/
public function isMemberOf($x, $y)
{
return new Expr\Comparison($x, 'MEMBER OF', $y);
}
/**
* Creates an instance of INSTANCE OF function, with the given arguments.
*
* @param string $x Value to be checked
* @param string $y Value to be checked against
*
* @return Expr\Comparison
*/
public function isInstanceOf($x, $y)
{
return new Expr\Comparison($x, 'INSTANCE OF', $y);
}
}
|