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

Commit 0c6bbef

Browse files
authored
Allow configuration via PHP attribute (Case 191330) (#43)
Also: - Deprecate the use of the annotation - Drop support for PHP 7
1 parent e0203e0 commit 0c6bbef

File tree

8 files changed

+61
-82
lines changed

8 files changed

+61
-82
lines changed

.github/workflows/depedencies.yml

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
on: [push]
22
name: Dependencies
33
env:
4-
PHP_VERSION: 7.2
5-
PHP_8_VERSION: 8.1
4+
PHP_VERSION: 8.1
65

76
jobs:
87
composer-require-checker:
9-
name: Check missing composer requirements (PHP 7.2)
8+
name: Check missing composer requirements (PHP 8.1)
109
runs-on: ubuntu-22.04
1110
steps:
1211
- uses: actions/checkout@v4
@@ -33,36 +32,5 @@ jobs:
3332
- run: |
3433
composer install --no-interaction --no-scripts --no-progress --no-suggest
3534
composer show
36-
- name: ComposerRequireChecker
37-
uses: docker://webfactory/composer-require-checker:3.2.0
38-
39-
composer-require-checker_PHP81:
40-
name: Check missing composer requirements (PHP 8.1)
41-
runs-on: ubuntu-22.04
42-
steps:
43-
- uses: actions/checkout@v4
44-
- name: Configure Composer
45-
run: |
46-
mkdir -p ~/.composer/cache
47-
- name: Konfiguriere PHP-Version und -Einstellungen im Worker-Node
48-
uses: shivammathur/setup-php@v2
49-
with:
50-
php-version: ${{ env.PHP_8_VERSION }}
51-
coverage: none
52-
tools: composer:v2
53-
ini-values: variables_order=EGPCS
54-
# Falls spezielle Extensions installiert werden müssen:
55-
# extensions: intl, mbstring
56-
- name: Cache Composer Dependencies
57-
uses: actions/cache@v4
58-
with:
59-
path: vendor/
60-
key: composer-${{ env.PHP_8_VERSION }}-${{ hashFiles('composer.*') }}
61-
restore-keys: |
62-
composer-${{ env.PHP_8_VERSION }}-${{ github.ref }}
63-
composer-${{ env.PHP_8_VERSION }}-
64-
- run: |
65-
composer install --no-interaction --no-scripts --no-progress --no-suggest
66-
composer show
6735
- name: ComposerRequireChecker
6836
uses: docker://ghcr.io/webfactory/composer-require-checker:4.6.0

.github/workflows/tests.yml

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ on: [push]
22
name: Tests
33
env:
44
APP_ENV: test
5-
PHP_VERSION: 7.2
6-
PHP_8_VERSION: 8.1
5+
PHP_VERSION: 8.1
76
TEMP: ${{ github.workspace }}/tmp
87

98
jobs:
109
PHPUnit:
11-
name: PHPUnit (PHP 7.2)
10+
name: PHPUnit (PHP 8.1)
1211
runs-on: ubuntu-22.04
1312
steps:
1413
- uses: actions/checkout@v4
@@ -37,34 +36,3 @@ jobs:
3736
composer install --no-interaction --no-scripts --no-progress --no-suggest
3837
composer show
3938
- run: vendor/bin/phpunit -vvv
40-
41-
PHPUnit_PHP81:
42-
name: PHPUnit (PHP 8.1)
43-
runs-on: ubuntu-22.04
44-
steps:
45-
- uses: actions/checkout@v4
46-
- name: Configure Composer
47-
run: |
48-
mkdir -p ~/.composer/cache
49-
- run: mkdir --mode=777 -p $GITHUB_WORKSPACE/{tmp,logs}
50-
- name: Konfiguriere PHP-Version und -Einstellungen im Worker-Node
51-
uses: shivammathur/setup-php@v2
52-
with:
53-
php-version: ${{ env.PHP_8_VERSION }}
54-
coverage: none
55-
tools: composer:v2
56-
ini-values: variables_order=EGPCS
57-
# Falls spezielle Extensions installiert werden müssen:
58-
# extensions: intl, mbstring
59-
- name: Cache Composer Dependencies
60-
uses: actions/cache@v4
61-
with:
62-
path: vendor/
63-
key: composer-${{ env.PHP_8_VERSION }}-${{ hashFiles('composer.*') }}
64-
restore-keys: |
65-
composer-${{ env.PHP_8_VERSION }}-${{ github.ref }}
66-
composer-${{ env.PHP_8_VERSION }}-
67-
- run: |
68-
composer install --no-interaction --no-scripts --no-progress --no-suggest
69-
composer show
70-
- run: vendor/bin/phpunit -vvv

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,20 @@ grade on a scale, based on which the visibility of the object will be determined
4646
**Currently, only entities that have a visibility column configured will be filtered at all.**
4747

4848
All you need to configure on your entity is *which* of its fields will be the one with the visibility information.
49-
You can do that by Adding the `VisibilityColumn()` annotation to that field.
49+
You can do that by Adding the `VisibilityColumn` attribute to that field.
5050

5151
```php
5252
5353
use Doctrine\ORM\Mapping as ORM;
54-
use Webfactory\VisibilityFilterBundle\Annotation\VisibilityColumn;
54+
use Webfactory\VisibilityFilterBundle\Attribute\VisibilityColumn;
5555
56-
/**
57-
* @ORM\Entity()
58-
*/
56+
#[ORM\Entity()]
5957
class EntityWithVisibilityColumn
6058
{
6159
// ...
62-
/**
63-
* @VisibilityColumn()
64-
*
65-
* @ORM\Column(type="string")
66-
*
67-
* @var string
68-
*/
69-
private $visibilityColumn;
60+
#[ORM\Column(type: "string")]
61+
#[VisibilityColumn]
62+
private string $visibilityColumn;
7063
// ...
7164
}
7265
```

UPGRADING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Upgrade notes for `webfactory/visibility-filter-bundle`
2+
3+
## 1.5.0
4+
5+
* The `\Webfactory\VisibilityFilterBundle\Annotation\VisibilityColumn` annotation has been deprecated. Use the
6+
`\Webfactory\VisibilityFilterBundle\Attribute\VisibilityColumn` attribute for configuration instead.
7+
* Support for PHP 7 has been dropped.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
}
1414
},
1515
"require": {
16-
"php": "^7.2|^8.1",
16+
"php": "^8.1",
1717
"doctrine/annotations": "^1.12",
1818
"doctrine/doctrine-bundle": "^1.12.13|^2.0",
1919
"doctrine/orm": "^2.7.2",
2020
"symfony/config": "^5.4|^6.4",
2121
"symfony/dependency-injection": "^5.4|^6.4",
22+
"symfony/deprecation-contracts": "^3.6.0",
2223
"symfony/event-dispatcher": "^5.4|^6.4",
2324
"symfony/http-kernel": "^5.4|^6.4"
2425
},

src/Annotation/VisibilityColumn.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@
1313
*
1414
* @Annotation
1515
* @Target("PROPERTY")
16+
*
17+
* @deprecated, to be replaced by attribute-based configuration
1618
*/
1719
final class VisibilityColumn
1820
{
21+
public function __construct(array $parameters)
22+
{
23+
trigger_deprecation(
24+
'webfactory/visibility-filter-bundle',
25+
'1.5.0',
26+
'The %s annotation has been deprecated, use the %s attribute instead.',
27+
__CLASS__,
28+
\Webfactory\VisibilityFilterBundle\Attribute\VisibilityColumn::class
29+
);
30+
}
1931
}

src/Attribute/VisibilityColumn.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Webfactory\VisibilityFilterBundle\Attribute;
4+
5+
use Attribute;
6+
use Webfactory\VisibilityFilterBundle\Filter\Strategy\FilterStrategy;
7+
8+
/**
9+
* This attribute marks a field of an entity as the field containing visibility information (e.g. "y" for visible,
10+
* "n" for invisible, or a more complicated system). If the VisibilityFilterBundle is set up, it will be interpreted
11+
* by an implementation of @see FilterStrategy.
12+
*
13+
* For more information on visibility filtering, consider reading the README.md file of this bundle.
14+
*/
15+
#[Attribute(Attribute::TARGET_PROPERTY)]
16+
final class VisibilityColumn
17+
{
18+
}

src/Filter/VisibilityColumnRetriever.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ private function getVisibilityProperty(ClassMetadata $classMetadata): ?Reflectio
4040
$visibilityProperty = null;
4141

4242
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+
4349
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+
4456
if (null !== $visibilityProperty) {
4557
throw new RuntimeException('More than 1 visibility column configured for '.$classMetadata->getName().'. You must only configure 1 visibility column per entity.');
4658
}

0 commit comments

Comments
 (0)