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