odea/library/Libs/Table.php
Damien LASSERRE d0cac19a26 Version 1.1 de ODEA
Stable
2012-02-02 17:29:14 +00:00

48 lines
1.2 KiB
PHP

<?php
abstract class Libs_Table extends Zend_Db_Table_Abstract
{
protected static $_loadedForms = array();
const DEFAULT_FORM = 'Default';
public function __construct($config = array())
{
$class = explode('_', get_class($this));
$rowClass = 'Object_' . substr(array_pop($class), 0, -1);
if (!class_exists($rowClass)) {
throw new Libs_Exception("Class $rowClass not found");
}
$config = array_merge($config, array(self::ROW_CLASS => $rowClass));
parent::__construct($config);
}
public function getForm($form = null)
{
$form = ucfirst(strtolower($form));
if ($form == null) {
$form = self::DEFAULT_FORM;
}
$className = "Form_" . ucfirst($this->_name) . '_' . $form;
if (array_key_exists($className, self::$_loadedForms)) {
return self::$_loadedForms[$className];
}
if (class_exists($className, true)) {
self::$_loadedForms[$className] = new $className;
return self::$_loadedForms[$className];
} else {
throw new Libs_Exception("Class $className not found");
}
}
public function __call($meth, $args)
{
if (preg_match('|get(\w+)Form|', $meth, $matches)) {
return $this->getForm($matches[1]);
}
}
}
?>