Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit 7b75a48

Browse files
authored
Drop annotation support, add Symfony 7 compatibility (Case 191330) (#45)
1 parent 0c6bbef commit 7b75a48

11 files changed

+55
-152
lines changed

UPGRADING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade notes for `webfactory/visibility-filter-bundle`
22

3+
## 2.0.0
4+
5+
* Annotation support has been dropped. Use the Atrtibute for configuration.
6+
37
## 1.5.0
48

59
* The `\Webfactory\VisibilityFilterBundle\Annotation\VisibilityColumn` annotation has been deprecated. Use the

composer.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,21 @@
1414
},
1515
"require": {
1616
"php": "^8.1",
17-
"doctrine/annotations": "^1.12",
1817
"doctrine/doctrine-bundle": "^1.12.13|^2.0",
1918
"doctrine/orm": "^2.7.2",
20-
"symfony/config": "^5.4|^6.4",
21-
"symfony/dependency-injection": "^5.4|^6.4",
19+
"symfony/config": "^5.4|^6.4|^7.0",
20+
"symfony/dependency-injection": "^5.4|^6.4|^7.0",
2221
"symfony/deprecation-contracts": "^3.6.0",
23-
"symfony/event-dispatcher": "^5.4|^6.4",
24-
"symfony/http-kernel": "^5.4|^6.4"
22+
"symfony/event-dispatcher": "^5.4|^6.4|^7.0",
23+
"symfony/http-kernel": "^5.4|^6.4|^7.0"
2524
},
2625
"config": {
2726
"sort-packages": true
2827
},
2928
"require-dev": {
3029
"dama/doctrine-test-bundle": "^6.5",
3130
"phpunit/phpunit": "^8.5",
32-
"symfony/framework-bundle": "^5.4|^6.4",
33-
"symfony/yaml": "^5.4|^6.4"
31+
"symfony/framework-bundle": "^5.4|^6.4|^7.0",
32+
"symfony/yaml": "^5.4|^6.4|^7.0"
3433
}
3534
}

src/Annotation/VisibilityColumn.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/DependencyInjection/services.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ services:
77
- 'y'
88

99
Webfactory\VisibilityFilterBundle\Filter\VisibilityColumnRetriever:
10-
arguments:
11-
- '@Doctrine\Common\Annotations\Reader'
1210

1311
Webfactory\VisibilityFilterBundle\DependencyInjection\OnRequestDependencyInjector:
1412
arguments:

src/Filter/VisibilityColumnRetriever.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,13 @@
22

33
namespace Webfactory\VisibilityFilterBundle\Filter;
44

5-
use Doctrine\Common\Annotations\Reader;
65
use Doctrine\ORM\Mapping\ClassMetadata;
76
use ReflectionProperty;
87
use RuntimeException;
9-
use Webfactory\VisibilityFilterBundle\Annotation\VisibilityColumn;
8+
use Webfactory\VisibilityFilterBundle\Attribute\VisibilityColumn;
109

1110
final class VisibilityColumnRetriever
1211
{
13-
/**
14-
* @var Reader
15-
*/
16-
private $annotationReader;
17-
18-
public function __construct(Reader $annotationReader)
19-
{
20-
$this->annotationReader = $annotationReader;
21-
}
22-
2312
public function getVisibilityColumnName(ClassMetadata $classMetadata): ?string
2413
{
2514
$property = $this->getVisibilityProperty($classMetadata);
@@ -40,19 +29,7 @@ private function getVisibilityProperty(ClassMetadata $classMetadata): ?Reflectio
4029
$visibilityProperty = null;
4130

4231
foreach ($classMetadata->getReflectionClass()->getProperties() as $property) {
43-
if (\PHP_MAJOR_VERSION >= 8) {
44-
if (0 < \count($property->getAttributes(\Webfactory\VisibilityFilterBundle\Attribute\VisibilityColumn::class))) {
45-
$visibilityProperty = $property;
46-
}
47-
}
48-
49-
if (null !== $this->annotationReader->getPropertyAnnotation($property, VisibilityColumn::class)) {
50-
trigger_deprecation(
51-
'webfactory/visibility-filter-bundle',
52-
'1.5.0',
53-
'Configuring webfactory/visibility-filter-bundle with annotations is deprecated, use attributes instead.'
54-
);
55-
32+
if (0 < \count($property->getAttributes(VisibilityColumn::class))) {
5633
if (null !== $visibilityProperty) {
5734
throw new RuntimeException('More than 1 visibility column configured for '.$classMetadata->getName().'. You must only configure 1 visibility column per entity.');
5835
}

tests/Fixtures/EntityWithFaultyVisibilityColumn.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,16 @@
33
namespace Webfactory\VisibilityFilterBundle\Tests\Fixtures;
44

55
use Doctrine\ORM\Mapping as ORM;
6-
use Webfactory\VisibilityFilterBundle\Annotation\VisibilityColumn;
6+
use Webfactory\VisibilityFilterBundle\Attribute\VisibilityColumn;
77

8-
/**
9-
* @ORM\Entity()
10-
*/
8+
#[ORM\Entity]
119
class EntityWithFaultyVisibilityColumn
1210
{
13-
/**
14-
* @VisibilityColumn()
15-
*
16-
* (No Doctrine Column Annotation)
17-
*
18-
* @var string
19-
*/
20-
public $visibilityColumn;
11+
// (No Doctrine Column Annotation)
12+
#[VisibilityColumn]
13+
public string $visibilityColumn;
2114

22-
/**
23-
* @ORM\Id()
24-
* @ORM\Column()
25-
*
26-
* @var int
27-
*/
28-
public $id;
15+
#[ORM\Id]
16+
#[ORM\Column]
17+
public int $id;
2918
}

tests/Fixtures/EntityWithManyToManyRelationship.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,19 @@
55
use Doctrine\Common\Collections\Collection;
66
use Doctrine\ORM\Mapping as ORM;
77

8-
/**
9-
* @ORM\Entity()
10-
*/
8+
#[ORM\Entity]
119
class EntityWithManyToManyRelationship
1210
{
13-
/**
14-
* Using many to many relationship to avoid the need of an inversed column in the target entity.
15-
*
16-
* @ORM\ManyToMany(targetEntity="EntityWithProperVisibilityColumn")
17-
* @ORM\JoinTable(name="jointable",
18-
* joinColumns={@ORM\JoinColumn(name="this", referencedColumnName="id")},
19-
* inverseJoinColumns={@ORM\JoinColumn(name="that", referencedColumnName="id")}
20-
* )
21-
*
22-
* @var Collection&array
23-
*/
24-
public $relationship;
11+
// Using many to many relationship to avoid the need of an inversed column in the target entity.
12+
#[ORM\ManyToMany(targetEntity: EntityWithProperVisibilityColumn::class)]
13+
#[ORM\JoinTable(name: 'jointable')]
14+
#[ORM\JoinColumn(name: 'this', referencedColumnName: 'id')]
15+
#[ORM\InverseJoinColumn(name: 'that', referencedColumnName: 'id')]
16+
public array|Collection $relationship;
2517

26-
/**
27-
* @ORM\Id()
28-
* @ORM\Column()
29-
*
30-
* @var int
31-
*/
32-
public $id;
18+
#[ORM\Id]
19+
#[ORM\Column]
20+
public int $id;
3321

3422
public function __construct(int $id)
3523
{

tests/Fixtures/EntityWithNoVisibilityColumn.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44

55
use Doctrine\ORM\Mapping as ORM;
66

7-
/**
8-
* @ORM\Entity()
9-
*/
7+
#[ORM\Entity]
108
class EntityWithNoVisibilityColumn
119
{
12-
/**
13-
* @ORM\Id()
14-
* @ORM\Column()
15-
*
16-
* @var int
17-
*/
18-
public $id;
10+
#[ORM\Id]
11+
#[ORM\Column(type: 'integer')]
12+
public int $id;
13+
14+
public function __construct(int $id)
15+
{
16+
$this->id = $id;
17+
}
1918
}

tests/Fixtures/EntityWithOneToOneRelationship.php

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

55
use Doctrine\ORM\Mapping as ORM;
66

7-
/**
8-
* @ORM\Entity()
9-
*/
7+
#[ORM\Entity]
108
class EntityWithOneToOneRelationship
119
{
12-
/**
13-
* @ORM\OneToOne(targetEntity="EntityWithProperVisibilityColumn", fetch="EAGER") fetch="EAGER" prevents a proxy object being put in here, so this will be null when the related entity is not found
14-
*
15-
* @var EntityWithProperVisibilityColumn
16-
*/
17-
public $relationship;
10+
// fetch="EAGER" prevents a proxy object being put in here, so this will be null when the related entity is not found
11+
#[ORM\OneToOne(targetEntity: EntityWithProperVisibilityColumn::class, fetch: 'EAGER')]
12+
public ?EntityWithProperVisibilityColumn $relationship = null;
1813

19-
/**
20-
* @ORM\Id()
21-
* @ORM\Column()
22-
*
23-
* @var int
24-
*/
25-
public $id;
14+
#[ORM\Id]
15+
#[ORM\Column]
16+
public int $id;
2617

2718
public function __construct(int $id)
2819
{

tests/Fixtures/EntityWithProperVisibilityColumn.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,18 @@
33
namespace Webfactory\VisibilityFilterBundle\Tests\Fixtures;
44

55
use Doctrine\ORM\Mapping as ORM;
6-
use Webfactory\VisibilityFilterBundle\Annotation\VisibilityColumn;
6+
use Webfactory\VisibilityFilterBundle\Attribute\VisibilityColumn;
77

8-
/**
9-
* @ORM\Entity()
10-
*/
8+
#[ORM\Entity]
119
class EntityWithProperVisibilityColumn
1210
{
13-
/**
14-
* @VisibilityColumn()
15-
*
16-
* @ORM\Column(type="string")
17-
*
18-
* @var string
19-
*/
20-
public $visibilityColumn;
11+
#[ORM\Column(type: 'string')]
12+
#[VisibilityColumn]
13+
public string $visibilityColumn;
2114

22-
/**
23-
* @ORM\Id()
24-
* @ORM\Column()
25-
*
26-
* @var int
27-
*/
28-
public $id;
15+
#[ORM\Id]
16+
#[ORM\Column(type: 'integer')]
17+
public int $id;
2918

3019
public function __construct(int $id, string $visibilityColumn)
3120
{

0 commit comments

Comments
 (0)