Esempio 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);
     }
 }
Esempio 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;
     }
 }
Esempio 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);
     }
 }