true, ])] public string $name; #[Field(name: "ORDINAL_POSITION", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public int $ordinalPosition; #[Field(name: "COLUMN_DEFAULT", type: "longtext")] public ? string $default; #[Field(name: "IS_NULLABLE", length: 3)] public string $nullable; #[Field(name: "DATA_TYPE", length: 64)] public string $dataType; #[Field(name: "CHARACTER_MAXIMUM_LENGTH", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $characterMaximumLength; #[Field(name: "CHARACTER_OCTET_LENGTH", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $characterOctetLength; #[Field(name: "NUMERIC_PRECISION", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $numericPrecision; #[Field(name: "NUMERIC_SCALE", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $numericScale; #[Field(name: "DATETIME_PRECISION", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $datetimePrecision; #[Field(name: "CHARACTER_SET_NAME", length: 32)] public ? string $characterSetName; #[Field(name: "COLLATION_NAME", length: 32)] public ? string $collationName; # #[Field(name: "COLLATION_TYPE", type: "longtext")] # public string $type; # #[Field(name: "IS_GENERATED", length: 6)] # public string $generated; public function matchFieldDefinition(ReflectedProperty $definition) : bool { $nullable = $this->nullable === 'YES'; $definitionValue = $this->getDefinitionValue($definition); if ($nullable !== $definition->allowsNull()) { return false; } if ( isset($definitionValue) && $this->canHaveDefaultValue() ) { if ( $definitionValue !== $this->defaultValue() ) { # dump($definition->value, $this->defaultValue(), $definition->name); return false; } } elseif (! isset($definitionValue)) { if ( ! $this->defaultValueIsNull() ) { return false; } } return true; } protected function getDefinitionValue(ReflectedProperty $definition) : mixed { # Attribute's value first, then defined in class value return $definition->getAttribute(Field::class)->object->default ?? $definition->value ?? null; } protected function defaultValueIsNull() : bool { return $this->defaultValue() === null; } protected function defaultValue() : mixed { if (is_numeric($this->default)) { return (int) $this->default; } return $this->default; } protected function canHaveDefaultValue() : bool { return true; } }