63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Ulmus\Adapter;
|
|
|
|
use Ulmus\{Common\Sql,
|
|
ConnectionAdapter,
|
|
Entity\InformationSchema\Table,
|
|
Migration\FieldDefinition,
|
|
Repository,
|
|
QueryBuilder\SqlQueryBuilder,
|
|
Ulmus};
|
|
|
|
trait SqlAdapterTrait
|
|
{
|
|
public function repositoryClass() : string
|
|
{
|
|
return Repository::class;
|
|
}
|
|
|
|
public function queryBuilderClass() : string
|
|
{
|
|
return SqlQueryBuilder::class;
|
|
}
|
|
|
|
public function tableSyntax() : array
|
|
{
|
|
return [
|
|
'ai' => "AUTO_INCREMENT",
|
|
'pk' => "PRIMARY KEY",
|
|
'unsigned' => "UNSIGNED",
|
|
];
|
|
}
|
|
|
|
public function databaseName() : string
|
|
{
|
|
return $this->database;
|
|
}
|
|
|
|
public function whitelistAttributes(array &$parameters) : void
|
|
{
|
|
$parameters = array_intersect_key($parameters, array_flip(static::ALLOWED_ATTRIBUTES));
|
|
}
|
|
|
|
public function writableValue(mixed $value) : mixed
|
|
{
|
|
switch (true) {
|
|
case $value instanceof \UnitEnum:
|
|
return Ulmus::convertEnum($value);
|
|
|
|
case is_object($value):
|
|
return Ulmus::convertObject($value);
|
|
|
|
case is_array($value):
|
|
return json_encode($value);
|
|
|
|
case is_bool($value):
|
|
return (int) $value;
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
}
|