/** * FactoryFromMormons * * almost the same as Factory but does strange things useful for Mormons * * @param string $super_class top class of the STI * @param Mormons $mormons mormons object to associate with the model * @params array $to_load array used to load the mmorm object * @access public * @return Morm */ public static function FactoryFromMormons($super_class, &$mormons, $to_load) { $model = new $super_class(); if ($sti_field = $model->getStiField()) { $sti_field_mormonized = 'morm' . MormConf::MORM_SEPARATOR . $model->_table . MormConf::MORM_SEPARATOR . $sti_field; if (isset($to_load[$sti_field_mormonized]) && !empty($to_load[$sti_field_mormonized])) { $sti_class = MormConf::generateMormClass($to_load[$sti_field_mormonized]); if (!$sti_class) { throw new MormSqlException('The class ' . $to_load[$sti_field_mormonized] . ' doesn\'t exists.'); } $sti_model = new $sti_class(); if ($sti_model->is_a($super_class)) { $model = $sti_model; } else { throw new Exception('The class ' . $sti_class . ' is not a ' . $super_class . ' and could not be used as a sti model'); } } else { throw new Exception('Could not guess the class to instantiate from this array, the sti field wasn\'t there'); } } $model->associateWithMormons($mormons); $model->loadFromMormons($to_load); return $model; }
/** * add_table * * * * @param string $table * @return string */ public function add_table($table) { if ($this->is_used_table($table)) { throw new Exception("The table " . $table . " already exists in this object"); } $class_name = MormConf::generateMormClass($table); $base_object = new $class_name(); $table = $base_object->_table; $this->tables[] = $table; $this->where[$table] = array(); $this->base_models[$table] = $base_object; return $table; }