Skip to content

Commit

Permalink
Merge pull request #1482 from garak/fix-docs
Browse files Browse the repository at this point in the history
📝 discourage annotations in the docs
  • Loading branch information
garak authored Dec 5, 2024
2 parents adf48d9 + 839b32e commit 6fb0038
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 100 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"yoast/phpunit-polyfills": "^2.0"
},
"suggest": {
"doctrine/annotations": "If you use doctrine/doctrine-bundle >2.7, this package is required to use annotations",
"doctrine/doctrine-bundle": "For integration with Doctrine",
"doctrine/mongodb-odm-bundle": "For integration with Doctrine ODM",
"doctrine/orm": "For integration with Doctrine ORM",
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ vich_uploader:
metadata:
auto_detection: true
cache: file
type: attribute # or annotation
type: attribute
mappings:
products:
uri_prefix: /uploads # uri prefix to resource
Expand Down
10 changes: 5 additions & 5 deletions docs/known_issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ metadata is joined with the file during the upload.
To summarize, [Gaufrette support for metadata is flawed](https://github.com/KnpLabs/Gaufrette/issues/108)
(see issue [GH-163](https://github.com/dustin10/VichUploaderBundle/issues/163)).

## Doctrine/annotations package required when using doctrine-bundle >= 2.8
## Doctrine/annotations package required when using annotations and doctrine-bundle >= 2.8

If your project is using `doctrine-bundle:>=2.8`, you must require `doctrine/annotations` package from
your project as it is not required in `doctrine-bundle` anymore from this version.
This bundle is using a `Reader` interface from this package in order to work for both annotations
and attributes mapping.
If your project uses annotations and `doctrine-bundle:>=2.8`, you must require the `doctrine/annotations`
package from your project, as it is not required in `doctrine-bundle` anymore from this version.
This bundle uses a `Reader` interface from this package in order to work for both attributes and annotations
mapping, but annotations are deprecated and will be removed in the future.
97 changes: 4 additions & 93 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,100 +153,11 @@ class Product
}
```

Or, with annotations :

``` php
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity
* @Vich\Uploadable
*/
class Product
{
/**
* @ORM\Id
* @ORM\Column()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
// ... other fields
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="products", fileNameProperty="imageName", size="imageSize")
*/
private ?File $imageFile;
/**
* @ORM\Column(nullable="true")
*/
private ?string $imageName = null;
/**
* @ORM\Column(nullable="true")
*/
private ?int $imageSize = null;
/**
* @ORM\Column(nullable="true")
*/
private ?\DateTimeImmutable $updatedAt = null;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
**Note:**

public function getImageSize(): ?int
{
return $this->imageSize;
}
}
```
> This bundle also supports annotations, but the attribute syntax is recommended.
> If you look for examples about annotations mapping, please refer to an older
> version of the documentation.

Alternatively you can use `Vich\UploaderBundle\Entity\File` embeddable for storing file info in your ORM entity:

Expand Down

0 comments on commit 6fb0038

Please sign in to comment.