1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Chadicus\Marvel\Api; |
4
|
|
|
|
5
|
|
|
use DominionEnterprises\Filterer as BaseFilterer; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Custom filterer for sanitizing API result data. |
9
|
|
|
*/ |
10
|
|
|
abstract class Filterer |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Array of filter aliases for use with BaseFilter. |
14
|
|
|
* |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
private static $filterAliases = [ |
18
|
|
|
'_date' => '\Chadicus\Marvel\Api\Entities\Date::fromArray', |
19
|
|
|
'_dates' => '\Chadicus\Marvel\Api\Entities\Date::fromArrays', |
20
|
|
|
'image' => '\Chadicus\Marvel\Api\Entities\Image::fromArray', |
21
|
|
|
'images' => '\Chadicus\Marvel\Api\Entities\Image::fromArrays', |
22
|
|
|
'price' => '\Chadicus\Marvel\Api\Entities\Price::fromArray', |
23
|
|
|
'prices' => '\Chadicus\Marvel\Api\Entities\Price::fromArrays', |
24
|
|
|
'resource-list' => '\Chadicus\Marvel\Api\Entities\ResourceList::fromArray', |
25
|
|
|
'summary' => '\Chadicus\Marvel\Api\Entities\Summary::fromArray', |
26
|
|
|
'summaries' => '\Chadicus\Marvel\Api\Entities\Summary::fromArrays', |
27
|
|
|
'text-object' => '\Chadicus\Marvel\Api\Entities\TextObject::fromArray', |
28
|
|
|
'text-objects' => '\Chadicus\Marvel\Api\Entities\TextObject::fromArrays', |
29
|
|
|
'_url' => '\Chadicus\Marvel\Api\Entities\Url::fromArray', |
30
|
|
|
'_urls' => '\Chadicus\Marvel\Api\Entities\Url::fromArrays', |
31
|
|
|
'character' => '\Chadicus\Marvel\Api\Entities\Character::fromArray', |
32
|
|
|
'characters' => '\Chadicus\Marvel\Api\Entities\Character::fromArrays', |
33
|
|
|
'comic' => '\Chadicus\Marvel\Api\Entities\Comic::fromArray', |
34
|
|
|
'comics' => '\Chadicus\Marvel\Api\Entities\Comic::fromArrays', |
35
|
|
|
'series' => '\Chadicus\Marvel\Api\Entities\Series::fromArrays', |
36
|
|
|
'events' => '\Chadicus\Marvel\Api\Entities\Event::fromArrays', |
37
|
|
|
'stories' => '\Chadicus\Marvel\Api\Entities\Story::fromArrays', |
38
|
|
|
'creators' => '\Chadicus\Marvel\Api\Entities\Creator::fromArrays', |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @see \DominionEntepries\Filterer::filter(). |
43
|
|
|
* |
44
|
|
|
* @param array $spec The filter specification. |
45
|
|
|
* @param array $input The data to be filtered. |
46
|
|
|
* @param array $options Array of filterer options. |
47
|
|
|
* |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
final public static function filter(array $spec, array $input, array $options = []) : array |
51
|
|
|
{ |
52
|
|
|
BaseFilterer::setFilterAliases(self::$filterAliases + BaseFilterer::getFilterAliases()); |
53
|
|
|
return BaseFilterer::filter($spec, $input, $options); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|