Skip to content

Commit 4c590b5

Browse files
authored
Merge pull request #1555 from endelwar/deprecate-annotations
Deprecate Annotation namespace in favor of Attribute namespace
2 parents 46fdbd8 + 1adff27 commit 4c590b5

24 files changed

Lines changed: 474 additions & 37 deletions

UPGRADE.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
# Upgrading from v2.8 to v2.9
22

3+
## Deprecations
4+
5+
* The `Vich\UploaderBundle\Mapping\Annotation` namespace is deprecated. Replace it with `Vich\UploaderBundle\Mapping\Attribute`;
6+
The old namespace will be removed in version 3.0.
7+
* `AttributeReader` methods: replace `*Annotation()` with `*Attribute()` (e.g., `getClassAnnotation()``getClassAttribute()`).
8+
9+
## New Features
10+
311
* New `namer_keep_extension` configuration option to force namers to preserve original file extension.
412
* Custom namers using `namer_keep_extension: true` must implement `ConfigurableInterface`.
513

614
# Upgrading from v2.7 to v2.8
715

8-
* Namers are not public anymore. If you uses a custom namer, you can now make it private.
16+
* Namers are not public anymore. If you use a custom namer, you can now make it private.
917

1018
# Upgrading from v2.6 to v2.7
1119

@@ -36,7 +44,7 @@
3644

3745
* every class marked as `@final` is now final
3846
* all properties are now fully type-hinted
39-
* all methods arguments are now fully type-hinted
47+
* all method arguments are now fully type-hinted
4048
* all methods have now return types
4149
* all constructors now use property promotion
4250
* all deprecated features were removed

config/mapping.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Metadata\MetadataFactory;
99
use Vich\UploaderBundle\Metadata\CacheWarmer;
1010
use Vich\UploaderBundle\Metadata\Driver\AnnotationDriver;
11+
use Vich\UploaderBundle\Metadata\Driver\AttributeDriver;
1112
use Vich\UploaderBundle\Metadata\Driver\AttributeReader;
1213
use Vich\UploaderBundle\Metadata\Driver\XmlDriver;
1314
use Vich\UploaderBundle\Metadata\Driver\YamlDriver;
@@ -27,10 +28,15 @@
2728
$services->set('vich_uploader.metadata.attribute_reader', AttributeReader::class);
2829

2930
// drivers
30-
$services->set('vich_uploader.metadata_driver.annotation', AnnotationDriver::class)
31+
$services->set('vich_uploader.metadata_driver.attribute', AttributeDriver::class)
3132
->arg('$reader', service('vich_uploader.metadata.reader'))
3233
->arg('$managerRegistryList', null); // replaced by compiler pass
3334

35+
$services->set('vich_uploader.metadata_driver.annotation', AnnotationDriver::class)
36+
->arg('$reader', service('vich_uploader.metadata.reader'))
37+
->arg('$managerRegistryList', null) // replaced by compiler pass
38+
->deprecate('vich/uploader-bundle', '2.9', 'The "%service_id%" service is deprecated, use "vich_uploader.metadata_driver.attribute" instead.');
39+
3440
$services->set('vich_uploader.metadata_driver.xml', XmlDriver::class)
3541
->args([
3642
service('vich_uploader.metadata.file_locator'),

docs/known_issues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace App\Entity;
7373
7474
use Doctrine\ORM\Mapping as ORM;
7575
use Symfony\Component\HttpFoundation\File\File;
76-
use Vich\UploaderBundle\Mapping\Annotation as Vich;
76+
use Vich\UploaderBundle\Mapping\Attribute as Vich;
7777
7878
#[ORM\Entity]
7979
#[Vich\Uploadable]

docs/usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace App\Entity;
8383
8484
use Doctrine\ORM\Mapping as ORM;
8585
use Symfony\Component\HttpFoundation\File\File;
86-
use Vich\UploaderBundle\Mapping\Annotation as Vich;
86+
use Vich\UploaderBundle\Mapping\Attribute as Vich;
8787
8888
#[ORM\Entity]
8989
#[Vich\Uploadable]
@@ -173,7 +173,7 @@ namespace App\Entity;
173173
use Doctrine\ORM\Mapping as ORM;
174174
use Symfony\Component\HttpFoundation\File\File;
175175
use Vich\UploaderBundle\Entity\File as EmbeddedFile;
176-
use Vich\UploaderBundle\Mapping\Annotation as Vich;
176+
use Vich\UploaderBundle\Mapping\Attribute as Vich;
177177
178178
#[ORM\Entity]
179179
#[Vich\Uploadable]

docs/validators/file_required.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ It validates that either an existing file is present or a new file has been uplo
66
## Basic Usage
77

88
```php
9-
use Vich\UploaderBundle\Mapping\Annotation as Vich;
9+
use Vich\UploaderBundle\Mapping\Attribute as Vich;
1010
use Vich\UploaderBundle\Validator\Constraints as VichAssert;
1111

1212
#[Vich\Uploadable]

src/DependencyInjection/Compiler/RegisterMappingDriversPass.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ public function process(ContainerBuilder $container): void
3030
}
3131

3232
if (\count($managers) > 0) {
33-
$drivers[] = $container->getDefinition('vich_uploader.metadata_driver.annotation')
33+
// Support both new 'attribute' service and deprecated 'annotation' service
34+
$driverServiceId = $container->hasDefinition('vich_uploader.metadata_driver.attribute')
35+
? 'vich_uploader.metadata_driver.attribute'
36+
: 'vich_uploader.metadata_driver.annotation';
37+
38+
$drivers[] = $container->getDefinition($driverServiceId)
3439
->replaceArgument('$managerRegistryList', $managers);
3540
}
3641

src/DependencyInjection/VichUploaderExtension.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function load(array $configs, ContainerBuilder $container): void
5656

5757
$this->loadServicesFiles($container, $config);
5858
$this->registerMetadataDirectories($container, $config);
59-
$this->registerAnnotationStrategy($container, $config);
59+
$this->registerAttributeStrategy($container, $config);
6060
$this->registerCacheStrategy($container, $config);
6161

6262
$this->registerListeners($container, $config);
@@ -139,9 +139,9 @@ protected function registerMetadataDirectories(ContainerBuilder $container, arra
139139
;
140140
}
141141

142-
protected function registerAnnotationStrategy(ContainerBuilder $container, array $config): void
142+
protected function registerAttributeStrategy(ContainerBuilder $container, array $config): void
143143
{
144-
if (!$container->has('vich_uploader.metadata_driver.annotation')) {
144+
if (!$container->has('vich_uploader.metadata_driver.attribute') && !$container->has('vich_uploader.metadata_driver.annotation')) {
145145
return;
146146
}
147147

@@ -168,6 +168,16 @@ protected function registerAnnotationStrategy(ContainerBuilder $container, array
168168
}
169169
}
170170

171+
/**
172+
* @deprecated since 2.9, use registerAttributeStrategy() instead
173+
*/
174+
protected function registerAnnotationStrategy(ContainerBuilder $container, array $config): void
175+
{
176+
trigger_deprecation('vich/uploader-bundle', '2.9', 'Method "%s" is deprecated, use "registerAttributeStrategy()" instead.', __METHOD__);
177+
178+
$this->registerAttributeStrategy($container, $config);
179+
}
180+
171181
protected function registerCacheStrategy(ContainerBuilder $container, array $config): void
172182
{
173183
if ('none' === $config['metadata']['cache']) {

src/Mapping/Annotation/Uploadable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212
* @Target({"CLASS"})
1313
* @NamedArgumentConstructor
1414
*
15+
* @deprecated since 2.9, use Vich\UploaderBundle\Mapping\Attribute\Uploadable instead
16+
*
1517
* @author Dustin Dobervich <ddobervich@gmail.com>
1618
*/
1719
#[\Attribute(\Attribute::TARGET_CLASS)]
1820
final class Uploadable implements AnnotationInterface
1921
{
22+
public function __construct()
23+
{
24+
trigger_deprecation('vich/uploader-bundle', '2.9', 'The "Vich\UploaderBundle\Mapping\Annotation\Uploadable" class is deprecated, use "Vich\UploaderBundle\Mapping\Attribute\Uploadable" instead.');
25+
}
2026
}

src/Mapping/Annotation/UploadableField.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
* @Target({"PROPERTY"})
1313
* @NamedArgumentConstructor
1414
*
15+
* @deprecated since 2.9, use Vich\UploaderBundle\Mapping\Attribute\UploadableField instead
16+
*
1517
* @author Dustin Dobervich <ddobervich@gmail.com>
1618
*/
1719
#[\Attribute(\Attribute::TARGET_PROPERTY)]
1820
final class UploadableField implements AnnotationInterface
1921
{
20-
/**
21-
* Constructs a new instance of UploadableField.
22-
*/
2322
public function __construct(
2423
private readonly string $mapping,
2524
private readonly ?string $fileNameProperty = null,
@@ -28,6 +27,7 @@ public function __construct(
2827
private readonly ?string $originalName = null,
2928
private readonly ?string $dimensions = null
3029
) {
30+
trigger_deprecation('vich/uploader-bundle', '2.9', 'The "Vich\UploaderBundle\Mapping\Annotation\UploadableField" class is deprecated, use "Vich\UploaderBundle\Mapping\Attribute\UploadableField" instead.');
3131
}
3232

3333
/**

src/Mapping/AnnotationInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Vich\UploaderBundle\Mapping;
44

5-
interface AnnotationInterface
5+
/**
6+
* @deprecated since 2.9, use AttributeInterface instead
7+
*/
8+
interface AnnotationInterface extends AttributeInterface
69
{
710
}

0 commit comments

Comments
 (0)