|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\ORM\Query\Expr; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Expression class for building DQL Order By parts. |
|
24
|
|
|
* |
|
25
|
|
|
* @link www.doctrine-project.org |
|
26
|
|
|
* @since 2.0 |
|
27
|
|
|
* @author Guilherme Blanco <[email protected]> |
|
28
|
|
|
* @author Jonathan Wage <[email protected]> |
|
29
|
|
|
* @author Roman Borschel <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
|
|
class OrderBy |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $preSeparator = ''; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $separator = ', '; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $postSeparator = ''; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $allowedClasses = []; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var array |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $parts = []; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param string|null $sort |
|
60
|
|
|
* @param string|null $order |
|
61
|
|
|
*/ |
|
62
|
16 |
|
public function __construct($sort = null, $order = null) |
|
63
|
|
|
{ |
|
64
|
16 |
|
if ($sort) { |
|
|
|
|
|
|
65
|
16 |
|
$this->add($sort, $order); |
|
66
|
|
|
} |
|
67
|
16 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param string $sort |
|
71
|
|
|
* @param string|null $order |
|
72
|
|
|
* |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
16 |
|
public function add($sort, $order = null) |
|
76
|
|
|
{ |
|
77
|
16 |
|
$order = ! $order ? 'ASC' : $order; |
|
78
|
16 |
|
$this->parts[] = $sort . ' '. $order; |
|
79
|
16 |
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return integer |
|
83
|
|
|
*/ |
|
84
|
1 |
|
public function count() |
|
85
|
|
|
{ |
|
86
|
1 |
|
return count($this->parts); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return array |
|
91
|
|
|
*/ |
|
92
|
1 |
|
public function getParts() |
|
93
|
|
|
{ |
|
94
|
1 |
|
return $this->parts; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
12 |
|
public function __toString() |
|
101
|
|
|
{ |
|
102
|
12 |
|
return $this->preSeparator . implode($this->separator, $this->parts) . $this->postSeparator; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: