- WIP on relations, constrains and foreign keys
This commit is contained in:
parent
01ab6e82d4
commit
d01624b8aa
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Ulmus\Attribute;
|
||||
|
||||
enum ConstrainActionEnum : string
|
||||
{
|
||||
case Cascade = 'cascade';
|
||||
|
||||
case NoAction = 'noaction';
|
||||
|
||||
case Restrict = 'restrict';
|
||||
|
||||
case SetNull = 'setnull';
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Ulmus\Attribute;
|
||||
|
||||
enum IndexTypeEnum : string
|
||||
{
|
||||
case Primary = 'primary';
|
||||
|
||||
case Index = 'index';
|
||||
|
||||
case Unique = 'unique';
|
||||
|
||||
case Spatial = 'spatial';
|
||||
|
||||
case Fulltext = 'fulltext';
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Ulmus\Attribute\Obj;
|
||||
|
||||
use Ulmus\Attribute\Attribute;
|
||||
use Ulmus\Attribute\ConstrainActionEnum;
|
||||
use Ulmus\Attribute\IndexTypeEnum;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
|
||||
class Constrain {
|
||||
public function __construct(
|
||||
public array $columns,
|
||||
public null|IndexTypeEnum $type = null,
|
||||
public null|string $name = null,
|
||||
public null|array|string|\Stringable $foreignKey = null,
|
||||
public null|array|string|\Stringable $references = null,
|
||||
public ConstrainActionEnum $onDelete = ConstrainActionEnum::NoAction,
|
||||
public ConstrainActionEnum $onUpdate = ConstrainActionEnum::NoAction,
|
||||
) {
|
||||
$this->foreignKey = Attribute::handleArrayField($this->foreignKey, false);
|
||||
$this->references = Attribute::handleArrayField($this->references, false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Ulmus\Attribute\Obj;
|
||||
|
||||
use Ulmus\Attribute\IndexTypeEnum;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
|
||||
class Index {
|
||||
public function __construct(
|
||||
public string|array $column,
|
||||
public IndexTypeEnum $type = IndexTypeEnum::Unique,
|
||||
public null|string $name = null,
|
||||
) {}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
namespace Ulmus\Attribute\Property\Field;
|
||||
|
||||
use Ulmus\Attribute\Attribute;
|
||||
use Ulmus\Attribute\ConstrainActionEnum;
|
||||
|
||||
/**
|
||||
* Since we need consistancy between the declaration of our ID and FK fields, it
|
||||
|
@ -10,17 +11,6 @@ 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',
|
||||
|
@ -33,11 +23,10 @@ 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,
|
||||
public null|string $relation = null,
|
||||
public ConstrainActionEnum $onDelete = ConstrainActionEnum::NoAction,
|
||||
public ConstrainActionEnum $onUpdate = ConstrainActionEnum::NoAction,
|
||||
) {
|
||||
$this->references = Attribute::handleArrayField($this->references, false);
|
||||
#$this->references = Attribute::handleArrayField($this->references, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,20 +2,11 @@
|
|||
|
||||
namespace Ulmus\Attribute\Property;
|
||||
|
||||
use Ulmus\Attribute\IndexTypeEnum;
|
||||
|
||||
#[\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,
|
||||
public IndexTypeEnum $type = IndexTypeEnum::Index,
|
||||
) {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Ulmus\Attribute\Property;
|
||||
|
||||
use Ulmus\Attribute\IndexTypeEnum;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
||||
class Unique {
|
||||
|
||||
public function __construct(
|
||||
public IndexTypeEnum $type = IndexTypeEnum::Unique,
|
||||
) {}
|
||||
}
|
|
@ -8,7 +8,7 @@ class EntityCollection extends \ArrayObject implements \JsonSerializable {
|
|||
|
||||
public ? string $entityClass = null;
|
||||
|
||||
public static function instance(array $data, null|string $entityClass) : self
|
||||
public static function instance(array $data, null|string $entityClass = null) : self
|
||||
{
|
||||
$instance = new static($data);
|
||||
$instance->entityClass = $entityClass;
|
||||
|
|
Loading…
Reference in New Issue