1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110:
<?php
class MappingModel
{
private $classname;
private $table_name;
private $primary_key;
private $fields;
private $joins;
private $properties_list = array();
public function __construct($classname, $table_name, MappingModelField $primary_key, $fields,
$joins = array())
{
$this->classname = $classname;
$this->table_name = $table_name;
$this->primary_key = $primary_key;
$this->fields = $fields;
$this->joins = $joins;
if (empty($this->fields))
{
throw new MappingModelException($this->classname, 'fields list can not be empty');
}
$this->build_properties_list();
}
public function new_instance($properties_map = array())
{
$instance = new $this->classname();
$instance->populate($properties_map);
return $instance;
}
public function get_raw_value($instance)
{
return $instance->get_raw_value($this->properties_list);
}
public function get_class_name()
{
return $this->classname;
}
public function get_table_name()
{
return $this->table_name;
}
public function get_primary_key()
{
return $this->primary_key;
}
public function get_fields()
{
return $this->fields;
}
public function get_joins()
{
return $this->joins;
}
private function build_properties_list()
{
$this->properties_list[] = $this->primary_key->get_property_name();
foreach ($this->fields as $field)
{
$this->properties_list[] = $field->get_property_name();
}
}
}
?>