1 | <?php |
||
7 | class Rule |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $method; |
||
13 | |||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $arguments; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $sugarMap = [ |
||
23 | 'select' => [ |
||
24 | 'select', 'addSelect' |
||
25 | ], |
||
26 | 'where' => [ |
||
27 | 'where', 'orWhere', |
||
28 | 'whereBetween', 'orWhereBetween', 'whereNotBetween', 'orWhereNotBetween', |
||
29 | 'whereExists', 'orWhereExists', 'whereNotExists', 'orWhereNotExists', |
||
30 | 'whereIn', 'orWhereIn', 'whereNotIn', 'orWhereNotIn', |
||
31 | 'whereNull', 'orWhereNull', 'whereNotNull', 'orWhereNotNull', |
||
32 | 'whereDate', 'whereDay', 'whereMonth', 'whereYear', |
||
33 | ], |
||
34 | 'having' => [ |
||
35 | 'having', 'orHaving', |
||
36 | ], |
||
37 | 'orderBy' => [ |
||
38 | 'orderBy', 'latest', 'oldest', |
||
39 | ], |
||
40 | 'offset' => [ |
||
41 | 'offset', 'skip', |
||
42 | ], |
||
43 | 'limit' => [ |
||
44 | 'limit', 'take', 'forPage', |
||
45 | ], |
||
46 | ]; |
||
47 | |||
48 | /** |
||
49 | * Create a new rule instance. |
||
50 | * |
||
51 | * @param string $method |
||
52 | * @param array $arguments |
||
53 | */ |
||
54 | public function __construct($method, array $arguments = []) |
||
59 | |||
60 | /** |
||
61 | * Test if the method call passes this rule. |
||
62 | * |
||
63 | * @param MethodCall $call |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function test(MethodCall $call) |
||
71 | |||
72 | /** |
||
73 | * Test if the given value matches the required method pattern. |
||
74 | * |
||
75 | * @param string $value |
||
76 | * @return bool |
||
77 | */ |
||
78 | protected function methodMatches($value) |
||
82 | |||
83 | /** |
||
84 | * Test if the given arguments match the required arguments signature. |
||
85 | * |
||
86 | * @param array $arguments |
||
87 | * @return bool |
||
88 | */ |
||
89 | protected function argumentListMatches(array $arguments) |
||
104 | |||
105 | /** |
||
106 | * Compare the given value to the given pattern. |
||
107 | * |
||
108 | * @param string $pattern |
||
109 | * @param string $value |
||
110 | * @return bool |
||
111 | */ |
||
112 | protected function comparePattern($pattern, $value) |
||
137 | } |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.