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_SANITIZE_URL, |
||
35 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
36 | ), |
||
37 | 'base' => array( |
||
38 | 'default' => 'http://linkeddata.center/botk/resource/', |
||
39 | 'filter' => FILTER_SANITIZE_URL, |
||
40 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
41 | ), |
||
42 | 'id' => array( |
||
43 | 'filter' => FILTER_CALLBACK, |
||
44 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_ID', |
||
45 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
46 | ), |
||
47 | 'page' => array( |
||
48 | 'filter' => FILTER_SANITIZE_URL, |
||
49 | 'flags' => FILTER_FORCE_ARRAY, |
||
50 | ), |
||
51 | 'homepage' => array( |
||
52 | 'filter' => FILTER_SANITIZE_URL, |
||
53 | 'flags' => FILTER_FORCE_ARRAY, |
||
54 | ), |
||
55 | ); |
||
56 | |||
57 | /** |
||
58 | * known vocabularies |
||
59 | */ |
||
60 | protected static $VOCABULARY = array( |
||
61 | 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
||
62 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
||
63 | 'owl' => 'http://www.w3.org/2002/07/owl#', |
||
64 | 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
||
65 | 'dct' => 'http://purl.org/dc/terms/', |
||
66 | 'void' => 'http://rdfs.org/ns/void#', |
||
67 | 'prov' => 'http://www.w3.org/ns/prov#', |
||
68 | 'sd' => 'http://www.w3.org/ns/sparql-service-description#', |
||
69 | 'schema' => 'http://schema.org/', |
||
70 | 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
||
71 | 'foaf' => 'http://xmlns.com/foaf/0.1/', |
||
72 | 'dq' => 'http://purl.org/linked-data/cube#', |
||
73 | 'daq' => 'http://purl.org/eis/vocab/daq#', |
||
74 | 'kees' => 'http://linkeddata.center/kees/v1#', |
||
75 | ); |
||
76 | |||
77 | |||
78 | protected $options ; |
||
79 | |||
80 | protected $data; |
||
81 | protected $rdf =null; //lazy created |
||
82 | protected $tripleCount=0; //lazy created |
||
83 | protected $uniqueIdGenerator=null; // dependency injections |
||
84 | protected $droppedFields = array(); |
||
85 | |||
86 | |||
87 | 27 | protected static function mergeOptions( array $options1, array $options2 ) |
|
98 | |||
99 | |||
100 | 27 | protected static function constructOptions() |
|
110 | |||
111 | |||
112 | /** |
||
113 | * Do not call directlty constructor, use fromArray or other factory methodsinstead |
||
114 | */ |
||
115 | 27 | protected function __construct(array $data = array(), array $customOptions = array()) |
|
140 | |||
141 | |||
142 | |||
143 | /** |
||
144 | * Create an instance from an associative array |
||
145 | */ |
||
146 | 27 | public static function fromArray(array $data, array $customOptions = array()) |
|
150 | |||
151 | |||
152 | /** |
||
153 | * Create an instance from an generic standard object |
||
154 | */ |
||
155 | 3 | public static function fromStdObject( \stdClass $obj, array $customOptions = array()) |
|
159 | |||
160 | |||
161 | 4 | public static function getVocabularies() |
|
171 | |||
172 | |||
173 | 3 | public static function getTurtleHeader($base=null) |
|
183 | |||
184 | |||
185 | 1 | public function getDroppedFields() |
|
189 | |||
190 | |||
191 | /** |
||
192 | * dependecy injection setter |
||
193 | */ |
||
194 | 27 | public function setIdGenerator($generator) |
|
201 | |||
202 | |||
203 | /** |
||
204 | * a generic implementation that use uri, base and id property (all optionals) |
||
205 | */ |
||
206 | 8 | public function getUri() |
|
221 | |||
222 | |||
223 | 2 | public function getOptions() |
|
227 | |||
228 | |||
229 | 4 | public function getTripleCount() |
|
238 | |||
239 | |||
240 | 13 | public function asArray() |
|
244 | |||
245 | |||
246 | |||
247 | 1 | public function asStdObject() |
|
251 | |||
252 | |||
253 | /** |
||
254 | * metadata not yet implemented |
||
255 | */ |
||
256 | 1 | public function asLinkedData() |
|
260 | |||
261 | |||
262 | 1 | public function asString() |
|
266 | |||
267 | |||
268 | 1 | public function __toString() |
|
272 | |||
273 | |||
274 | /** |
||
275 | * this must be implemented |
||
276 | */ |
||
277 | abstract public function asTurtleFragment(); |
||
278 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.