This repository has been archived by the owner on May 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryBuilder.php
92 lines (80 loc) · 2.1 KB
/
QueryBuilder.php
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
<?php
namespace Gos\Component\DoctrineQueryBuilder;
use Doctrine\ORM\QueryBuilder as DoctrineQueryBuilder;
class QueryBuilder extends DoctrineQueryBuilder implements QueryBuilderInterface
{
/**
* @var string
*/
protected $entityName;
/**
* @param string $entityName
*/
public function setEntityName($entityName)
{
$this->entityName = $entityName;
}
/**
* @return string
*/
public function getEntityName()
{
return $this->entityName;
}
/**
* @param array $groups
*/
public function load($groups = 'default')
{
foreach ((array) $groups as $group) {
$this->configure($group);
}
return $this;
}
/**
* @param $group
*/
protected function configure($group)
{
}
/**
* @return array
*/
protected function registerFilters()
{
return [];
}
/**
* @param $filterName
* @param array $parameters
*
* @return $this
* @throws \Exception
*/
public function applyFilter($filterName, $parameters = [])
{
if (!is_array($filters = $this->registerFilters())) {
throw new \Exception(sprintf("ApplyFilter should return array, %s given", gettype($this->registerFilters())));
}
if (array_key_exists($filterName, $filters)) {
if (method_exists($this, $filters[$filterName])) {
$this->{$filters[$filterName]}($parameters);
return $this;
} else {
throw new \Exception(sprintf("Method %s not exist in class %s", $filters[$filterName], get_class($this)));
}
} else {
throw new \Exception(sprintf("Filter %s not exist in %s", $filterName, join(', ', array_keys($filters))));
}
}
/**
* @param string $defaultTable
* @param array $parameters
*/
protected function setDefaultTable($defaultTable, array &$parameters = [])
{
if (!isset($parameters['table'])) {
$parameters['table'] = $defaultTable;
}
}
}