public static function get() { if (is_null(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * load the fieldinfo for the given class and fieldName * * @param $fieldName * @throws base_exception_Fieldinfo * @throws base_database_Exception * @return $this */ public function load($fieldName) { $cache = base_cache_Fieldinfo::get(); $result = $cache->getFieldinfo($this->class, $fieldName); if (!is_null($result)) { return $result; } $table = DB::table($this->table); $colFieldName = $table->getColumn('fieldName'); $colClass = $table->getColumn('class'); $where = DB::where($colFieldName, DB::stringTerm($fieldName)); $where->addAnd($colClass, DB::stringTerm($this->class)); $sqlStatement = new base_database_statement_Select(); $sqlStatement->setTable($table); $sqlStatement->setWhere($where); $result = $sqlStatement->fetchDatabase(); if (empty($result)) { throw new base_exception_Fieldinfo(TMS(base_exception_Fieldinfo::FIELD_NOT_EXISTS, array('field' => $fieldName, 'class' => $this->class))); } foreach ($result[0] as $field => $value) { $this->$field = $value; } $cache->setFieldinfo($this); return $this; }