85 lines
2.5 KiB
PHP
85 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Ulmus\Entity\Mssql;
|
|
|
|
use Ulmus\Attribute\Obj\Table as TableObj;
|
|
use Ulmus\Attribute\Property\Field;
|
|
use Ulmus\ConnectionAdapter;
|
|
use Ulmus\Entity\Mysql\id;
|
|
use Ulmus\Repository;
|
|
use Ulmus\Ulmus;
|
|
|
|
#[TableObj(name: "columns", schema: "information_schema")]
|
|
class Column extends \Ulmus\Entity\InformationSchema\Column
|
|
{
|
|
/*
|
|
public static function repository(string $alias = Repository::DEFAULT_ALIAS, ConnectionAdapter $adapter = null): Repository
|
|
{
|
|
$adapter = Ulmus::$registeredAdapters[$this->loadedFromAdapter];
|
|
|
|
return Ulmus::repository(static::class, $alias, $adapter);
|
|
}*/
|
|
|
|
# TODO ! Handle FUNCTIONAL default value
|
|
protected function canHaveDefaultValue(): bool
|
|
{
|
|
return ! in_array(strtoupper($this->dataType), [
|
|
# 'BLOB', 'TINYBLOB', 'MEDIUMBLOB', 'LONGBLOB', 'JSON', 'TEXT', 'TINYTEXT', 'MEDIUMTEXT', 'LONGTEXT', 'GEOMETRY'
|
|
]);
|
|
}
|
|
|
|
protected function defaultValue() : mixed
|
|
{
|
|
if ($this->default === null) {
|
|
return null;
|
|
}
|
|
|
|
# Removing first pairs of brackets
|
|
$default = $this->isBetween($this->default, '(', ')') ? substr($this->default, 1, -1) : $this->default;
|
|
|
|
if ($default === "NULL") {
|
|
return null;
|
|
}
|
|
|
|
# Checking if another pairs of brackets surrounds the value
|
|
if ($this->isBetween($default, '(', ')')) {
|
|
$default = substr($default, 1, -1);
|
|
|
|
if (is_numeric($default)) {
|
|
return (int) $default;
|
|
}
|
|
}
|
|
elseif ($this->isBetween($default, "'", "'")) {
|
|
$default = new class($default) implements \Stringable {
|
|
public function __construct(
|
|
private readonly string $default
|
|
) {}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return substr($this->default, 1, -1);;
|
|
}
|
|
};
|
|
}
|
|
else {
|
|
$default = new class($default) implements \Stringable {
|
|
public function __construct(
|
|
private readonly string $default
|
|
) {}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return $this->default;
|
|
}
|
|
};
|
|
}
|
|
|
|
return (string) $default;
|
|
}
|
|
|
|
private function isBetween(string $str, string $first, string $last) : bool
|
|
{
|
|
return str_starts_with($str, $first) && str_ends_with($str, $last);
|
|
}
|
|
|
|
} |