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-11 21:49:06 +02:00

68 lines
No EOL
1.5 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 data mappers
*
* @param $name
* @return Fiktiv_Data_Point
*/
public function __get($name) {
// Class prefix
$table = 'Table_'.$name;
$name = 'Mapper_'.$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($table);
}
} else if (class_exists($name)) {
$this->_dataStorage[$name] = new $name($table);
}
return $this->_dataStorage[$name];
}
}