Skip to content

Commit

Permalink
improve support for php 8
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed Jul 24, 2022
1 parent 95afbe2 commit 6ab9f8d
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 161 deletions.
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ make test TEST="Tests/Util/FilenameUtilsTest.php"

will allow testing single Test Classes.

There are 3 environments available: PHP 7.3, 7.4 and 8.0.
Default environment is *PHP 7.4* if you want to execute it against
other PHP version please use environment variables as this:
There are three environments available: PHP 7.4, 8.0, and 8.1.
Default environment is *PHP 8.1*. If you want to execute it against
other PHP version, please use environment variables as this:

```bash
make tests #PHP 7.3 env
TARGET=74 make tests #PHP 7.4 env
make tests #PHP 8.1 env
TARGET=80 make tests #PHP 8.0 env
TARGET=74 make tests #PHP 7.4 env

make test TEST="tests/Util/FilenameUtilsTest.php" #PHP 7.3 env
make test TEST="tests/Util/FilenameUtilsTest.php" #PHP 8.1 env
TARGET=74 make test TEST="tests/Util/FilenameUtilsTest.php" #PHP 7.4 env
TARGET=80 make test TEST="tests/Util/FilenameUtilsTest.php" #PHP 8.0 env
```
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#/bin/bash

TARGET?=74
TARGET?=81

.PHONY: tests
tests:
Expand Down
44 changes: 44 additions & 0 deletions docker/Dockerfile81
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM php:8.1.8-alpine

ARG MONGODB_VERSION=1.14.0

# Install mongo
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
openssl-dev \
; \
pecl install \
mongodb-${MONGODB_VERSION} \
; \
docker-php-ext-enable \
mongodb \
; \
pecl clear-cache; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .api-add-phpexts-rundeps $runDeps \
curl \
;

RUN curl -s https://getcomposer.org/installer | php

RUN mv composer.phar /usr/local/bin/composer

WORKDIR /srv/vich-uploader

# prevent the reinstallation of vendors at every changes in the source code

#COPY ./docker/script/runTests.sh ./runTests.sh
COPY . ./

RUN set -eux; \
composer install --prefer-dist --ignore-platform-reqs; \
composer clear-cache

CMD ["/init"]
2 changes: 1 addition & 1 deletion docs/configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ vich_uploader:
cache: file
type: annotation # or attribute
mappings:
product_image:
products:
uri_prefix: /uploads # uri prefix to resource
upload_destination: ~ # gaufrette storage fs id, required
namer: ~ # specify a file namer service for this entity, null default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ the service id for the `directory_namer` configuration option of your mapping. A
vich_uploader:
# ...
mappings:
product_image:
products:
upload_destination: product_image
directory_namer: my.directory_namer.product
```
Expand Down
2 changes: 1 addition & 1 deletion docs/events/howto/remove_files_asynchronously.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RemoveFileEventSubscriber implements EventSubscriberInterface
$mapping = $event->getMapping();
$mappingName = $mapping->getMappingName();

if ('product_image' === $mappingName) {
if ('products' === $mappingName) {
$this->dispatch(RemoveProductImageMessage::class, $event);
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/file_namer/howto/create_a_custom_file_namer.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ the service for the `namer` configuration option of your mapping. An example:
vich_uploader:
# ...
mappings:
product_image:
products:
upload_destination: product_image
namer: App\Naming\MyNamer
```
Expand Down
25 changes: 9 additions & 16 deletions docs/known_issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ is the only updated.
A workaround to solve this issue is to manually generate a change:

```php
<?php

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class Product
{
// ...

/**
* @ORM\Column(type="datetime")
*
* @var \DateTimeInterface|null
*/
private $updatedAt;
#[ORM\Column(type: "datetime")]
private ?\DateTimeInterface $updatedAt = null;

// ...

Expand Down Expand Up @@ -76,18 +75,12 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity
* @Vich\Uploadable
*/
#[ORM\Entity]
#[Vich\Uploadable]
class Product
{
/**
* @Vich\UploadableField(mapping="product_image", fileNameProperty="imageName")
*
* @var File|null
*/
private $imageFile;
#[Vich\UploadableField(mapping: "products", fileNameProperty: "imageName")]
private ?File $imageFile = null;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
Expand Down
2 changes: 1 addition & 1 deletion docs/mapping/xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ format and comes with the following syntax to declare your uploadable fields:
<!-- config/vich_uploader/Entity.Product.xml -->
<!-- Attributes "mapping", "name" and "filename_property" are required -->
<vich_uploader class="Acme\DemoBundle\Entity\Product">
<field mapping="product_image" name="imageFile" filename_property="imageName"
<field mapping="products" name="imageFile" filename_property="imageName"
size="imageSize" dimensions="imageDimensions" mime_type="imageMimeType" original_name="imageOriginalName" />
</vich_uploader>
```
Expand Down
2 changes: 1 addition & 1 deletion docs/mapping/yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ format and comes with the following syntax to declare your uploadable fields:
# config/vich_uploader/Entity.Product.yaml
Acme\DemoBundle\Entity\Product:
imageFile:
mapping: product_image # required
mapping: products # required
filename_property: imageName # required
size: imageSize
mime_type: imageMimeType
Expand Down
32 changes: 16 additions & 16 deletions docs/namers.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ property will be used:
vich_uploader:
# ...
mappings:
product_image:
upload_destination: product_image_fs
products:
upload_destination: products_fs
namer:
service: Vich\UploaderBundle\Naming\PropertyNamer
options: { property: 'slug' } # supposing that the object contains a "slug" attribute or a "getSlug" method
options: { property: 'slug' } # supposing that the object contains a "slug" property or a "getSlug" method
```
**HashNamer** will use a hash of random string to name the file. You also can specify
Expand All @@ -48,8 +48,8 @@ hash `algorithm` and result `length` of the file:
vich_uploader:
# ...
mappings:
product_image:
upload_destination: product_image_fs
products:
upload_destination: products_fs
namer:
service: Vich\UploaderBundle\Naming\HashNamer
options: { algorithm: 'sha256', length: 50 }
Expand Down Expand Up @@ -85,8 +85,8 @@ services:
vich_uploader:
# ...
mappings:
product_image:
upload_destination: product_image_fs
products:
upload_destination: products_fs
namer: Vich\UploaderBundle\Naming\SmartUniqueNamer # or any other namer listed above
```

Expand Down Expand Up @@ -133,8 +133,8 @@ configuration option of your mapping:
vich_uploader:
# ...
mappings:
product_image:
upload_destination: product_image
products:
upload_destination: products
directory_namer: Vich\UploaderBundle\Naming\SubdirDirectoryNamer
```

Expand All @@ -144,8 +144,8 @@ Or provide configuration:
vich_uploader:
# ...
mappings:
product_image:
upload_destination: product_image
products:
upload_destination: products
directory_namer:
service: Vich\UploaderBundle\Naming\SubdirDirectoryNamer
options: { chars_per_dir: 1, dirs: 2 } # will create directory "a/b" for "abcdef.jpg"
Expand All @@ -161,11 +161,11 @@ optionally you can use the `transliterate` option to remove special chars from d
vich_uploader:
# ...
mappings:
product_image:
upload_destination: product_image
products:
upload_destination: products
directory_namer:
service: vich_uploader.namer_directory_property
options: { property: 'slug', transliterate: true } # supposing that the object contains a "slug" attribute or a "getSlug" method
options: { property: 'slug', transliterate: true } # supposing that the object contains a "slug" property or a "getSlug" method
```

**CurrentDateTimeDirectoryNamer** creates subdirs depending on the current locale datetime. By default, it will be
Expand All @@ -182,8 +182,8 @@ configuration option of your mapping:
vich_uploader:
# ...
mappings:
product_image:
upload_destination: product_image
products:
upload_destination: products
directory_namer:
service: Vich\UploaderBundle\Naming\CurrentDateTimeDirectoryNamer
options:
Expand Down
10 changes: 5 additions & 5 deletions docs/storage/flysystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vich_uploader:
storage: flysystem

mappings:
product_image:
products:
uri_prefix: /images/products
upload_destination: default.storage # Use the name you defined for your storage here
```
Expand Down Expand Up @@ -84,18 +84,18 @@ oneup_flysystem:
location: '%kernel.project_dir%/public/images/products'

filesystems:
product_image:
products:
adapter: product_adapter
mount: product_image
mount: products

vich_uploader:
db_driver: orm
storage: flysystem

mappings:
product_image:
products:
uri_prefix: /images/products
upload_destination: oneup_flysystem.product_image_filesystem
upload_destination: oneup_flysystem.products_filesystem
```
## That was it!
Expand Down
6 changes: 3 additions & 3 deletions docs/storage/gaufrette.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ knp_gaufrette:
directory: '%kernel.project_dir%/public/images/products'

filesystems:
product_image_fs:
products_fs:
adapter: product_adapter

vich_uploader:
db_driver: orm
storage: gaufrette

mappings:
product_image:
products:
uri_prefix: /images/products
upload_destination: product_image_fs
upload_destination: products_fs
```
Using `Vich\UploaderBundle\Storage\GaufretteStorage` as the storage service,
Expand Down
Loading

0 comments on commit 6ab9f8d

Please sign in to comment.