示例#1
0
 /**
  * {@inheritdoc}
  */
 public function updateState($state)
 {
     // remove default if preserveDefault==false, we dont want it in future updates.
     if (false === $this->preserveDefault) {
         $field = $this->field->deepClone();
         $field->default = NOT_PROVIDED;
     } else {
         $field = $this->field;
     }
     $state->modelStates[$this->modelName]->fields[$this->name] = $field;
 }
示例#2
0
 public function contributeToClass($field, $model)
 {
     parent::contributeToClass($field, $model);
     assert(!$model->meta->hasAutoField, sprintf("The Model '%s' more than one AutoField, which is not allowed.", $this->scopeModel->meta->modelName));
     $this->scopeModel->meta->hasAutoField = true;
     $this->scopeModel->meta->autoField = $this;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function updateState($state)
 {
     if (false === $this->preserveDefault) {
         $alteredField = $this->field->deepClone();
         $alteredField->default = NOT_PROVIDED;
     } else {
         $alteredField = $this->field;
     }
     $fields = $state->modelStates[$this->modelName]->fields;
     $newFields = [];
     foreach ($fields as $name => $oldField) {
         if ($name == $this->name) {
             $newFields[$name] = $alteredField;
         } else {
             $newFields[$name] = $oldField;
         }
     }
     $state->modelStates[$this->modelName]->fields = $newFields;
 }
示例#4
0
 /**
  * @param Asker $asker
  * @param $modelName
  * @param $oldName
  * @param $newName
  * @param Field $fieldObj
  *
  * @return ConfirmationQuestion
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public static function hasFieldRenamed($asker, $modelName, $oldName, $newName, $fieldObj)
 {
     $msg = 'Did you rename %1$s.%2$s to %1$s.%3$s (a %4$s)? [y/N]';
     $q = new ConfirmationQuestion(sprintf($msg, $modelName, $oldName, $newName, $fieldObj->getShortClassName()));
     return $asker->ask($q);
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function getConstructorArgs()
 {
     $kwargs = parent::getConstructorArgs();
     if (ArrayHelper::hasKey($kwargs, 'onDelete')) {
         $kwargs['onDelete'] = $this->relation->onDelete;
     }
     if (is_string($this->relation->toModel)) {
         $kwargs['to'] = $this->relation->toModel;
     } else {
         $name = $this->relation->toModel->getFullClassName();
         $kwargs['to'] = ClassHelper::getNameFromNs($name, BaseOrm::getModelsNamespace());
     }
     if ($this->relation->parentLink) {
         $kwargs['parentLink'] = $this->relation->parentLink;
     }
     return $kwargs;
 }
示例#6
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;
 }
示例#7
0
 public function __construct($config = [])
 {
     $config['maxLength'] = 32;
     parent::__construct($config);
 }