- Some small bugfixes made

This commit is contained in:
mcndave committed 2023-07-09 12:38:52 -04:00
1 parent a4743b471c
commit 01ab6e82d4
6 files changed
+55 -8

No files matched your search

+8 -1
View File
@@ -3,13 +3,20 @@
namespace Ulmus\Attribute;
use Ulmus\Common\EntityField;
use Ulmus\Repository;
class Attribute
{
public static function handleArrayField(null|\Stringable|string|array $field) : mixed
public static function handleArrayField(null|\Stringable|string|array $field, null|string|bool $alias = Repository::DEFAULT_ALIAS, string $separator = ', ') : mixed
{
if ( is_array($field) ) {
$class = array_shift($field);
$field[1] ??= $alias;
if (is_array($field[0])) {
$field[] = $separator;
return $class::fields(...$field);
}
return $class::field(...$field);
}
+15 -1
View File
@@ -10,6 +10,17 @@ use Ulmus\Attribute\Attribute;
*/
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class ForeignKey extends PrimaryKey {
public const SET_NULL = "null";
public const SET_DEFAULT = "default";
public const RESTRICT = "restrict";
public const NO_ACTION = "noaction";
public const CASCADE = "cascade";
public function __construct(
public ? string $name = null,
public ? string $type = 'bigint',
@@ -22,8 +33,11 @@ class ForeignKey extends PrimaryKey {
public bool $nullable = false,
public mixed $default = null,
public bool $readonly = false,
public null|array|string|\Stringable $foreignKey = "",
public null|array|string|\Stringable $references = null,
public null|string $onDelete = self::NO_ACTION,
public null|string $onUpdate = self::NO_ACTION,
) {
$this->references = Attribute::handleArrayField($this->references);
$this->references = Attribute::handleArrayField($this->references, false);
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace Ulmus\Attribute\Property;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Index {
public const TYPE_PRIMARY = 'primary';
public const TYPE_INDEX = 'index';
public const TYPE_UNIQUE = 'unique';
public const TYPE_SPATIAL = 'spatial';
public const TYPE_FULLTEXT = 'fulltext';
public function __construct(
public string $type = self::TYPE_INDEX,
) {}
}