Skip to content

Commit 98d8ab4

Browse files
committed
Symfony 5 adaptation
1 parent d37b2ab commit 98d8ab4

File tree

143 files changed

+657
-1353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+657
-1353
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/var
12
/vendor
23
composer.lock
34
.phpcs-cache

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ matrix:
1919
env:
2020
- COMPOSER_FLAGS='--prefer-lowest'
2121
- php: 7.4
22+
- php: 8.0
2223

2324
before_install:
2425
- phpenv config-rm xdebug.ini

Admin/CRUD/Context/BatchElementContext.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
namespace FSi\Bundle\AdminBundle\Admin\CRUD\Context;
1313

1414
use FSi\Bundle\AdminBundle\Admin\Context\ContextAbstract;
15+
use FSi\Bundle\AdminBundle\Admin\Context\Request\HandlerInterface;
1516
use FSi\Bundle\AdminBundle\Admin\CRUD\BatchElement;
16-
use FSi\Bundle\AdminBundle\Admin\CRUD\FormElement;
1717
use FSi\Bundle\AdminBundle\Admin\Element;
1818
use FSi\Bundle\AdminBundle\Event\AdminEvent;
1919
use FSi\Bundle\AdminBundle\Event\FormEvent;
2020
use FSi\Bundle\AdminBundle\Exception\InvalidArgumentException;
2121
use Symfony\Component\Form\FormInterface;
2222
use Symfony\Component\Form\FormBuilderInterface;
23-
use Symfony\Component\Form\RequestHandlerInterface;
2423
use Symfony\Component\HttpFoundation\Request;
2524

2625
class BatchElementContext extends ContextAbstract
@@ -41,10 +40,10 @@ class BatchElementContext extends ContextAbstract
4140
protected $indexes;
4241

4342
/**
44-
* @param array<RequestHandlerInterface> $requestHandlers
43+
* @param iterable<HandlerInterface> $requestHandlers
4544
* @param FormBuilderInterface $formBuilder
4645
*/
47-
public function __construct(array $requestHandlers, FormBuilderInterface $formBuilder)
46+
public function __construct(iterable $requestHandlers, FormBuilderInterface $formBuilder)
4847
{
4948
parent::__construct($requestHandlers);
5049
$this->form = $formBuilder->getForm();

Admin/CRUD/Context/DeleteElementContext.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
class DeleteElementContext extends BatchElementContext
1818
{
19+
public static function getPriority(): int
20+
{
21+
return 10;
22+
}
23+
1924
protected function supportsElement(Element $element): bool
2025
{
2126
return $element instanceof DeleteElement;

Admin/CRUD/Context/Request/BatchFormValidRequestHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected function action(FormEvent $event, Request $request): void
6060

6161
foreach ($objects as $object) {
6262
$preEvent = new BatchPreApplyEvent($element, $request, $object);
63-
$this->eventDispatcher->dispatch(BatchEvents::BATCH_OBJECT_PRE_APPLY, $preEvent);
63+
$this->eventDispatcher->dispatch($preEvent, BatchEvents::BATCH_OBJECT_PRE_APPLY);
6464

6565
if (true === $preEvent->shouldSkip()) {
6666
continue;
@@ -69,8 +69,8 @@ protected function action(FormEvent $event, Request $request): void
6969
$element->apply($object);
7070

7171
$this->eventDispatcher->dispatch(
72-
BatchEvents::BATCH_OBJECT_POST_APPLY,
73-
new BatchEvent($element, $request, $object)
72+
new BatchEvent($element, $request, $object),
73+
BatchEvents::BATCH_OBJECT_POST_APPLY
7474
);
7575
}
7676
}

Admin/CRUD/Context/Request/DataGridBindDataHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public function handleRequest(AdminEvent $event, Request $request): ?Response
2727
$event = $this->validateEvent($event);
2828

2929
if (true === $request->isMethod(Request::METHOD_POST)) {
30-
$this->eventDispatcher->dispatch(ListEvents::LIST_DATAGRID_REQUEST_PRE_BIND, $event);
30+
$this->eventDispatcher->dispatch($event, ListEvents::LIST_DATAGRID_REQUEST_PRE_BIND);
3131
if ($event->hasResponse()) {
3232
return $event->getResponse();
3333
}
3434

3535
$event->getDataGrid()->bindData($request);
36-
$this->eventDispatcher->dispatch(ListEvents::LIST_DATAGRID_REQUEST_POST_BIND, $event);
36+
$this->eventDispatcher->dispatch($event, ListEvents::LIST_DATAGRID_REQUEST_POST_BIND);
3737
if ($event->hasResponse()) {
3838
return $event->getResponse();
3939
}
@@ -45,8 +45,8 @@ public function handleRequest(AdminEvent $event, Request $request): ?Response
4545
$event->getDataGrid()->setData($event->getDataSource()->getResult());
4646
}
4747

48-
$this->eventDispatcher->dispatch(ListEvents::LIST_RESPONSE_PRE_RENDER, $event);
49-
if (true === $event->hasResponse()) {
48+
$this->eventDispatcher->dispatch($event, ListEvents::LIST_RESPONSE_PRE_RENDER);
49+
if ($event->hasResponse()) {
5050
return $event->getResponse();
5151
}
5252

Admin/CRUD/Context/Request/DataGridSetDataHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public function handleRequest(AdminEvent $event, Request $request): ?Response
2525
{
2626
$event = $this->validateEvent($event);
2727

28-
$this->eventDispatcher->dispatch(ListEvents::LIST_DATAGRID_DATA_PRE_BIND, $event);
28+
$this->eventDispatcher->dispatch($event, ListEvents::LIST_DATAGRID_DATA_PRE_BIND);
2929
if ($event->hasResponse()) {
3030
return $event->getResponse();
3131
}
3232

3333
$event->getDataGrid()->setData($event->getDataSource()->getResult());
34-
$this->eventDispatcher->dispatch(ListEvents::LIST_DATAGRID_DATA_POST_BIND, $event);
34+
$this->eventDispatcher->dispatch($event, ListEvents::LIST_DATAGRID_DATA_POST_BIND);
3535

3636
if ($event->hasResponse()) {
3737
return $event->getResponse();

Admin/CRUD/Context/Request/DataSourceBindParametersHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public function handleRequest(AdminEvent $event, Request $request): ?Response
2929
return $event->getResponse();
3030
}
3131

32-
$this->eventDispatcher->dispatch(ListEvents::LIST_DATASOURCE_REQUEST_PRE_BIND, $event);
32+
$this->eventDispatcher->dispatch($event, ListEvents::LIST_DATASOURCE_REQUEST_PRE_BIND);
3333
if ($event->hasResponse()) {
3434
return $event->getResponse();
3535
}
3636

3737
$event->getDataSource()->bindParameters($request);
3838

39-
$this->eventDispatcher->dispatch(ListEvents::LIST_DATASOURCE_REQUEST_POST_BIND, $event);
39+
$this->eventDispatcher->dispatch($event, ListEvents::LIST_DATASOURCE_REQUEST_POST_BIND);
4040
if ($event->hasResponse()) {
4141
return $event->getResponse();
4242
}

Admin/CRUD/Context/Request/DeleteRequestHandler.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616
use FSi\Bundle\AdminBundle\Admin\RedirectableElement;
1717
use FSi\Bundle\AdminBundle\Event\AdminEvent;
1818
use FSi\Bundle\AdminBundle\Event\FormEvent;
19+
use FSi\Bundle\AdminBundle\Exception\InvalidArgumentException;
1920
use FSi\Bundle\AdminBundle\Message\FlashMessages;
2021
use LogicException;
2122
use Symfony\Component\HttpFoundation\RedirectResponse;
2223
use Symfony\Component\HttpFoundation\Request;
2324
use Symfony\Component\HttpFoundation\Response;
2425
use Symfony\Component\Routing\RouterInterface;
2526

27+
use function get_class;
28+
2629
class DeleteRequestHandler implements HandlerInterface
2730
{
2831
/**
29-
* @var HandlerInterface
32+
* @var BatchFormValidRequestHandler
3033
*/
3134
private $batchHandler;
3235

@@ -41,7 +44,7 @@ class DeleteRequestHandler implements HandlerInterface
4144
private $router;
4245

4346
public function __construct(
44-
HandlerInterface $batchHandler,
47+
BatchFormValidRequestHandler $batchHandler,
4548
FlashMessages $flashMessages,
4649
RouterInterface $router
4750
) {
@@ -52,6 +55,9 @@ public function __construct(
5255

5356
public function handleRequest(AdminEvent $event, Request $request): ?Response
5457
{
58+
if (false === $event instanceof FormEvent) {
59+
throw InvalidArgumentException::create(self::class, FormEvent::class, get_class($event));
60+
}
5561
try {
5662
$this->validateDeletion($event);
5763
$response = $this->batchHandler->handleRequest($event, $request);

Admin/CRUD/Context/Request/FormValidRequestHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public function handleRequest(AdminEvent $event, Request $request): ?Response
4545
return $response;
4646
}
4747

48-
$this->eventDispatcher->dispatch(FormEvents::FORM_RESPONSE_PRE_RENDER, $event);
49-
if (true === $event->hasResponse()) {
48+
$this->eventDispatcher->dispatch($event, FormEvents::FORM_RESPONSE_PRE_RENDER);
49+
if ($event->hasResponse()) {
5050
return $event->getResponse();
5151
}
5252

Admin/Context/ContextAbstract.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ abstract class ContextAbstract implements ContextInterface
2929
*/
3030
private $template;
3131

32+
public static function getPriority(): int
33+
{
34+
return 0;
35+
}
36+
3237
/**
33-
* @param array<HandlerInterface> $requestHandlers
38+
* @param iterable<HandlerInterface> $requestHandlers
3439
* @param string|null $template
3540
*/
36-
public function __construct(array $requestHandlers, ?string $template = null)
41+
public function __construct(iterable $requestHandlers, ?string $template = null)
3742
{
3843
$this->requestHandlers = $requestHandlers;
3944
$this->template = $template;

Admin/Context/ContextInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
interface ContextInterface
1919
{
20+
public static function getPriority(): int;
21+
2022
public function supports(string $route, Element $element): bool;
2123

2224
public function setElement(Element $element): void;

Admin/Context/ContextManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class ContextManager
2121
protected $contexts;
2222

2323
/**
24-
* @param array<ContextInterface> $contexts
24+
* @param iterable<ContextInterface> $contexts
2525
*/
26-
public function __construct(array $contexts = [])
26+
public function __construct(iterable $contexts)
2727
{
2828
$this->contexts = [];
2929

Admin/Context/Request/AbstractFormSubmitHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public function handleRequest(AdminEvent $event, Request $request): ?Response
2727
return null;
2828
}
2929

30-
$this->eventDispatcher->dispatch($this->getPreSubmitEventName(), $event);
30+
$this->eventDispatcher->dispatch($event, $this->getPreSubmitEventName());
3131
if ($event->hasResponse()) {
3232
return $event->getResponse();
3333
}
3434

3535
$event->getForm()->handleRequest($request);
3636

37-
$this->eventDispatcher->dispatch($this->getPostSubmitEventName(), $event);
37+
$this->eventDispatcher->dispatch($event, $this->getPostSubmitEventName());
3838
if ($event->hasResponse()) {
3939
return $event->getResponse();
4040
}

Admin/Context/Request/AbstractFormValidRequestHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public function handleRequest(AdminEvent $event, Request $request): ?Response
4242
return null;
4343
}
4444

45-
$this->eventDispatcher->dispatch($this->getPreSaveEventName(), $event);
45+
$this->eventDispatcher->dispatch($event, $this->getPreSaveEventName());
4646
if ($event->hasResponse()) {
4747
return $event->getResponse();
4848
}
4949

5050
$this->action($event, $request);
5151

52-
$this->eventDispatcher->dispatch($this->getPostSaveEventName(), $event);
52+
$this->eventDispatcher->dispatch($event, $this->getPostSaveEventName());
5353
if ($event->hasResponse()) {
5454
return $event->getResponse();
5555
}

Admin/Display/Context/Request/Handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function handleRequest(AdminEvent $event, Request $request): ?Response
3333
throw new RequestHandlerException(sprintf('%s requires DisplayEvent', get_class($this)));
3434
}
3535

36-
$this->eventDispatcher->dispatch(DisplayEvents::DISPLAY_PRE_RENDER, $event);
37-
if (true === $event->hasResponse()) {
36+
$this->eventDispatcher->dispatch($event, DisplayEvents::DISPLAY_PRE_RENDER);
37+
if ($event->hasResponse()) {
3838
return $event->getResponse();
3939
}
4040

Admin/Manager.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ class Manager implements ManagerInterface
2020
*/
2121
protected $elements;
2222

23-
public function __construct()
23+
/**
24+
* @param iterable<Visitor> $visitors
25+
*/
26+
public function __construct(iterable $visitors)
2427
{
2528
$this->elements = [];
29+
foreach ($visitors as $visitor) {
30+
$visitor->visitManager($this);
31+
}
2632
}
2733

2834
public function addElement(Element $element): void
@@ -49,9 +55,4 @@ public function getElements(): array
4955
{
5056
return $this->elements;
5157
}
52-
53-
public function accept(Visitor $visitor): void
54-
{
55-
$visitor->visitManager($this);
56-
}
5758
}

Admin/Manager/DependentElementsVisitor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
class DependentElementsVisitor implements Visitor
1818
{
19+
public static function getPriority(): int
20+
{
21+
return 0;
22+
}
23+
1924
public function visitManager(ManagerInterface $manager): void
2025
{
2126
foreach ($manager->getElements() as $element) {

Admin/Manager/ElementCollectionVisitor.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class ElementCollectionVisitor implements Visitor
1919
{
2020
/**
21-
* @var array<Element>
21+
* @var iterable<Element>
2222
*/
2323
private $elements;
2424

@@ -27,11 +27,16 @@ class ElementCollectionVisitor implements Visitor
2727
*/
2828
private $factoryProductionLine;
2929

30+
public static function getPriority(): int
31+
{
32+
return 1024;
33+
}
34+
3035
/**
31-
* @param array<Element> $elements
36+
* @param iterable<Element> $elements
3237
* @param ProductionLine $factoryProductionLine
3338
*/
34-
public function __construct(array $elements, ProductionLine $factoryProductionLine)
39+
public function __construct(iterable $elements, ProductionLine $factoryProductionLine)
3540
{
3641
$this->elements = $elements;
3742
$this->factoryProductionLine = $factoryProductionLine;

Admin/Manager/Visitor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515

1616
interface Visitor
1717
{
18+
public static function getPriority(): int;
1819
public function visitManager(ManagerInterface $manager): void;
1920
}

Admin/ManagerInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,4 @@ public function removeElement(string $id): void;
2727
* @return array<Element>
2828
*/
2929
public function getElements(): array;
30-
31-
public function accept(Visitor $visitor): void;
3230
}

Admin/ResourceRepository/Context/Request/FormValidRequestHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function handleRequest(AdminEvent $event, Request $request): ?Response
5656
return $response;
5757
}
5858

59-
$this->eventDispatcher->dispatch(FormEvents::FORM_RESPONSE_PRE_RENDER, $event);
60-
if (true === $event->hasResponse()) {
59+
$this->eventDispatcher->dispatch($event, FormEvents::FORM_RESPONSE_PRE_RENDER);
60+
if ($event->hasResponse()) {
6161
return $event->getResponse();
6262
}
6363

Admin/ResourceRepository/Context/ResourceRepositoryContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ class ResourceRepositoryContext extends ContextAbstract
4242
private $form;
4343

4444
/**
45-
* @param array<HandlerInterface> $requestHandlers
45+
* @param iterable<HandlerInterface> $requestHandlers
4646
* @param string $template
4747
* @param ResourceFormBuilder $resourceFormBuilder
4848
*/
4949
public function __construct(
50-
array $requestHandlers,
50+
iterable $requestHandlers,
5151
string $template,
5252
ResourceFormBuilder $resourceFormBuilder
5353
) {

Behat/Context/AdminContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,6 @@ public function castWordToNumber(string $word): int
173173

174174
private function getAdminManager(): ManagerInterface
175175
{
176-
return $this->getContainer()->get('test.admin.manager');
176+
return $this->getContainer()->get(sprintf('test.%s', ManagerInterface::class));
177177
}
178178
}

Behat/Context/DataContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function createDatabase(): void
5454
*/
5555
public function deleteDatabaseIfExist(): void
5656
{
57-
$dbFilePath = $this->getKernel()->getRootDir() . '/data.sqlite';
57+
$dbFilePath = $this->getKernel()->getProjectDir() . '/var/data.sqlite';
5858
if (true === file_exists($dbFilePath)) {
5959
unlink($dbFilePath);
6060
}

0 commit comments

Comments
 (0)