1 | <?php |
||
7 | abstract class AbstractModel |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * |
||
12 | * MUST be redefined by concrete class with the model schema |
||
13 | * Each array element is composed by a propery name and and property options. |
||
14 | * Property option is an array with following (optional) fields: |
||
15 | * 'default' a value to be used for the propery |
||
16 | * 'filter' a php filter |
||
17 | * 'options' php filter options |
||
18 | * 'flags' php filter flags |
||
19 | * |
||
20 | * Example:array ( |
||
21 | * 'legalName' => array( |
||
22 | * 'filter' => FILTER_CALLBACK, |
||
23 | * 'options' => '\BOTK\Filters::FILTER_NORMALIZZE_ADDRESS', |
||
24 | * ), |
||
25 | * 'alternateName' => array( |
||
26 | 'flags' => FILTER_FORCE_ARRAY, |
||
27 | * ), |
||
28 | * 'postalCode' => array( // italian rules |
||
29 | * 'filter' => FILTER_VALIDATE_REGEXP, |
||
30 | * 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
||
31 | * 'flags' => FILTER_REQUIRE_SCALAR, |
||
32 | * ), |
||
33 | * ) |
||
34 | */ |
||
35 | protected static $DEFAULT_OPTIONS = array( |
||
36 | 'base' => array( |
||
37 | 'default' => 'http://linkeddata.center/botk/resource/', |
||
38 | 'filter' => FILTER_SANITIZE_URL, |
||
39 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
40 | ), |
||
41 | 'uri' => array( |
||
42 | 'filter' => FILTER_SANITIZE_URL, |
||
43 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
44 | ), |
||
45 | 'lang' => array( |
||
46 | 'default' => 'it', |
||
47 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
48 | 'options' => array('regexp'=>'/^[a-z]{2}$/'), |
||
49 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
50 | ), |
||
51 | 'id' => array( |
||
52 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
53 | 'options' => array('regexp'=>'/^\w+$/'), |
||
54 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
55 | ), |
||
56 | ); |
||
57 | |||
58 | protected $options ; |
||
59 | protected $vocabulary = array( |
||
60 | 'botk' => 'http://http://linkeddata.center/botk/v1#', |
||
61 | 'schema' => 'http://schema.org/', |
||
62 | 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
||
63 | 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
||
64 | 'dct' => 'http://purl.org/dc/terms/', |
||
65 | 'foaf' => 'http://xmlns.com/foaf/0.1/', |
||
66 | ); |
||
67 | protected $data; |
||
68 | protected $rdf =null; //lazy created |
||
69 | protected $tripleCount=0; //lazy created |
||
70 | protected $uniqueIdGenerator=null; // dependency injections |
||
71 | |||
72 | abstract public function asTurtle(); |
||
73 | |||
74 | protected function mergeOptions( array $options1, array $options2 ) |
||
86 | |||
87 | public function __construct(array $data = array(), array $customOptions = array()) |
||
111 | |||
112 | |||
113 | /** |
||
114 | * dependecy injection setter |
||
115 | */ |
||
116 | public function setIdGenerator($generator) |
||
123 | |||
124 | |||
125 | /** |
||
126 | * a generic implementation that use uri, base and id property (all optionals) |
||
127 | */ |
||
128 | public function getUri() |
||
143 | |||
144 | |||
145 | public function asArray() |
||
149 | |||
150 | |||
151 | public function getOptions() |
||
155 | |||
156 | |||
157 | public function getVocabulary() |
||
161 | |||
162 | |||
163 | public function setVocabulary($prefix,$ns) |
||
167 | |||
168 | |||
169 | public function unsetVocabulary($prefix) |
||
173 | |||
174 | |||
175 | public function getTurtleHeader($base=null) |
||
184 | |||
185 | |||
186 | public function getTripleCount() |
||
195 | |||
196 | |||
197 | public function __toString() |
||
201 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.