1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Happyr Doctrine Specification package. |
5
|
|
|
* |
6
|
|
|
* (c) Tobias Nyholm <[email protected]> |
7
|
|
|
* Kacper Gunia <[email protected]> |
8
|
|
|
* Peter Gribanov <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Happyr\DoctrineSpecification\Operand; |
15
|
|
|
|
16
|
|
|
use Doctrine\ORM\QueryBuilder; |
17
|
|
|
use Happyr\DoctrineSpecification\Exception\InvalidArgumentException; |
18
|
|
|
|
19
|
|
|
@trigger_error('The '.__NAMESPACE__.'\Bitwise class is deprecated since version 1.1 and will be removed in 2.0.', E_USER_DEPRECATED); |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @deprecated This class is deprecated since version 1.1 and will be removed in 2.0. |
23
|
|
|
*/ |
24
|
|
|
abstract class Bitwise implements Operand |
25
|
|
|
{ |
26
|
|
|
const B_AND = '&'; |
27
|
|
|
|
28
|
|
|
const B_OR = '|'; |
29
|
|
|
|
30
|
|
|
const B_XOR = '^'; |
31
|
|
|
|
32
|
|
|
const B_LS = '<<'; |
33
|
|
|
|
34
|
|
|
const B_RS = '>>'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string[] |
38
|
|
|
*/ |
39
|
|
|
private static $operations = [ |
40
|
|
|
self::B_AND, |
41
|
|
|
self::B_OR, |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $operation; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var Operand|string |
51
|
|
|
*/ |
52
|
|
|
private $field; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var Operand|string |
56
|
|
|
*/ |
57
|
|
|
private $value; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $operation |
61
|
|
|
* @param Operand|string $field |
62
|
|
|
* @param Operand|string $value |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
public function __construct($operation, $field, $value) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
if (!in_array($operation, self::$operations, true)) { |
67
|
|
|
throw new InvalidArgumentException(sprintf( |
68
|
|
|
'"%s" is not a valid bitwise operation. Valid operations are: "%s"', |
69
|
|
|
$operation, |
70
|
|
|
implode(', ', self::$operations) |
71
|
|
|
)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->operation = $operation; |
75
|
|
|
$this->field = $field; |
76
|
|
|
$this->value = $value; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param QueryBuilder $qb |
81
|
|
|
* @param string $dqlAlias |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function transform(QueryBuilder $qb, $dqlAlias) |
86
|
|
|
{ |
87
|
|
|
$function = self::B_AND === $this->operation ? 'BIT_AND' : 'BIT_OR'; |
88
|
|
|
|
89
|
|
|
return (new PlatformFunction($function, $this->field, $this->value))->transform($qb, $dqlAlias); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: