1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2016 Beñat Espiña <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace BenatEspina\StackExchangeApiClient\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class filter model class. |
16
|
|
|
* |
17
|
|
|
* @author Beñat Espiña <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Filter implements Model |
20
|
|
|
{ |
21
|
|
|
const FILTER_TYPES = ['invalid', 'safe', 'unsafe']; |
22
|
|
|
|
23
|
|
|
protected $filter; |
24
|
|
|
protected $filterType; |
25
|
|
|
protected $includedFields; |
26
|
|
|
|
27
|
|
|
public static function fromJson(array $data) |
28
|
|
|
{ |
29
|
|
|
$instance = new self(); |
30
|
|
|
$instance |
31
|
|
|
->setFilter(array_key_exists('filter', $data) ? $data['filter'] : null) |
32
|
|
|
->setFilterType(array_key_exists('filter_type', $data) ? $data['filter_type'] : null) |
33
|
|
|
->setIncludedFields(array_key_exists('included_fields', $data) ? $data['included_fields'] : null); |
34
|
|
|
|
35
|
|
|
return $instance; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public static function fromProperties($filter, $filterType, array $includedFields) |
39
|
|
|
{ |
40
|
|
|
$instance = new self(); |
41
|
|
|
$instance |
42
|
|
|
->setFilter($filter) |
43
|
|
|
->setFilterType($filterType) |
44
|
|
|
->setIncludedFields($includedFields); |
45
|
|
|
|
46
|
|
|
return $instance; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setFilter($filter) |
50
|
|
|
{ |
51
|
|
|
$this->filter = $filter; |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getFilter() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
return $this->filter; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function setFilterType($filterType) |
62
|
|
|
{ |
63
|
|
|
if (in_array($filterType, self::FILTER_TYPES, true)) { |
64
|
|
|
$this->filterType = $filterType; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getFilterType() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
return $this->filterType; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setIncludedFields(array $includedFields = []) |
76
|
|
|
{ |
77
|
|
|
$this->includedFields = $includedFields; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getIncludedFields() |
83
|
|
|
{ |
84
|
|
|
return $this->includedFields; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.