Ejemplo n.º 1
0
 /**
  * @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);
     }
 }
Ejemplo n.º 2
0
 /**
  * @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;
     }
 }
Ejemplo n.º 3
0
 /**
  * @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);
     }
 }
Ejemplo n.º 4
0
 /**
  * @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'));
 }