Skip to content

Commit

Permalink
Allow Symfony 7 (#436)
Browse files Browse the repository at this point in the history
* 1. Implemented the AsCommand attributes for final $defaultName
2. Removed support for PHP <8.0
3. Reworked the __construct methods to be on-par with php >=8.0
4. Removed all rferences to GetMasterRequest - using only getMainRequest now
5. Fixed custom_uploader.md documentation to use getMainRequest

* Changed the ci.yml fot gihub actions

* Ran php cs fixer for code style
Reran testes, all passes

* Updated php_cs_fixer to v4
Changed the config file to work with the new version
Ran php_cs_fixer on codebase
Tests still pass

* Updated php_stan and config file

* Updated php unit-brdge to v6.0.*

* Add tyope hint var comment/Annotation to the $helper class

* Fixe some more phpstan issues with regards to type hints and retur types

* Some mroe php cs fixer changes

* Removed unused sensio/framework-extra-bundle + updated symfony/phpunit-bridge version constraint

* Allow Symfony 7

* Updated CI to test SF 6.2 - 7.0

* Fixes phpstan errors

* Refactored phpstan fixes

* Fix CI for prefer lowest run

* Drop support for symfony/* ^4.4

* Fix CI for Yaml incompatibility

---------

Co-authored-by: Johan Kasselman <[email protected]>
  • Loading branch information
evertharmeling and Johan Kasselman authored Feb 5, 2024
1 parent 34d2204 commit 594def5
Show file tree
Hide file tree
Showing 69 changed files with 365 additions and 859 deletions.
147 changes: 80 additions & 67 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,80 +1,93 @@
name: CI

on:
pull_request: ~
push:
branches:
- master
tags:
- '*'
pull_request: ~
push:
branches:
- master
tags:
- '*'

jobs:
coding-style:
name: Coding Style
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@2.9.0
with:
php-version: 7.4
extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo, zlib
coverage: none
coding-style:
name: Coding Style
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo, zlib
coverage: none

- name: Checkout
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3

- name: Install the dependencies
run: composer install --no-interaction --no-suggest
- name: Check the coding style
run: vendor/bin/php-cs-fixer fix --diff --dry-run
- name: Analyze the code
run: vendor/bin/phpstan analyze src/ tests/ --level=max
- name: Install the dependencies
run: composer install --no-interaction

tests:
name: PHP ${{ matrix.php }} / SF ^${{ matrix.symfony }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [7.4, 8.0]
symfony: [4.4, 5.4, 6.0]
exclude:
# Symfony 6.0 does not supports php <8.0
- php: 7.4
symfony: 6.0
steps:
- name: Setup PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php }}
extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib
coverage: none
- name: Check the coding style
run: vendor/bin/php-cs-fixer fix --diff --dry-run

- name: Checkout
uses: actions/checkout@v2
- name: Analyze the code
run: vendor/bin/phpstan analyze

- name: Install the dependencies
run: |
composer require symfony/framework-bundle:^${{ matrix.symfony }} symfony/http-foundation:^${{ matrix.symfony }}
composer install --no-interaction --no-suggest
- name: Run the unit tests
run: vendor/bin/phpunit --colors=always
tests:
name: PHP ${{ matrix.php }} / SF ^${{ matrix.symfony }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [8.0, 8.1, 8.2]
symfony: [5.4, 6.0, 6.1, 6.2, 6.3, 6.4, 7.0]
exclude:
- php: 8.0
symfony: 6.1
- php: 8.0
symfony: 6.2
- php: 8.0
symfony: 6.3
- php: 8.0
symfony: 6.4
- php: 8.0
symfony: 7.0
- php: 8.1
symfony: 7.0
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib
coverage: none

prefer-lowest:
name: Prefer Lowest
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/[email protected]
with:
php-version: 7.4
extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib
coverage: none
- name: Checkout
uses: actions/checkout@v3

- name: Checkout
uses: actions/checkout@v2
- name: Install the dependencies
run: |
composer require symfony/framework-bundle:^${{ matrix.symfony }} symfony/http-foundation:^${{ matrix.symfony }} symfony/yaml:^${{ matrix.symfony }}
composer install --no-interaction --no-suggest
- name: Install the dependencies
run: composer update --prefer-lowest --prefer-stable --no-interaction --no-suggest
- name: Run the unit tests
run: vendor/bin/phpunit --colors=always
- name: Run the unit tests
run: vendor/bin/phpunit --colors=always

prefer-lowest:
name: Prefer Lowest
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib
coverage: none

- name: Checkout
uses: actions/checkout@v3

- name: Install the dependencies
run: composer update --prefer-lowest --prefer-stable --no-interaction

- name: Run the unit tests
run: vendor/bin/phpunit --colors=always
14 changes: 6 additions & 8 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php
use PhpCsFixer\Config;

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests'])
->exclude(['App/cache', 'App/var'])
;

return PhpCsFixer\Config::create()
$config = new Config();
return $config
->setRules([
'@DoctrineAnnotation' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHP80Migration' => true,
'@PHP80Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'align_multiline_comment' => true,
Expand All @@ -21,11 +23,7 @@
],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'general_phpdoc_annotation_remove' => [
'author',
'expectedException',
'expectedExceptionMessage',
],
'general_phpdoc_annotation_remove' => true,
'heredoc_to_nowdoc' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
Expand Down
31 changes: 15 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,32 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"symfony/asset": "^4.4 || ^5.4 || ^6.0",
"php": "^8.0",
"symfony/asset": "^5.4 || ^6.0 || ^7.0",
"symfony/event-dispatcher-contracts": "^1.0 || ^2.0 || ^3.0",
"symfony/finder": "^4.4 || ^5.4 || ^6.0",
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0",
"symfony/mime": "^4.4 || ^5.4 || ^6.0",
"symfony/templating": "^4.4 || ^5.4 || ^6.0",
"symfony/translation": "^4.4 || ^5.4 || ^6.0",
"symfony/finder": "^5.4 || ^6.0 || ^7.0",
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/mime": "^5.4 || ^6.0 || ^7.0",
"symfony/templating": "^5.4 || ^6.0 || ^7.0",
"symfony/translation": "^5.4 || ^6.0 || ^7.0",
"symfony/translation-contracts": "^1.0 || ^2.0 || ^3.0",
"symfony/yaml": "^4.4 || ^5.4 || ^6.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
"twig/twig": "^2.4 || ^3.0"
},
"require-dev": {
"amazonwebservices/aws-sdk-for-php": "1.5.*",
"doctrine/common": "^2.12 || ^3.0",
"doctrine/doctrine-bundle": "^2.4",
"friendsofphp/php-cs-fixer": "^2.16",
"friendsofphp/php-cs-fixer": "^3.40",
"knplabs/gaufrette": "^0.9",
"m2mtech/flysystem-stream-wrapper": "^1.0",
"oneup/flysystem-bundle": "^4.1",
"phpstan/phpstan": "^0.12.10",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.5",
"sensio/framework-extra-bundle": "^5.0 || ^6.0",
"m2mtech/flysystem-stream-wrapper": "^1.0",
"symfony/browser-kit": "^4.4 || ^5.4 || ^6.0",
"symfony/phpunit-bridge": "^5.4",
"symfony/security-bundle": "^4.4 || ^5.4 || ^6.0",
"symfony/var-dumper": "^4.4 || ^5.4 || ^6.0",
"symfony/browser-kit": "^5.4 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^6.0.17 || ^7.0",
"symfony/security-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/var-dumper": "^5.4 || ^6.0 || ^7.0",
"twistor/flysystem-stream-wrapper": "^1.0"
},
"suggest": {
Expand Down
10 changes: 7 additions & 3 deletions doc/custom_uploader.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ namespace Acme\DemoBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Oneup\UploaderBundle\Controller\UploaderController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;use Symfony\Component\HttpFoundation\RequestStack;
class CustomUploader extends UploaderController
{
public function __construct(protected RequestStack $requestStack) {
}
public function upload()
{
// get some basic stuff together
$request = $this->container->get('request_stack')->getMasterRequest();
$request = $this->requestStack->getMainRequest();
$response = new EmptyResponse();
// get file from request (your own logic)
Expand Down Expand Up @@ -100,7 +104,7 @@ class FineUploaderResponse extends AbstractResponse
public function assemble()
{
// explicitly overwrite success and error key
// as these keys are used internaly by the
// as these keys are used internally by the
// frontend uploader
$data = $this->data;
$data['success'] = $this->success;
Expand Down
33 changes: 28 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
parameters:
bootstrapFiles:
- %rootDir%/../../../vendor/autoload.php

excludes_analyse:
level: 9
paths:
- src
- tests
excludePaths:
- src/DependencyInjection/Configuration.php
- tests/App/cache
- tests/App/logs
- tests/App/var
- var
- vendor

checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false

ignoreErrors:
- '#Cannot cast mixed to int\.#'
- '#Cannot call method addListener\(\) on mixed\.#'
- '#Cannot call method getSize\(\) on mixed\.#'
- '#Cannot call method maxSize\(\) on mixed\.#'
- '#Cannot call method getPathname\(\) on mixed\.#'
- '#Cannot call method getPath\(\) on mixed\.#'
- '#Cannot call method getRealPath\(\) on mixed\.#'
- '#Cannot call method getBasename\(\) on mixed\.#'
- '#Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required\.#'
-
message: '#Cannot use array destructuring on array<int, string>\|false\.#'
path: '%currentWorkingDirectory%/src/Controller/BlueimpController.php'
-
message: '#Binary operation "/" between string and int results in an error\.#'
path: '%currentWorkingDirectory%/src/Controller/BlueimpController.php'
-
message: '#Dead catch - Gaufrette\\Exception\\FileNotFound is never thrown in the try block\.#'
path: '%currentWorkingDirectory%/src/Uploader/Chunk/Storage/GaufretteStorage.php'
-
message: '#Parameter \#1 \$finfo of function finfo_file|finfo_close expects finfo, resource given\.#'
path: '%currentWorkingDirectory%/src/Uploader/File/GaufretteFile.php'
-
message: '#Parameter \#2 ...\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.#'
path: '%currentWorkingDirectory%/src/Controller/PluploadController.php'
-
message: '#Parameter \#1 \$parameters of class Symfony\\Component\\HttpFoundation\\FileBag constructor expects array<Symfony\\Component\\HttpFoundation\\File\\UploadedFile>, array<int, Symfony\\Component\\HttpFoundation\\File\\UploadedFile\|null> given\.#'
path: '%currentWorkingDirectory%/tests/Controller/FileBagExtractorTest.php'
6 changes: 4 additions & 2 deletions src/Command/ClearChunkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
namespace Oneup\UploaderBundle\Command;

use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'oneup:uploader:clear-chunks'
)]
class ClearChunkCommand extends Command
{
protected static $defaultName = 'oneup:uploader:clear-chunks'; // Make command lazy load

/**
* @var ChunkManager
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Command/ClearOrphansCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
namespace Oneup\UploaderBundle\Command;

use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'oneup:uploader:clear-orphans'
)]
class ClearOrphansCommand extends Command
{
protected static $defaultName = 'oneup:uploader:clear-orphans';
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/AbstractChunkedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Oneup\UploaderBundle\Event\PostChunkUploadEvent;
use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;

Expand Down Expand Up @@ -70,7 +71,10 @@ protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $re
// with reassembling the parts
if ($last) {
$path = $assembled->getPath();
$this->handleUpload($assembled, $response, $request);
if ($assembled instanceof File) {
$this->handleUpload($assembled, $response, $request);
}
// @todo $assembled is of type mixed, so would error without check

$chunkManager->cleanup($path);
}
Expand Down
Loading

0 comments on commit 594def5

Please sign in to comment.