-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryBuilder.php
More file actions
95 lines (82 loc) · 2.72 KB
/
QueryBuilder.php
File metadata and controls
95 lines (82 loc) · 2.72 KB
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
<?php
/**
* This file is part of braincrafted/arrayquery.
*
* (c) Florian Eckerstorfer <florian@eckerstorfer.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Braincrafted\ArrayQuery;
use Braincrafted\ArrayQuery\Factory\FilterFactory;
use Braincrafted\ArrayQuery\Factory\OperatorFactory;
/**
* QueryBuilder
*
* @package braincrafted/arrayquery
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2013 Florian Eckerstorfer
* @license http://opensource.org/licenses/MIT The MIT License
*/
class QueryBuilder
{
/** @var SelectEvaluation */
private $selectEvaluation;
/** @var WhereEvaluation */
private $whereEvaluation;
/**
* @param SelectEvaluation $selectEvaluation
* @param WhereEvaluation $whereEvaluation
*/
public function __construct($selectEvaluation = null, $whereEvaluation = null)
{
$this->selectEvaluation = $this->getSelectEvaluation($selectEvaluation);
$this->whereEvaluation = $this->getWhereEvaluation($whereEvaluation);
}
/**
* @return ArrayQuery
*/
public function create()
{
return new ArrayQuery($this->selectEvaluation, $this->whereEvaluation);
}
/**
* @param SelectEvaluation $selectEvaluation
*
* @return SelectEvaluation
*/
protected function getSelectEvaluation($selectEvaluation = null)
{
if (null !== $selectEvaluation && false === ($selectEvaluation instanceof SelectEvaluation)) {
throw new \InvalidArgumentException('Argument "selectEvaluation" must be an instance of SelectEvaluation.');
}
if (null === $selectEvaluation) {
$selectEvaluation = new SelectEvaluation;
}
foreach (FilterFactory::getFilters() as $filter) {
$selectEvaluation->addFilter($filter);
}
return $selectEvaluation;
}
/**
* @param WhereEvaluation $whereEvaluation
*
* @return WhereEvaluation
*/
protected function getWhereEvaluation($whereEvaluation = null)
{
if (null !== $whereEvaluation && false === ($whereEvaluation instanceof WhereEvaluation)) {
throw new \InvalidArgumentException('Argument "whereEvaluation" must be an instance of WhereEvaluation.');
}
if (null === $whereEvaluation) {
$whereEvaluation = new WhereEvaluation;
}
foreach (OperatorFactory::getOperators() as $operator) {
$whereEvaluation->addOperator($operator);
}
foreach (FilterFactory::getFilters() as $filter) {
$whereEvaluation->addFilter($filter);
}
return $whereEvaluation;
}
}