Skip to content

Commit 4024d2e

Browse files
authored
Support for generated fields (#96)
1 parent bb376d2 commit 4024d2e

34 files changed

Lines changed: 314 additions & 47 deletions

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"prefer-stable": true,
88
"require": {
99
"php": ">=8.0",
10-
"cycle/orm": "^2.2.0",
11-
"cycle/schema-builder": "^2.6",
10+
"cycle/orm": "^2.7",
11+
"cycle/schema-builder": "^2.8",
1212
"doctrine/annotations": "^1.14.3 || ^2.0.1",
1313
"spiral/attributes": "^2.8|^3.0",
1414
"spiral/tokenizer": "^2.8|^3.0",

src/Annotation/Column.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
/**
1313
* @Annotation
14-
*
1514
* @NamedArgumentConstructor
16-
*
1715
* @Target({"PROPERTY", "ANNOTATION", "CLASS"})
1816
*/
1917
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]

src/Annotation/Embeddable.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
/**
1111
* @Annotation
12-
*
1312
* @NamedArgumentConstructor
14-
*
1513
* @Target("CLASS")
1614
*/
1715
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]

src/Annotation/Entity.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
/**
1111
* @Annotation
12-
*
1312
* @NamedArgumentConstructor
14-
*
1513
* @Target("CLASS")
1614
*/
1715
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]

src/Annotation/ForeignKey.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
/**
1212
* @Annotation
13-
*
1413
* @NamedArgumentConstructor
15-
*
1614
* @Target({"PROPERTY", "ANNOTATION", "CLASS"})
1715
*/
1816
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]

src/Annotation/GeneratedValue.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Annotation;
6+
7+
use Cycle\ORM\Schema\GeneratedField;
8+
use Spiral\Attributes\NamedArgumentConstructor;
9+
10+
/**
11+
* @Annotation
12+
* @NamedArgumentConstructor
13+
* @Target({"PROPERTY"})
14+
*/
15+
#[\Attribute(\Attribute::TARGET_PROPERTY)]
16+
#[NamedArgumentConstructor]
17+
class GeneratedValue
18+
{
19+
public function __construct(
20+
protected bool $beforeInsert = false,
21+
protected bool $onInsert = false,
22+
protected bool $beforeUpdate = false,
23+
) {
24+
}
25+
26+
public function getFlags(): ?int
27+
{
28+
if (!$this->beforeInsert && !$this->onInsert && !$this->beforeUpdate) {
29+
return null;
30+
}
31+
32+
return
33+
($this->beforeInsert ? GeneratedField::BEFORE_INSERT : 0) |
34+
($this->onInsert ? GeneratedField::ON_INSERT : 0) |
35+
($this->beforeUpdate ? GeneratedField::BEFORE_UPDATE : 0);
36+
}
37+
}

src/Annotation/Inheritance/DiscriminatorColumn.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
/**
1010
* @Annotation
11-
*
1211
* @NamedArgumentConstructor
13-
*
1412
* @Target("CLASS")
1513
*/
1614
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]

src/Annotation/Inheritance/JoinedTable.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
/**
1212
* @Annotation
13-
*
1413
* @NamedArgumentConstructor
15-
*
1614
* @Target("CLASS")
1715
*/
1816
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]

src/Annotation/Inheritance/SingleTable.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
/**
1111
* @Annotation
12-
*
1312
* @NamedArgumentConstructor
14-
*
1513
* @Target("CLASS")
1614
*/
1715
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]

src/Annotation/Relation/BelongsTo.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
/**
1313
* @Annotation
14-
*
1514
* @NamedArgumentConstructor
16-
*
1715
* @Target("PROPERTY")
1816
*/
1917
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]

0 commit comments

Comments
 (0)