1 | <?php |
||
14 | abstract class BaseSerializer implements \JsonSerializable |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * borrowed |
||
19 | * |
||
20 | * @var unknown |
||
21 | */ |
||
22 | protected $arguments = [ |
||
23 | 'read_only', |
||
24 | 'write_only', |
||
25 | 'required', |
||
26 | 'default', |
||
27 | 'initial', |
||
28 | 'source', |
||
29 | 'label', |
||
30 | 'help_text', |
||
31 | 'style', |
||
32 | 'error_messages', |
||
33 | 'allow_empty', |
||
34 | 'instance', |
||
35 | 'data', |
||
36 | 'partial', |
||
37 | 'context', |
||
38 | 'allow_null' |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * available methods |
||
43 | * based on the serializer type |
||
44 | * should not be settable except from inside the serializer |
||
45 | * |
||
46 | * @var unknown |
||
47 | */ |
||
48 | protected $methods = []; |
||
49 | |||
50 | protected $fillable = []; |
||
51 | |||
52 | protected $initialData = []; |
||
53 | |||
54 | protected $data = []; |
||
55 | |||
56 | protected $requiredOptions = []; |
||
57 | |||
58 | /** |
||
59 | * This is pretty important |
||
60 | * It is going to hold a list of all the fields and their types. |
||
61 | * Each one has to get loaded up by factory. |
||
62 | * |
||
63 | * Collection of DataFields mapped to field names |
||
64 | */ |
||
65 | protected $dataFields = null; |
||
66 | |||
67 | 9 | public function __construct($initialData = []) |
|
73 | |||
74 | /** |
||
75 | * this is where your definitions will go. |
||
76 | */ |
||
77 | abstract public function initDataFields(); |
||
78 | |||
79 | 9 | public function setInitialData($initialData) |
|
84 | |||
85 | 9 | public function addField($name, DataField $field) |
|
91 | |||
92 | 4 | public function getField($name) |
|
96 | |||
97 | 4 | public function getDataFieldCollection() |
|
101 | |||
102 | /** |
||
103 | * not the same as fill data - it should prob be depricated |
||
104 | * |
||
105 | * @param unknown $data |
||
106 | */ |
||
107 | abstract public function loadData($data); |
||
108 | |||
109 | /** |
||
110 | * |
||
111 | * @throws \RuntimeException |
||
112 | */ |
||
113 | 1 | public function create() |
|
117 | |||
118 | /** |
||
119 | * |
||
120 | * @throws \RuntimeException |
||
121 | */ |
||
122 | 1 | public function update() |
|
126 | |||
127 | /** |
||
128 | * should get implemented at the concrete levels |
||
129 | */ |
||
130 | 1 | public function save() |
|
134 | |||
135 | /** |
||
136 | * (non-PHPdoc) |
||
137 | * |
||
138 | * @see JsonSerializable::jsonSerialize() |
||
139 | */ |
||
140 | abstract public function jsonSerialize(); |
||
141 | } |
||
142 |