/** * {@inheritdoc} */ public function getDefaultValue() { $defaultValue = parent::getDefaultValue(); if (in_array($this->type, $this->forbiddenDefaults)) { return null; } return $defaultValue; }
/** * Export default value from column schema into scalar form (which we can store in cache). * * @param AbstractColumn $column * @return mixed|null */ private function exportDefault(AbstractColumn $column) { if (in_array($column->getName(), $this->tableSchema->getPrimaryKeys())) { //Column declared as primary key, nothing to do with default values return null; } $defaultValue = $column->getDefaultValue(); if ($defaultValue instanceof FragmentInterface) { //We can't cache values like that return null; } if (is_null($defaultValue) && !$column->isNullable()) { return $this->castDefault($column); } return $defaultValue; }
/** * Must compare two instances of AbstractColumn. * * @param self $initial * @return bool */ public function compare(self $initial) { $normalized = clone $initial; $normalized->declared = $this->declared; if ($this == $normalized) { return true; } $columnVars = get_object_vars($this); $dbColumnVars = get_object_vars($normalized); $difference = []; foreach ($columnVars as $name => $value) { if ($name == 'defaultValue') { //Default values has to compared using type-casted value if ($this->getDefaultValue() != $initial->getDefaultValue()) { $difference[] = $name; } continue; } if ($value != $dbColumnVars[$name]) { $difference[] = $name; } } return empty($difference); }