65 lines
No EOL
1.4 KiB
PHP
65 lines
No EOL
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Data service to allow easy access to data storage
|
|
*
|
|
*/
|
|
class Fiktiv_Data_Service
|
|
{
|
|
/**
|
|
* Hold the singleton instance
|
|
*
|
|
* @var Fiktiv_Data_Service
|
|
*/
|
|
protected static $_instance = null;
|
|
|
|
/**
|
|
* Set of datapoints that the service can access
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $_dataStorage = array();
|
|
|
|
/**
|
|
* Returns the current singleton instance
|
|
*
|
|
* @return Fiktiv_Data_Service $_instance
|
|
*/
|
|
public static function getInstance()
|
|
{
|
|
if (self::$_instance === null) {
|
|
self::$_instance = new Fiktiv_Data_Service();
|
|
}
|
|
|
|
return self::$_instance;
|
|
}
|
|
|
|
/**
|
|
* Provides access to the underlaying datapoint objects.
|
|
* TODO: Better / faster loading of datapoints?
|
|
*
|
|
* @param $name
|
|
* @return Fiktiv_Data_Point
|
|
*/
|
|
public function __get($name) {
|
|
|
|
/*
|
|
* Two ways to go, if we already have the datapoint object we
|
|
* will choose a faster route
|
|
*/
|
|
if (array_key_exists($name, $this->_dataStorage)) {
|
|
|
|
// If we for some very odd reason have lost the object, re-create it!
|
|
if (!is_object($this->_dataStorage[$name])) {
|
|
$this->_dataStorage[$name] = new $name();
|
|
}
|
|
|
|
|
|
} else if (class_exists($name)) {
|
|
|
|
$this->_dataStorage[$name] = new $name();
|
|
}
|
|
|
|
return $this->_dataStorage[$name];
|
|
}
|
|
|
|
} |