ulmus/src/Entity/Sqlite/Column.php
2024-06-28 11:46:09 +00:00

61 lines
1.3 KiB
PHP

<?php
namespace Ulmus\Entity\Sqlite;
use Notes\Common\ReflectedProperty;
use Ulmus\EntityCollection;
use Ulmus\{Attribute\Obj\Table};
use Ulmus\Attribute\Property\{Field, Filter, FilterJoin, Relation, Join, Virtual, Where};
#[Table]
class Column
{
use \Ulmus\EntityTrait;
#[Field\Id]
public int $cid;
#[Field]
public string $type;
#[Field]
public string $name;
#[Virtual]
public string $tableName;
#[Field(name: "notnull")]
public bool $notNull;
#[Field(name: "dflt_value")]
public ? string $defaultValue;
#[Field(name: "pk")]
public bool $primaryKey;
public function matchFieldDefinition(ReflectedProperty $definition) : bool
{
if ($this->notNull === $definition->allowsNull()) {
return false;
}
if (isset($definition->value)) {
if ( $definition->value !== $this->defaultValue) {
return false;
}
}
elseif (! isset($definition->value)) {
if ( ! $this->defaultValueIsNull() ) {
return false;
}
}
return true;
}
protected function defaultValueIsNull() : bool
{
return $this->defaultValue === null || $this->defaultValue === "NULL";
}
}