This repository was archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathFilterableTrait.php
76 lines (64 loc) · 2.02 KB
/
FilterableTrait.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
<?php
/**
* This file is part of the SgDatatablesBundle package.
*
* (c) stwe <https://github.com/stwe/DatatablesBundle>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sg\DatatablesBundle\Datatable\Column;
use Sg\DatatablesBundle\Datatable\Filter\FilterInterface;
use Sg\DatatablesBundle\Datatable\Factory;
use Exception;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
* Class FilterableTrait
*
* @package Sg\DatatablesBundle\Datatable\Column
*/
trait FilterableTrait
{
/**
* A FilterInterface instance for individual filtering.
* Default: See the column type.
*
* @var FilterInterface
*/
protected $filter;
//-------------------------------------------------
// Getters && Setters
//-------------------------------------------------
/**
* Get Filter instance.
*
* @return FilterInterface
*/
public function getFilter()
{
return $this->filter;
}
/**
* Set Filter instance.
*
* @param array $filterClassAndOptions
*
* @return $this
* @throws Exception
*/
public function setFilter(array $filterClassAndOptions)
{
if (count($filterClassAndOptions) != 2) {
throw new Exception('AbstractColumn::setFilter(): Two arguments expected.');
}
if (!isset($filterClassAndOptions[0]) || !is_string($filterClassAndOptions[0]) && !$filterClassAndOptions[0] instanceof FilterInterface) {
throw new Exception('AbstractColumn::setFilter(): Set a Filter class.');
}
if (!isset($filterClassAndOptions[1]) || !is_array($filterClassAndOptions[1])) {
throw new Exception('AbstractColumn::setFilter(): Set an options array.');
}
$newFilter = Factory::create($this->container, $filterClassAndOptions[0], FilterInterface::class);
$this->filter = $newFilter->set($filterClassAndOptions[1]);
return $this;
}
}