Created
February 27, 2011 20:24
-
-
Save peaceman/846501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class Vpfw_DataMapper_Abstract { | |
protected $dataObjectHolders; | |
protected $database; | |
protected $tableInformation; | |
public function __construct(Vpfw_DataBase_Interface $database, Vpfw_Config_TableInformation $tableInformation) { | |
$this->database = $database; | |
$this->tableInformation = $tableInformation; | |
$this->initializeDataObjectHolders(); | |
} | |
protected function initializeDataObjectHolders() { | |
$this->dataObjectHolders = array(); | |
$this->dataObjectHolders['persistent'] = new Vpfw_DataObject_Holder(); | |
$this->dataObjectHolders['new'] = new Vpfw_DataObject_Holder(); | |
} | |
protected function getPersistentDataObjectHolder() { | |
return $this->dataObjectHolders['persistent']; | |
} | |
protected function getNewDataObjectHolder() { | |
return $this->dataObjectHolders['new']; | |
} | |
} | |
class Vpfw_Config_TableInformation { | |
protected $columns; | |
protected $tableName; | |
public function __construct(array $informations) { | |
if (!array_keys_exists(array('name', 'columns'), $informations)) { | |
Vpfw_Exception_Critical('Faulty DataMapper configuration'); | |
} | |
$this->tableName = $informations['name']; | |
if (!is_array($informations['columns'])) { | |
Vpfw_Exception_Critical('Faulty DataMapper configuration, columns has to be an array'); | |
} else { | |
foreach ($informations['columns'] as $column) { | |
$this->columns[] = new Vpfw_Config_TableColumnInformation($column); | |
} | |
} | |
} | |
public function getColumns() { | |
return $this->columns; | |
} | |
public function getName() { | |
return $this->tableName; | |
} | |
} | |
class Vpfw_Config_TableColumnInformation { | |
protected $name; | |
protected $type; | |
protected $length; | |
protected $required; | |
public function __construct(array $informations) { | |
if (!array_key_exists('name', $informations)) { | |
$this->missingInformation('name'); | |
} else { | |
$this->name = $informations['name']; | |
} | |
if (!array_key_exists('type', $informations)) { | |
$this->missingInformation('type'); | |
} else { | |
$this->type = $informations['type']; | |
} | |
if (array_key_exists('length', $informations)) { | |
$this->length = $informations['length']; | |
} | |
if (array_key_exists('required', $informations)) { | |
if (!is_bool($informations['required'])) { | |
throw new Vpfw_Exception_Logical('Expected a boolean value for the required field in table information'); | |
} | |
$this->required = $informations['required']; | |
} else { | |
$this->required = true; | |
} | |
} | |
public function getName() { | |
return $this->name; | |
} | |
public function getType() { | |
return $this->type; | |
} | |
public function getLength() { | |
return $this->length; | |
} | |
public function isRequired() { | |
return $this->required; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment