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 | 'uri' => array( |
||
34 | 'filter' => FILTER_CALLBACK, |
||
35 | 'options' => '\BOTK\Filters::FILTER_VALIDATE_URI', |
||
36 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
37 | ), |
||
38 | 'base' => array( |
||
39 | 'default' => 'urn:local:', |
||
40 | 'filter' => FILTER_CALLBACK, |
||
41 | 'options' => '\BOTK\Filters::FILTER_VALIDATE_URI', |
||
42 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
43 | ), |
||
44 | 'id' => array( |
||
45 | 'filter' => FILTER_CALLBACK, |
||
46 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_ID', |
||
47 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
48 | ), |
||
49 | 'page' => array( |
||
50 | 'filter' => FILTER_VALIDATE_URL, |
||
51 | 'flags' => FILTER_FORCE_ARRAY, |
||
52 | ), |
||
53 | 'homepage' => array( |
||
54 | 'filter' => FILTER_VALIDATE_URL, |
||
55 | 'flags' => FILTER_FORCE_ARRAY, |
||
56 | ), |
||
57 | 'near' => array( |
||
58 | 'filter' => FILTER_CALLBACK, |
||
59 | 'options' => '\BOTK\Filters::FILTER_VALIDATE_URI', |
||
60 | 'flags' => FILTER_FORCE_ARRAY, |
||
61 | ), |
||
62 | 'similarName' => array( |
||
63 | 'filter' => FILTER_CALLBACK, |
||
64 | 'options' => '\BOTK\Filters::FILTER_VALIDATE_URI', |
||
65 | 'flags' => FILTER_FORCE_ARRAY, |
||
66 | ), |
||
67 | ); |
||
68 | |||
69 | /** |
||
70 | * known vocabularies |
||
71 | */ |
||
72 | protected static $VOCABULARY = array( |
||
73 | 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
||
74 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
||
75 | 'owl' => 'http://www.w3.org/2002/07/owl#', |
||
76 | 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
||
77 | 'dct' => 'http://purl.org/dc/terms/', |
||
78 | 'void' => 'http://rdfs.org/ns/void#', |
||
79 | 'prov' => 'http://www.w3.org/ns/prov#', |
||
80 | 'sd' => 'http://www.w3.org/ns/sparql-service-description#', |
||
81 | 'schema' => 'http://schema.org/', |
||
82 | 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
||
83 | 'foaf' => 'http://xmlns.com/foaf/0.1/', |
||
84 | 'qb' => 'http://purl.org/linked-data/cube#', |
||
85 | 'daq' => 'http://purl.org/eis/vocab/daq#', |
||
86 | 'kees' => 'http://linkeddata.center/kees/v1#', |
||
87 | 'botk' => 'http://botk.linkeddata.center/#', |
||
88 | ); |
||
89 | |||
90 | |||
91 | protected $options ; |
||
92 | |||
93 | protected $data; |
||
94 | protected $rdf =null; //lazy created |
||
95 | protected $tripleCount=0; //lazy created |
||
96 | protected $uniqueIdGenerator=null; // dependency injections |
||
97 | protected $droppedFields = array(); |
||
98 | |||
99 | |||
100 | 27 | protected static function mergeOptions( array $options1, array $options2 ) |
|
111 | |||
112 | |||
113 | 27 | protected static function constructOptions() |
|
123 | |||
124 | |||
125 | /** |
||
126 | * Do not call directlty constructor, use fromArray or other factory methodsinstead |
||
127 | */ |
||
128 | 27 | protected function __construct(array $data = array(), array $customOptions = array()) |
|
158 | |||
159 | |||
160 | |||
161 | /** |
||
162 | * Create an instance from an associative array |
||
163 | */ |
||
164 | 27 | public static function fromArray(array $data, array $customOptions = array()) |
|
168 | |||
169 | |||
170 | /** |
||
171 | * Create an instance from an generic standard object |
||
172 | */ |
||
173 | 3 | public static function fromStdObject( \stdClass $obj, array $customOptions = array()) |
|
177 | |||
178 | |||
179 | 4 | public static function getVocabularies() |
|
189 | |||
190 | |||
191 | 3 | public static function getTurtleHeader($base=null) |
|
201 | |||
202 | |||
203 | 1 | public function getDroppedFields() |
|
207 | |||
208 | |||
209 | /** |
||
210 | * dependecy injection setter |
||
211 | */ |
||
212 | 27 | public function setIdGenerator($generator) |
|
219 | |||
220 | |||
221 | /** |
||
222 | * a generic implementation that use uri, base and id property (all optionals) |
||
223 | */ |
||
224 | 8 | public function getUri() |
|
239 | |||
240 | |||
241 | 2 | public function getOptions() |
|
245 | |||
246 | |||
247 | 4 | public function getTripleCount() |
|
256 | |||
257 | |||
258 | 13 | public function asArray() |
|
262 | |||
263 | |||
264 | |||
265 | 1 | public function asStdObject() |
|
269 | |||
270 | |||
271 | /** |
||
272 | * metadata not yet implemented |
||
273 | */ |
||
274 | 1 | public function asLinkedData() |
|
278 | |||
279 | |||
280 | 1 | public function asString() |
|
284 | |||
285 | |||
286 | 1 | public function __toString() |
|
290 | |||
291 | |||
292 | /** |
||
293 | * this must be implemented |
||
294 | */ |
||
295 | abstract public function asTurtleFragment(); |
||
296 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.