示例#1
0
 /**
  * @param AbstractTable $table
  * @return TableBuilder
  */
 public function setTable(AbstractTable $table) : self
 {
     $this->dbDriver = $table->getDb()->driver();
     $this->columns = $table->getColumns();
     $this->constraints = $table->getConstraints();
     $this->tableName = $table->getName();
     $this->tableEngine = $table->getEngine();
     // Return self
     return $this;
 }
示例#2
0
 /**
  * @param bool $camelCase
  * @return array
  * @throws FluentException
  * @throws SchemaException
  */
 private function getProps(bool $camelCase) : array
 {
     $props = [];
     $columnKeys = $this->schemaTable->getColumnsKeys();
     foreach ($columnKeys as $column) {
         $columnKey = $column;
         $camelKey = Comely::camelCase($columnKey);
         $propKey = $camelCase ? $camelKey : $columnKey;
         $column = $this->schemaTable->getColumn($column);
         // Look for prop's value
         if (array_key_exists($camelKey, $this->private)) {
             $value = $this->private[$camelKey];
             // Private
         } elseif (property_exists($this, $camelKey)) {
             $value = $this->{$camelKey};
             // Public
         }
         // Do we have value?
         if (isset($value)) {
             // Cross check value type with column's
             if ($column->scalarType !== gettype($value)) {
                 // Check if value type is NULL and column is nullable
                 if (gettype($value) === "NULL" && array_key_exists("nullable", $column->attributes)) {
                     // Column is nullable
                 } else {
                     // Data type of value doesn't match with column's
                     throw FluentException::badColumnValue($this->modelName, $columnKey, $column->scalarType, gettype($value));
                 }
             }
             // Save prop
             $props[$propKey] = $value;
             unset($value);
         }
     }
     // Private values have preference over public values
     return $props;
 }