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/Db/Service.php
2010-08-29 12:42:25 +02:00

72 lines
No EOL
1.5 KiB
PHP

<?php
/**
* Database service to allow easy access to the tables in the database
* This is a wrapper for all the table classes used.
*
*/
class Fiktiv_Db_Service
{
/**
* Hold the singleton instance
*
* @var Fiktiv_Db_Service
*/
protected static $_instance = null;
/**
* Set of tables that the service can access
*
* @var array
*/
protected $_tables = array();
/**
* Returns the current singleton instance
*
* @return Fiktiv_Db_Service $_instance
*/
public static function getInstance()
{
if (self::$_instance === null) {
self::$_instance = new Fiktiv_Db_Service();
}
return self::$_instance;
}
/**
* Set tables the service can access.
* This only defines the table, it does not
* connect to the table. Connections are made
* "at runtime" to the needed tables.
*
* @param array $options
*/
public function setTables(array $options) {
foreach ($options as $tbl) {
$this->_tables[$tbl] = null;
}
}
/**
* Provides access to the underlaying table objects.
*
* @param $name
* @return Zend_Db_Table_Abstract
*/
public function __get($name) {
if (array_key_exists($name, $this->_tables)) {
if (!($this->_tables[$name] instanceof Zend_Db_Table_Abstract)) {
$class = ucfirst($name);
$this->_tables[$name] = new $class();
}
}
return $this->_tables[$name];
}
}