/** * This function must be copied in each peer class. */ public static function getInstance() { return coreDatabaseTable::_getInstance(__CLASS__); }
/** * Initialize this table peer instance. * * The only reason we instantiate the class is that static variables * can not be overriden in the extending class as of Php 5.2. * * @param coreDatabase $db coreDatabase instance. * @param string $tableName Table name obtained from the class name without 'Peer' suffix * @return */ public function __construct($peerclass) { // static reference for convenience self::$db = coreContext::getInstance()->getDatabase(); // check naming of model and determine the default table name if (!preg_match('/^(\\w+)Peer$/', $peerclass, $matches)) { throw new coreException('Invalid coreDatabaseTable class name: ' . $peerclass); } // if not explicitly set, the table name is derived from the class name, in lowercase if ($this->tableName === null) { $this->tableName = strtolower($matches[1]); } // columns check if (empty($this->columns)) { throw new coreException('coreDatabaseTable table ' . $this->getName() . ' columns not set.'); } $this->initialize(); }