Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge code from 3.x #92

Merged
merged 17 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require": {
"php": ">=8.1",
"cycle/orm": "^2.2.0",
"cycle/schema-builder": "^2.5.1",
"cycle/schema-builder": "^2.6",
"spiral/attributes": "^2.8|^3.0",
"spiral/tokenizer": "^2.8|^3.0",
"doctrine/inflector": "^2.0"
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target({"PROPERTY", "ANNOTATION", "CLASS"})
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Embeddable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
Expand Down
14 changes: 11 additions & 3 deletions src/Annotation/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
Expand All @@ -29,6 +27,7 @@ class Entity
* @param non-empty-string|non-empty-string[]|null $typecast
* @param class-string|null $scope Class name of constraint to be applied to every entity query.
* @param Column[] $columns Entity columns.
* @param ForeignKey[] $foreignKeys Entity foreign keys.
*/
public function __construct(
protected ?string $role = null,
Expand All @@ -40,7 +39,8 @@ public function __construct(
protected ?string $source = null,
protected array|string|null $typecast = null,
protected ?string $scope = null,
protected array $columns = []
protected array $columns = [],
protected array $foreignKeys = [],
) {
}

Expand Down Expand Up @@ -113,6 +113,14 @@ public function getColumns(): array
return $this->columns;
}

/**
* @return ForeignKey[]
*/
public function getForeignKeys(): array
{
return $this->foreignKeys;
}

/**
* @return non-empty-string|non-empty-string[]|null
*/
Expand Down
41 changes: 41 additions & 0 deletions src/Annotation/ForeignKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Annotation;

use Doctrine\Common\Annotations\Annotation\Target;
use JetBrains\PhpStorm\ExpectedValues;
use Spiral\Attributes\NamedArgumentConstructor;

/**
* @Annotation
* @NamedArgumentConstructor
* @Target({"PROPERTY", "ANNOTATION", "CLASS"})
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
#[NamedArgumentConstructor]
class ForeignKey
{
/**
* @param non-empty-string $target Role or class name of the target entity.
* @param list<non-empty-string>|non-empty-string|null $innerKey You don't need to specify this if the attribute
* is used on a property.
* @param list<non-empty-string>|non-empty-string|null $outerKey Outer key in the target entity.
* Defaults to the primary key.
* @param 'CASCADE'|'NO ACTION'|'SET null' $action
* @param bool $indexCreate Note: MySQL and MSSQL might create an index for the foreign key automatically.
*/
public function __construct(
public string $target,
public array|string|null $innerKey = null,
public array|string|null $outerKey = null,
/**
* @Enum({"NO ACTION", "CASCADE", "SET NULL"})
*/
#[ExpectedValues(values: ['NO ACTION', 'CASCADE', 'SET NULL'])]
public string $action = 'CASCADE',
public bool $indexCreate = true,
) {
}
}
2 changes: 0 additions & 2 deletions src/Annotation/Inheritance/DiscriminatorColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Inheritance/JoinedTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Inheritance/SingleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("PROPERTY")
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/Embedded.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("PROPERTY")
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("PROPERTY")
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("PROPERTY")
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/Inverse.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target({"PROPERTY", "ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/ManyToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("PROPERTY")
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/Morphed/BelongsToMorphed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("PROPERTY")
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/Morphed/MorphedHasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("PROPERTY")
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/Morphed/MorphedHasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("PROPERTY")
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Relation/RefersTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("PROPERTY")
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target({"CLASS", "ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Table/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("ANNOTATION", "CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE), NamedArgumentConstructor]
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/Table/PrimaryKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

/**
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("ANNOTATION", "CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
Expand Down
Loading
Loading