Skip to content

Commit

Permalink
1. Implemented the AsCommand attributes for final $defaultName
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Johan Kasselman committed Aug 4, 2023
1 parent 34d2204 commit eb0cdf7
Show file tree
Hide file tree
Showing 30 changed files with 118 additions and 460 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"symfony/asset": "^4.4 || ^5.4 || ^6.0",
"symfony/event-dispatcher-contracts": "^1.0 || ^2.0 || ^3.0",
"symfony/finder": "^4.4 || ^5.4 || ^6.0",
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
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
36 changes: 2 additions & 34 deletions src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,8 @@

abstract class AbstractController
{
/**
* @var ErrorHandlerInterface
*/
protected $errorHandler;

/**
* @var ContainerInterface
*/
protected $container;

/**
* @var StorageInterface
*/
protected $storage;

/**
* @var array
*/
protected $config;

/**
* @var string
*/
protected $type;

public function __construct(ContainerInterface $container, StorageInterface $storage, ErrorHandlerInterface $errorHandler, array $config, string $type)
public function __construct(protected ContainerInterface $container, protected StorageInterface $storage, protected ErrorHandlerInterface $errorHandler, protected array $config, protected string $type)
{
$this->errorHandler = $errorHandler;
$this->container = $container;
$this->storage = $storage;
$this->config = $config;
$this->type = $type;
}

abstract public function upload(): JsonResponse;
Expand Down Expand Up @@ -223,9 +193,7 @@ protected function getRequest(): Request
$requestStack = $this->container->get('request_stack');

/** @var Request $request */
$request = method_exists($requestStack, 'getMainRequest')
? $requestStack->getMainRequest()
: $requestStack->getMasterRequest();
$request = $requestStack->getMainRequest();

return $request;
}
Expand Down
46 changes: 7 additions & 39 deletions src/Event/PostChunkUploadEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,21 @@ class PostChunkUploadEvent extends Event
{
public const NAME = UploadEvents::POST_CHUNK_UPLOAD;

/**
* @var mixed
*/
protected $chunk;

/**
* @var Request
*/
protected $request;

/**
* @var string
*/
protected $type;

/**
* @var ResponseInterface
*/
protected $response;

/**
* @var array
*/
protected $config;

/**
* @var bool
*/
protected $isLast;

/**
* @param mixed $chunk
* @param ResponseInterface $response
* @param Request $request
* @param bool $isLast
* @param string $type
* @param array $config
*/
public function __construct($chunk, ResponseInterface $response, Request $request, bool $isLast, string $type, array $config)
{
$this->chunk = $chunk;
$this->request = $request;
$this->response = $response;
$this->isLast = $isLast;
$this->type = $type;
$this->config = $config;
public function __construct(protected mixed $chunk, protected ResponseInterface $response, protected Request $request, protected bool $isLast, protected string $type, protected array $config) {
}

/**
* @return mixed
*/
public function getChunk()
public function getChunk(): mixed
{
return $this->chunk;
}
Expand Down
37 changes: 5 additions & 32 deletions src/Event/PostPersistEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,14 @@ class PostPersistEvent extends Event
{
public const NAME = UploadEvents::POST_PERSIST;

/**
* @var FileInterface|File
*/
protected $file;

/**
* @var Request
*/
protected $request;

/**
* @var string
*/
protected $type;

/**
* @var ResponseInterface
*/
protected $response;

/**
* @var array
*/
protected $config;

/**
* @param FileInterface|File $file
* @param ResponseInterface $response
* @param Request $request
* @param string $type
* @param array $config
*/
public function __construct($file, ResponseInterface $response, Request $request, string $type, array $config)
{
$this->file = $file;
$this->request = $request;
$this->response = $response;
$this->type = $type;
$this->config = $config;
public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) {
}

/**
Expand Down
37 changes: 5 additions & 32 deletions src/Event/PostUploadEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,14 @@ class PostUploadEvent extends Event
{
public const NAME = UploadEvents::POST_UPLOAD;

/**
* @var FileInterface|File
*/
protected $file;

/**
* @var Request
*/
protected $request;

/**
* @var string
*/
protected $type;

/**
* @var ResponseInterface
*/
protected $response;

/**
* @var array
*/
protected $config;

/**
* @param FileInterface|File $file
* @param ResponseInterface $response
* @param Request $request
* @param string $type
* @param array $config
*/
public function __construct($file, ResponseInterface $response, Request $request, string $type, array $config)
{
$this->file = $file;
$this->request = $request;
$this->response = $response;
$this->type = $type;
$this->config = $config;
public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) {
}

/**
Expand Down
39 changes: 6 additions & 33 deletions src/Event/PreUploadEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,13 @@ class PreUploadEvent extends Event
public const NAME = UploadEvents::PRE_UPLOAD;

/**
* @var FileInterface|File
* @param File|FileInterface $file
* @param ResponseInterface $response
* @param Request $request
* @param string $type
* @param array $config
*/
protected $file;

/**
* @var Request
*/
protected $request;

/**
* @var string
*/
protected $type;

/**
* @var ResponseInterface
*/
protected $response;

/**
* @var array
*/
protected $config;

/**
* @param FileInterface|File $file
*/
public function __construct($file, ResponseInterface $response, Request $request, string $type, array $config)
{
$this->file = $file;
$this->request = $request;
$this->response = $response;
$this->type = $type;
$this->config = $config;
public function __construct(protected File|FileInterface $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) {
}

/**
Expand Down
37 changes: 5 additions & 32 deletions src/Event/ValidationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,14 @@ class ValidationEvent extends Event
{
public const NAME = UploadEvents::VALIDATION;

/**
* @var FileInterface|File
*/
protected $file;

/**
* @var array
*/
protected $config;

/**
* @var string
*/
protected $type;

/**
* @var Request
*/
protected $request;

/**
* @var ResponseInterface|null
*/
protected $response;

/**
* @param FileInterface|File $file
* @param Request $request
* @param array $config
* @param string $type
* @param ResponseInterface|null $response
*/
public function __construct($file, Request $request, array $config, string $type, ResponseInterface $response = null)
{
$this->file = $file;
$this->config = $config;
$this->type = $type;
$this->request = $request;
$this->response = $response;
public function __construct(protected FileInterface|File $file, protected Request $request, protected array $config, protected string $type, protected ?ResponseInterface $response = null) {
}

/**
Expand Down
9 changes: 2 additions & 7 deletions src/Routing/RouteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@

class RouteLoader extends Loader
{
/**
* @var array
*/
protected $controllers;

public function __construct(array $controllers)
{
$this->controllers = $controllers;
public function __construct(protected array $controllers) {
parent::__construct();
}

/**
Expand Down
Loading

0 comments on commit eb0cdf7

Please sign in to comment.