1 | <?php |
||
4 | abstract class AbstractModel |
||
5 | { |
||
6 | |||
7 | /** |
||
8 | * |
||
9 | * MUST be redefined by concrete class with the model schema |
||
10 | * Each array element is composed by a propery name and and property options. |
||
11 | * Property option is an array with following (optional) fields: |
||
12 | * 'default' a value to be used for the propery |
||
13 | * 'filter' a php filter |
||
14 | * 'options' php filter options |
||
15 | * 'flags' php filter flags |
||
16 | * |
||
17 | * Example:array ( |
||
18 | * 'legalName' => array( |
||
19 | * 'filter' => FILTER_CALLBACK, |
||
20 | * 'options' => '\BOTK\Filters::FILTER_NORMALIZZE_ADDRESS', |
||
21 | * ), |
||
22 | * 'alternateName' => array( |
||
23 | 'flags' => FILTER_FORCE_ARRAY, |
||
24 | * ), |
||
25 | * 'postalCode' => array( // italian rules |
||
26 | * 'filter' => FILTER_VALIDATE_REGEXP, |
||
27 | * 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
||
28 | * 'flags' => FILTER_REQUIRE_SCALAR, |
||
29 | * ), |
||
30 | * ) |
||
31 | */ |
||
32 | protected static $DEFAULT_OPTIONS = array( |
||
33 | 'base' => array( |
||
34 | 'default' => 'urn:resource:', |
||
35 | 'filter' => FILTER_CALLBACK, |
||
36 | 'options' => '\BOTK\Filters::FILTER_VALIDATE_URI', |
||
37 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
38 | ), |
||
39 | ); |
||
40 | |||
41 | |||
42 | /** |
||
43 | * known vocabularies |
||
44 | */ |
||
45 | protected static $VOCABULARY = array( |
||
46 | 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
||
47 | 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
||
48 | ); |
||
49 | |||
50 | |||
51 | protected $options ; |
||
52 | |||
53 | protected $data; |
||
54 | protected $rdf =null; //lazy created |
||
55 | protected $tripleCount=0; //lazy created |
||
56 | protected $uniqueIdGenerator=null; // dependency injections |
||
57 | protected $droppedFields = array(); |
||
58 | |||
59 | |||
60 | 12 | protected static function mergeOptions( array $options1, array $options2 ) |
|
71 | |||
72 | |||
73 | 12 | protected static function constructOptions() |
|
83 | |||
84 | |||
85 | /** |
||
86 | * Do not call directlty constructor, use fromArray or other factory methodsinstead |
||
87 | */ |
||
88 | 12 | protected function __construct(array $data = array(), array $customOptions = array()) |
|
116 | |||
117 | |||
118 | |||
119 | /** |
||
120 | * Create an instance from an associative array |
||
121 | */ |
||
122 | 12 | public static function fromArray(array $data, array $customOptions = array()) |
|
126 | |||
127 | |||
128 | /** |
||
129 | * Create an instance from an generic standard object |
||
130 | */ |
||
131 | 1 | public static function fromStdObject( \stdClass $obj, array $customOptions = array()) |
|
135 | |||
136 | |||
137 | 4 | public static function getVocabularies() |
|
147 | |||
148 | |||
149 | 3 | public static function getTurtleHeader($base=null) |
|
159 | |||
160 | |||
161 | public function getDroppedFields() |
||
165 | |||
166 | |||
167 | /** |
||
168 | * dependecy injection setter |
||
169 | */ |
||
170 | 12 | public function setIdGenerator($generator) |
|
177 | |||
178 | |||
179 | /** |
||
180 | * returns an uri |
||
181 | */ |
||
182 | 6 | public function getUri($id=null, $suffix='') |
|
195 | |||
196 | |||
197 | 1 | public function getOptions() |
|
201 | |||
202 | |||
203 | 1 | public function getTripleCount() |
|
212 | |||
213 | |||
214 | 2 | public function asArray() |
|
218 | |||
219 | |||
220 | |||
221 | 1 | public function asStdObject() |
|
225 | |||
226 | |||
227 | /** |
||
228 | * metadata not yet implemented |
||
229 | */ |
||
230 | 1 | public function asLinkedData() |
|
235 | |||
236 | |||
237 | 1 | public function asString() |
|
241 | |||
242 | |||
243 | 1 | public function __toString() |
|
247 | |||
248 | |||
249 | /** |
||
250 | * adds a turtle fragment managing cardinality > 1 |
||
251 | */ |
||
252 | 1 | protected function addFragment($format, $var, $sanitize=true){ |
|
260 | |||
261 | /** |
||
262 | * this must be implemented |
||
263 | */ |
||
264 | abstract public function asTurtleFragment(); |
||
265 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.