|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* DataSetFactory class |
|
4
|
|
|
* |
|
5
|
|
|
* This file describes the static DataSetFactory class |
|
6
|
|
|
* |
|
7
|
|
|
* PHP version 5 and 7 |
|
8
|
|
|
* |
|
9
|
|
|
* @author Patrick Boyd / [email protected] |
|
10
|
|
|
* @copyright Copyright (c) 2015, Austin Artistic Reconstruction |
|
11
|
|
|
* @license http://www.apache.org/licenses/ Apache 2.0 License |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Allow other classes to be loaded as needed |
|
16
|
|
|
*/ |
|
17
|
|
|
require_once('Autoload.php'); |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* A static class allowing the caller to easily obtain \Data\DataSet object instances |
|
21
|
|
|
* |
|
22
|
|
|
* This class will utilize the Settings class to determine who to construct the \Data\DataSet object requested by the caller |
|
23
|
|
|
*/ |
|
24
|
|
|
class DataSetFactory |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Obtain the \Data\DataSet given the name of the dataset used in the settings |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $setName The name of the DataSet used in the Settings |
|
30
|
|
|
* |
|
31
|
|
|
* @return \Data\DataSet The DataSet specified |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function getDataSetByName($setName) |
|
34
|
|
|
{ |
|
35
|
|
|
static $instances = array(); |
|
36
|
|
|
if(isset($instances[$setName])) |
|
37
|
|
|
{ |
|
38
|
|
|
return $instances[$setName]; |
|
39
|
|
|
} |
|
40
|
|
|
$settings = \Settings::getInstance(); |
|
41
|
|
|
$setData = $settings->getDataSetData($setName); |
|
42
|
|
|
if($setData === false) |
|
43
|
|
|
{ |
|
44
|
|
|
throw new Exception('Unknown dataset name '.$setName); |
|
45
|
|
|
} |
|
46
|
|
|
$class_name = '\\Data\\'.$setData['type']; |
|
47
|
|
|
$obj = new $class_name($setData['params']); |
|
48
|
|
|
$instances[$setName] = $obj; |
|
49
|
|
|
return $obj; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Obtain the \Data\DataTable given the name of the dataset used in the settings and the name of the table |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $dataSetName The name of the DataSet used in the Settings |
|
56
|
|
|
* @param string $dataTableName The name of the DataTable |
|
57
|
|
|
* |
|
58
|
|
|
* @return \Data\DataTable The DataTable specified |
|
59
|
|
|
*/ |
|
60
|
|
|
public static function getDataTableByNames($dataSetName, $dataTableName) |
|
61
|
|
|
{ |
|
62
|
|
|
$dataSet = self::getDataSetByName($dataSetName); |
|
63
|
|
|
return $dataSet[$dataTableName]; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
|
67
|
|
|
|