1 | <?php |
||
9 | class ZeroConfDriver implements DriverInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var Source\AbstractSchemaSource |
||
13 | */ |
||
14 | protected $metadata; |
||
15 | |||
16 | /** |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $params; |
||
21 | |||
22 | /** |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $default_options = [ |
||
27 | 'alias' => 'default', |
||
28 | 'path' => null, |
||
29 | 'version' => 'latest', |
||
30 | 'schema' => null, |
||
31 | 'permissions' => 0666 |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected static $metadataCache = []; |
||
39 | |||
40 | /** |
||
41 | * Underlying database adapter |
||
42 | * @var Adapter |
||
43 | */ |
||
44 | protected $adapter; |
||
45 | |||
46 | /** |
||
47 | * Construct a new Zero configuration driver |
||
48 | * |
||
49 | * $params allows you to specify the |
||
50 | * path : where to store the model definition (default to sys_get_temp_dir()) |
||
51 | * alias : the alias to use when using multiple schemas, default: 'default' |
||
52 | * version : the version to use, default to 'latest' |
||
53 | * schema : the database schema name, default to current adapter connection |
||
54 | * permissions: by default the model file is created with permission 0666 |
||
55 | * |
||
56 | * |
||
57 | * @param Adapter $adapter |
||
58 | * @param array|Traversable $params [alias,path,version] |
||
59 | * @throws Exception\ModelPathNotFoundException |
||
60 | * @throws Exception\InvalidArgumentException |
||
61 | */ |
||
62 | 151 | public function __construct(Adapter $adapter, $params = []) |
|
80 | |||
81 | /** |
||
82 | * Checks model configuration params |
||
83 | * @throws Exception\InvalidArgumentException |
||
84 | * |
||
85 | */ |
||
86 | 151 | protected function checkParams() |
|
105 | |||
106 | /** |
||
107 | * Return models configuration file |
||
108 | * @return string |
||
109 | */ |
||
110 | 17 | public function getModelsConfigFile() |
|
116 | |||
117 | /** |
||
118 | * Get models definition according to options |
||
119 | * |
||
120 | * @throws Exception\ModelFileNotFoundException |
||
121 | * @throws Exception\ModelFileCorruptedException |
||
122 | * @return array |
||
123 | */ |
||
124 | 17 | public function getModelsDefinition() |
|
152 | |||
153 | /** |
||
154 | * Save model definition |
||
155 | * |
||
156 | * @throws Exception\ModelFileNotWritableException |
||
157 | * @param array $models_definition |
||
158 | * @return DriverInterface |
||
159 | */ |
||
160 | 6 | protected function saveModelsDefinition(array $models_definition) |
|
180 | |||
181 | /** |
||
182 | * Set underlying database adapter |
||
183 | * |
||
184 | * @param Adapter $adapter |
||
185 | * @return DriverInterface |
||
186 | */ |
||
187 | 151 | protected function setDbAdapter(Adapter $adapter) |
|
192 | |||
193 | /** |
||
194 | * Get underlying database adapter |
||
195 | * |
||
196 | * @return Adapter |
||
197 | */ |
||
198 | 132 | public function getDbAdapter() |
|
202 | |||
203 | /** |
||
204 | * Get internal metadata reader |
||
205 | * |
||
206 | * @return Source\AbstractSchemaSource |
||
207 | */ |
||
208 | 146 | public function getMetadata() |
|
220 | |||
221 | /** |
||
222 | * |
||
223 | * @return ZeroConfDriver |
||
224 | */ |
||
225 | 20 | public function clearMetadataCache() |
|
230 | |||
231 | /** |
||
232 | * |
||
233 | * @return Metadata\NormalistModels |
||
234 | */ |
||
235 | 17 | protected function getDefaultMetadata() |
|
256 | |||
257 | /** |
||
258 | * Set internal metadata reader |
||
259 | * |
||
260 | * @param Source\AbstractSchemaSource $metadata |
||
261 | * @return ZeroConfDriver |
||
262 | */ |
||
263 | 1 | public function setMetadata(Source\AbstractSchemaSource $metadata) |
|
268 | } |
||
269 |