Skip to content

Commit 3a96ece

Browse files
committed
up
1 parent b5eed22 commit 3a96ece

File tree

5 files changed

+103
-20
lines changed

5 files changed

+103
-20
lines changed

src/Configurator.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function initEmbedding(Embeddable $emb, \ReflectionClass $class): EntityS
9797

9898
public function initFields(EntitySchema $entity, \ReflectionClass $class, string $columnPrefix = ''): void
9999
{
100-
foreach ($this->getActualProperties($class) as $property) {
100+
foreach ($class->getProperties() as $property) {
101101
try {
102102
$column = $this->reader->firstPropertyMetadata($property, Column::class);
103103
} catch (\Exception $e) {
@@ -114,13 +114,14 @@ public function initFields(EntitySchema $entity, \ReflectionClass $class, string
114114

115115
$field = $this->initField($property->getName(), $column, $class, $columnPrefix);
116116
$field->setEntityClass($property->getDeclaringClass()->getName());
117+
$field->setObsolete($this->isObsolete($property));
117118
$entity->getFields()->set($property->getName(), $field);
118119
}
119120
}
120121

121122
public function initRelations(EntitySchema $entity, \ReflectionClass $class): void
122123
{
123-
foreach ($this->getActualProperties($class) as $property) {
124+
foreach ($class->getProperties() as $property) {
124125
$metadata = $this->getPropertyMetadata($property, RelationAnnotation\RelationInterface::class);
125126

126127
foreach ($metadata as $meta) {
@@ -173,6 +174,7 @@ public function initRelations(EntitySchema $entity, \ReflectionClass $class): vo
173174
$relation->getOptions()->set($option, $value);
174175
}
175176

177+
$relation->setObsolete($this->isObsolete($property));
176178
// need relation definition
177179
$entity->getRelations()->set($property->getName(), $relation);
178180
}
@@ -415,22 +417,8 @@ private function isOnInsertGeneratedField(Field $field): bool
415417
};
416418
}
417419

418-
/**
419-
* @return \Generator<\ReflectionProperty>
420-
*/
421-
private function getActualProperties(\ReflectionClass $class): \Generator
420+
private function isObsolete(\ReflectionProperty $property): bool
422421
{
423-
foreach ($class->getProperties() as $property) {
424-
// Obsolete property must not be included in the scheme.
425-
$metadata = $this->getPropertyMetadata($property, Obsolete::class);
426-
if (!\is_array($metadata)) {
427-
$metadata = \iterator_to_array($metadata);
428-
}
429-
if ($metadata !== []) {
430-
continue;
431-
}
432-
433-
yield $property;
434-
}
422+
return $this->reader->firstPropertyMetadata($property, Obsolete::class) !== null;
435423
}
436424
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures26;
6+
7+
use Cycle\Annotated\Annotation\Column;
8+
use Cycle\Annotated\Annotation\Embeddable;
9+
10+
/**
11+
* @Embeddable(columnPrefix="address_")
12+
*/
13+
#[Embeddable(columnPrefix: 'address_')]
14+
class Address
15+
{
16+
/** @Column(type="string") */
17+
#[Column(type: 'string')]
18+
protected $city;
19+
20+
/** @Column(type="string") */
21+
#[Column(type: 'string')]
22+
protected $country;
23+
24+
/** @Column(type="string") */
25+
#[Column(type: 'string')]
26+
protected $address;
27+
28+
/** @Column(type="int") */
29+
#[Column(type: 'integer')]
30+
protected $zipcode;
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures26;
6+
7+
use Cycle\Annotated\Annotation\Column;
8+
use Cycle\Annotated\Annotation\Entity;
9+
use Cycle\Annotated\Annotation\Obsolete;
10+
use Cycle\Annotated\Annotation\Relation\BelongsTo;
11+
12+
/**
13+
* @Entity(table="passport")
14+
*/
15+
#[Entity(table: 'passport')]
16+
class Passport
17+
{
18+
/** @Column(type="primary") */
19+
#[Column(type: 'primary')]
20+
protected $id;
21+
22+
/** @Column(type="string") */
23+
#[Column(type: 'string')]
24+
protected $number;
25+
26+
/**
27+
* @Obsolete
28+
* @BelongsTo(target=User::class)
29+
*/
30+
#[Obsolete]
31+
#[BelongsTo(target: User::class, innerKey: 'passport_id', outerKey: 'id')]
32+
protected User $user;
33+
}

tests/Annotated/Fixtures/Fixtures26/User.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Cycle\Annotated\Annotation\Column;
88
use Cycle\Annotated\Annotation\Entity;
99
use Cycle\Annotated\Annotation\Obsolete;
10+
use Cycle\Annotated\Annotation\Relation\Embedded;
11+
use Cycle\Annotated\Annotation\Relation\HasOne;
1012

1113
/**
1214
* @Entity(table="user")
@@ -23,8 +25,8 @@ class User
2325
protected $name;
2426

2527
/**
26-
* @Column(type="integer", nullable=true)
2728
* @Obsolete
29+
* @Column(type="integer", nullable=true)
2830
*
2931
* @deprecated Since May 5, 2025
3032
*/
@@ -36,5 +38,25 @@ class User
3638
* There is must not be problems with it.
3739
*/
3840
#[Obsolete]
39-
private $secret;
41+
protected $secret;
42+
43+
/**
44+
* @Obsolete
45+
* @Embedded(target=Address::class)
46+
*/
47+
#[Obsolete]
48+
#[Embedded(target: Address::class)]
49+
protected Address $address;
50+
51+
/**
52+
* @Obsolete
53+
* @HasOne(target=Passport::class)
54+
*/
55+
#[Obsolete]
56+
#[HasOne(target: Passport::class)]
57+
protected $passport;
58+
59+
public function __construct() {
60+
$this->address = new Address();
61+
}
4062
}

tests/Annotated/Functional/Driver/Common/ObsoleteTest.php

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

55
namespace Cycle\Annotated\Tests\Functional\Driver\Common;
66

7+
use Cycle\Annotated\Embeddings;
78
use Cycle\Annotated\Entities;
9+
use Cycle\Annotated\Locator\TokenizerEmbeddingLocator;
810
use Cycle\Annotated\Locator\TokenizerEntityLocator;
911
use Cycle\Annotated\MergeColumns;
1012
use Cycle\Annotated\MergeIndexes;
@@ -40,6 +42,7 @@ public function testObsoleteColumn(ReaderInterface $reader): void
4042
$r = new Registry($this->dbal);
4143

4244
$schema = (new Compiler())->compile($r, [
45+
new Embeddings(new TokenizerEmbeddingLocator($locator, $reader), $reader),
4346
new Entities(new TokenizerEntityLocator($locator, $reader), $reader),
4447
new ResetTables(),
4548
new MergeColumns($reader),
@@ -52,7 +55,13 @@ public function testObsoleteColumn(ReaderInterface $reader): void
5255
new GenerateTypecast(),
5356
]);
5457

58+
$this->assertArrayNotHasKey('user:address:address', $schema);
59+
// user
5560
$this->assertArrayNotHasKey('skype', $schema['user'][SchemaInterface::COLUMNS]);
5661
$this->assertArrayNotHasKey('skype', $schema['user'][SchemaInterface::TYPECAST]);
62+
$this->assertArrayNotHasKey('passport', $schema['user'][SchemaInterface::RELATIONS]);
63+
$this->assertArrayNotHasKey('address', $schema['user'][SchemaInterface::RELATIONS]);
64+
// passport
65+
$this->assertArrayNotHasKey('user', $schema['passport'][SchemaInterface::RELATIONS]);
5766
}
5867
}

0 commit comments

Comments
 (0)