/** * @param array|DictionaryInterface $details list of column attrs * @return Column */ public function __construct($details) { /* * inherit from schema object which will setup the dictionary for * attribute list */ parent::__construct($details); $attrList = $this->getAttributeList(); $err = "Failed to instatiate:"; $name = $attrList->get('column-name'); if (empty($name) || !is_string($name)) { throw new Exception("{$err} column name must be a non empty string"); } $this->name = $name; $type = $attrList->get('data-type'); if (!$type instanceof DataTypeInterface) { $err .= " Data Type not found for key 'data-type' or does not"; $err .= " implment Appfuel\\Framework\\Db\\Schema\\DataTypeInterface"; throw new Exception($err); } $this->dataType = $type; if ($attrList->existsAs('is-nullable', 'bool-true')) { $this->isNullable = true; } if ($attrList->existsAs('is-default', 'bool-true')) { $this->isDefault = true; $this->defaultValue = $attrList->get('default-value', null); } }
/** * @param mixed array|DictionaryInterface $details * @return DataType */ public function __construct($details) { parent::__construct($details); $attrList = $this->getAttributeList(); $name = $attrList->get('type-name', null); if (empty($name) || !is_string($name)) { throw new Exception("type-name must be a non empty string"); } $this->name = $name; $modifier = $attrList->get('type-modifier', null); if (!empty($modifier)) { $this->typeModifier = $modifier; } }
/** * @param array|DictionaryInterface $data table definition * @param SchemaFactoryInterface $factory u * @return Column */ public function __construct($data, SchemaFactoryInterface $factory = null) { if (null === $factory) { $factory = new SchemaFactory(); } /* * inherit from schema object which will setup the dictionary for * attribute list */ parent::__construct($details); $attrList = $this->getAttributeList(); $err = "Failed to instatiate:"; $name = $attrList->get('table-name'); if (empty($name) || !is_string($name)) { throw new Exception("{$err} column name must be a non empty string"); } $this->name = $name; $listedCols = $attrList->get('columns'); if (empty($columns)) { throw new Exception("Table must define columns"); } if (!is_array($columns)) { throw new Exception("List of columns must be stored in an array"); } $columns = array(); foreach ($listedCols as $col) { $column = $this->createColumn($col); $columns[$column->getName()] = $column; } $this->columna = $type; if ($attrList->existsAs('is-nullable', 'bool-true')) { $this->isNullable = true; } if ($attrList->existsAs('is-default', 'bool-true')) { $this->isDefault = true; $this->defaultValue = $attrList->get('default-value', null); } }
/** * @return null */ public function testConstructorDictionaryInterface() { $attr = new Dictionary(array('type-name' => 'enum', 'type-modifier' => array('a', 'b', 'c'), 'attrA' => 'valueA', 'attrB' => 12345, 'attrC' => array(1, 2, 3))); $object = new SchemaObject($attr); $this->assertTrue($object->isAttribute('attrA')); $this->assertTrue($object->isAttribute('attrB')); $this->assertTrue($object->isAttribute('attrC')); $this->assertEquals('valueA', $object->getAttribute('attrA')); $this->assertEquals(12345, $object->getAttribute('attrB')); $this->assertEquals(array(1, 2, 3), $object->getAttribute('attrC')); }