- Added relation's shortcut attributes

This commit is contained in:
Dave Mc Nicoll 2024-12-02 21:36:03 +00:00
parent 9eed2fe1a8
commit 1fac12c928
3 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,42 @@
<?php
namespace Ulmus\Attribute\Property\Relation;
use Ulmus\Attribute\Property\Relation;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class ManyToMany extends Relation
{
public function __construct(
public \Stringable|string|array $key = "",
public null|\Closure|array $generateKey = null,
public null|\Stringable|string|array $foreignKey = null,
public null|\Stringable|string|array $foreignField = null,
public array $foreignKeys = [],
public null|string $bridge = null,
public null|\Stringable|string|array $bridgeKey = null,
public null|\Stringable|string|array $bridgeField = null,
public null|\Stringable|string|array $bridgeForeignKey = null,
public null|\Stringable|string|array $field = null,
public null|string $entity = null,
public null|string $join = null,
public null|string $function = null,
) {
parent::__construct(
RelationTypeEnum::manyToMany,
$this->key,
$this->generateKey,
$this->foreignKey,
$this->foreignField,
$this->foreignKeys,
$this->bridge,
$this->bridgeKey,
$this->bridgeField,
$this->bridgeForeignKey,
$this->field,
$this->entity,
$this->join,
$this->function,
);
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Ulmus\Attribute\Property\Relation;
use Ulmus\Attribute\Property\Relation;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class OneToMany extends Relation
{
public function __construct(
public \Stringable|string|array $key = "",
public null|\Closure|array $generateKey = null,
public null|\Stringable|string|array $foreignKey = null,
public null|\Stringable|string|array $foreignField = null,
public array $foreignKeys = [],
public null|string $bridge = null,
public null|\Stringable|string|array $bridgeKey = null,
public null|\Stringable|string|array $bridgeField = null,
public null|\Stringable|string|array $bridgeForeignKey = null,
public null|\Stringable|string|array $field = null,
public null|string $entity = null,
public null|string $join = null,
public null|string $function = null,
) {
parent::__construct(
RelationTypeEnum::oneToMany,
$this->key,
$this->generateKey,
$this->foreignKey,
$this->foreignField,
$this->foreignKeys,
$this->bridge,
$this->bridgeKey,
$this->bridgeField,
$this->bridgeForeignKey,
$this->field,
$this->entity,
$this->join,
$this->function,
);
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Ulmus\Attribute\Property\Relation;
use Ulmus\Attribute\Property\Relation;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class OneToOne extends Relation
{
public function __construct(
public \Stringable|string|array $key = "",
public null|\Closure|array $generateKey = null,
public null|\Stringable|string|array $foreignKey = null,
public null|\Stringable|string|array $foreignField = null,
public array $foreignKeys = [],
public null|string $bridge = null,
public null|\Stringable|string|array $bridgeKey = null,
public null|\Stringable|string|array $bridgeField = null,
public null|\Stringable|string|array $bridgeForeignKey = null,
public null|\Stringable|string|array $field = null,
public null|string $entity = null,
public null|string $join = null,
public null|string $function = null,
) {
parent::__construct(
RelationTypeEnum::oneToOne,
$this->key,
$this->generateKey,
$this->foreignKey,
$this->foreignField,
$this->foreignKeys,
$this->bridge,
$this->bridgeKey,
$this->bridgeField,
$this->bridgeForeignKey,
$this->field,
$this->entity,
$this->join,
$this->function,
);
}
}