Example #1
0
 /**
  * @param Field      $field
  * @param bool|false $includeDefault
  *
  * @return array
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public function getDoctrineColumnOptions($field, $includeDefault = false)
 {
     $options = [];
     // set constraint
     if ($field->hasProperty('maxLength') && $field->maxLength) {
         $options['length'] = $field->maxLength;
     }
     if ($field->hasProperty('maxDigits') && $field->maxDigits) {
         $options['precision'] = $field->maxDigits;
     }
     if ($field->hasProperty('decimalPlaces') && $field->decimalPlaces) {
         $options['scale'] = $field->decimalPlaces;
     }
     // for columns that can be signed
     if ($field->hasProperty('signed') && $field->signed !== null) {
         $options['unsigned'] = $field->signed === false;
     }
     if ($field->hasDefault() && ($includeDefault && !$this->skipDefault($field))) {
         // the default value
         $default_value = $this->effectiveDefault($field);
         // if value is provided, create the defualt
         if ($default_value == NOT_PROVIDED) {
             $options['default'] = $this->prepareDefault($field);
         }
     }
     // the null option
     if ($field->null) {
         $options['notnull'] = $field->null;
     }
     // the comment option
     if ($field->comment) {
         $options['comment'] = $field->comment;
     }
     // auto increament option
     if ($field instanceof AutoField) {
         $options['autoincrement'] = true;
     }
     return $options;
 }