Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fiktivkod/library/Fiktiv/Data/Service.php
2010-09-10 23:30:22 +02:00

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];
}
}