Skip to content

Commit 89b12ae

Browse files
pszewczykplPiotr Szewczyk
and
Piotr Szewczyk
authored
Feature: Supports Symfony ^6.0 and ^7.0 (#84)
* build(composer): PHP version up * build(composer): Symfony version up to 7.0 * fix(php): Typing improved * fix(symfony): Fixed deprecations (added AsCommand instead consts) * fix(transformers): Added required TransformerInterface use statement * fix(event): Added nullable Request * chore(readme): Updated Parameter entity in README.md * fix(symfony): Added void return types * feat(symfony): Disabled Symfony 5 and PHP 7 support * fix(parameter): Fixes for non required parameters --------- Co-authored-by: Piotr Szewczyk <[email protected]>
1 parent d711a5b commit 89b12ae

Some content is hidden

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

43 files changed

+195
-716
lines changed

.circleci/config.yml

-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ common: &common
1111

1212

1313
jobs:
14-
test74:
15-
docker:
16-
- image: cimg/php:7.4
17-
<<: *common
1814
test80:
1915
docker:
2016
- image: cimg/php:8.0
@@ -27,6 +23,5 @@ workflows:
2723
version: 2
2824
build:
2925
jobs:
30-
- test74
3126
- test80
3227
- test81

Command/ExportCommand.php

+7-15
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@
33
namespace Sherlockode\ConfigurationBundle\Command;
44

55
use Sherlockode\ConfigurationBundle\Manager\ExportManagerInterface;
6+
use Symfony\Component\Console\Attribute\AsCommand;
67
use Symfony\Component\Console\Command\Command;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
910
use Symfony\Component\Console\Style\SymfonyStyle;
1011
use Symfony\Component\HttpKernel\Kernel;
1112

13+
#[AsCommand(
14+
name: 'sherlockode:configuration:export',
15+
description: 'Export configuration parameters to the vault.'
16+
)]
1217
class ExportCommand extends Command
1318
{
14-
protected static $defaultName = 'sherlockode:configuration:export';
15-
protected static $defaultDescription = 'Export configuration parameters to the vault';
19+
private ExportManagerInterface $exportManager;
1620

17-
/**
18-
* @var ExportManagerInterface
19-
*/
20-
private $exportManager;
21-
22-
/**
23-
* @param ExportManagerInterface $exportManager
24-
*/
2521
public function __construct(ExportManagerInterface $exportManager)
2622
{
2723
parent::__construct();
@@ -35,10 +31,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3531
$this->exportManager->exportInVault();
3632
$io->success('Configuration successfully sealed in vault');
3733

38-
if (Kernel::VERSION_ID >= 50100) {
39-
return Command::SUCCESS;
40-
}
41-
42-
return 0;
34+
return Command::SUCCESS;
4335
}
4436
}

Command/ImportCommand.php

+7-15
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@
33
namespace Sherlockode\ConfigurationBundle\Command;
44

55
use Sherlockode\ConfigurationBundle\Manager\ImportManagerInterface;
6+
use Symfony\Component\Console\Attribute\AsCommand;
67
use Symfony\Component\Console\Command\Command;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
910
use Symfony\Component\Console\Style\SymfonyStyle;
1011
use Symfony\Component\HttpKernel\Kernel;
1112

13+
#[AsCommand(
14+
name: 'sherlockode:configuration:import',
15+
description: 'Import configuration parameters from the vault.'
16+
)]
1217
class ImportCommand extends Command
1318
{
14-
protected static $defaultName = 'sherlockode:configuration:import';
15-
protected static $defaultDescription = 'Import configuration parameters from the vault';
19+
private ImportManagerInterface $importManager;
1620

17-
/**
18-
* @var ImportManagerInterface
19-
*/
20-
private $importManager;
21-
22-
/**
23-
* @param ImportManagerInterface $importManager
24-
*/
2521
public function __construct(ImportManagerInterface $importManager)
2622
{
2723
parent::__construct();
@@ -35,10 +31,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3531
$this->importManager->importFromVault();
3632
$io->success('Configuration successfully imported from vault');
3733

38-
if (Kernel::VERSION_ID >= 50100) {
39-
return Command::SUCCESS;
40-
}
41-
42-
return 0;
34+
return Command::SUCCESS;
4335
}
4436
}

Controller/ParameterController.php

+11-67
Original file line numberDiff line numberDiff line change
@@ -29,75 +29,30 @@
2929
*/
3030
class ParameterController
3131
{
32-
/**
33-
* @var ParameterManagerInterface
34-
*/
35-
private $parameterManager;
32+
private ParameterManagerInterface $parameterManager;
3633

37-
/**
38-
* @var ExportManagerInterface
39-
*/
40-
private $exportManager;
34+
private ExportManagerInterface $exportManager;
4135

42-
/**
43-
* @var ImportManagerInterface
44-
*/
45-
private $importManager;
36+
private ImportManagerInterface $importManager;
4637

47-
/**
48-
* @var RequestStack
49-
*/
50-
private $requestStack;
38+
private RequestStack $requestStack;
5139

52-
/**
53-
* @var FormFactoryInterface
54-
*/
55-
private $formFactory;
40+
private FormFactoryInterface $formFactory;
5641

57-
/**
58-
* @var EventDispatcherInterface
59-
*/
60-
private $eventDispatcher;
42+
private EventDispatcherInterface $eventDispatcher;
6143

62-
/**
63-
* @var UrlGeneratorInterface
64-
*/
65-
private $urlGenerator;
44+
private UrlGeneratorInterface $urlGenerator;
6645

67-
/**
68-
* @var Environment
69-
*/
70-
private $twig;
46+
private Environment $twig;
7147

72-
/**
73-
* @var string
74-
*/
75-
private $editFormTemplate;
48+
private string $editFormTemplate;
7649

77-
/**
78-
* @var string
79-
*/
80-
private $importFormTemplate;
50+
private string $importFormTemplate;
8151

82-
/**
83-
* @var string
84-
*/
85-
private $redirectAfterImportRoute;
52+
private string $redirectAfterImportRoute;
8653

8754
/**
8855
* ParameterController constructor.
89-
*
90-
* @param ParameterManagerInterface $parameterManager
91-
* @param ExportManagerInterface $exportManager
92-
* @param ImportManagerInterface $importManager
93-
* @param EventDispatcherInterface $eventDispatcher
94-
* @param RequestStack $requestStack
95-
* @param FormFactoryInterface $formFactory
96-
* @param UrlGeneratorInterface $urlGenerator
97-
* @param Environment $twig
98-
* @param string $editFormTemplate
99-
* @param string $importFormTemplate
100-
* @param string $redirectAfterImportRoute
10156
*/
10257
public function __construct(
10358
ParameterManagerInterface $parameterManager,
@@ -126,10 +81,6 @@ public function __construct(
12681
}
12782

12883
/**
129-
* @param Request $request
130-
*
131-
* @return Response
132-
*
13384
* @throws LoaderError
13485
* @throws RuntimeError
13586
* @throws SyntaxError
@@ -171,9 +122,6 @@ public function listAction(Request $request): Response
171122
]));
172123
}
173124

174-
/**
175-
* @return Response
176-
*/
177125
public function exportAction(): Response
178126
{
179127
$response = new Response($this->exportManager->exportAsString());
@@ -187,10 +135,6 @@ public function exportAction(): Response
187135
}
188136

189137
/**
190-
* @param Request $request
191-
*
192-
* @return Response
193-
*
194138
* @throws LoaderError
195139
* @throws RuntimeError
196140
* @throws SyntaxError

DependencyInjection/Compiler/FieldTypePass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class FieldTypePass implements CompilerPassInterface
1010
{
11-
public function process(ContainerBuilder $container)
11+
public function process(ContainerBuilder $container): void
1212
{
1313
if (!class_exists('Doctrine\\ORM\\EntityManager')) {
1414
$container->removeDefinition('sherlockode_configuration.field.entity');

DependencyInjection/SherlockodeConfigurationExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class SherlockodeConfigurationExtension extends Extension
1212
{
13-
public function load(array $configs, ContainerBuilder $container)
13+
public function load(array $configs, ContainerBuilder $container): void
1414
{
1515
$configuration = new Configuration();
1616
$config = $this->processConfiguration($configuration, $configs);

Event/PostSaveEvent.php

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ class PostSaveEvent
99
use ResponseEventTrait;
1010
use RequestEventTrait;
1111

12-
/**
13-
* @param Request $request
14-
*/
1512
public function __construct(Request $request)
1613
{
1714
$this->request = $request;

Event/PreSaveEvent.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,15 @@ class PreSaveEvent
99
use ResponseEventTrait;
1010
use RequestEventTrait;
1111

12-
/**
13-
* @var array
14-
*/
15-
private $parameters;
12+
private array $parameters;
1613

17-
/**
18-
* @param array $parameters
19-
*/
20-
public function __construct(Request $request, $parameters)
14+
public function __construct(Request $request, array $parameters)
2115
{
2216
$this->request = $request;
2317
$this->parameters = $parameters;
2418
}
2519

26-
/**
27-
* @return array
28-
*/
29-
public function getParameters()
20+
public function getParameters(): array
3021
{
3122
return $this->parameters;
3223
}

Event/RequestEventTrait.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@
66

77
trait RequestEventTrait
88
{
9-
/**
10-
* @var Request
11-
*/
12-
private $request;
9+
private ?Request $request = null;
1310

14-
/**
15-
* @return Request
16-
*/
17-
public function getRequest()
11+
public function getRequest(): ?Request
1812
{
1913
return $this->request;
2014
}

Event/ResponseEventTrait.php

+3-14
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,14 @@
66

77
trait ResponseEventTrait
88
{
9-
/**
10-
* @var Response
11-
*/
12-
private $response;
9+
private ?Response $response = null;
1310

14-
/**
15-
* @return Response
16-
*/
17-
public function getResponse()
11+
public function getResponse(): ?Response
1812
{
1913
return $this->response;
2014
}
2115

22-
/**
23-
* @param Response $response
24-
*
25-
* @return $this
26-
*/
27-
public function setResponse(Response $response)
16+
public function setResponse(?Response $response): self
2817
{
2918
$this->response = $response;
3019

FieldType/AbstractField.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,12 @@
77

88
abstract class AbstractField implements FieldTypeInterface
99
{
10-
/**
11-
* @param ParameterDefinition $definition
12-
*
13-
* @return array
14-
*/
15-
public function getFormOptions(ParameterDefinition $definition)
10+
public function getFormOptions(ParameterDefinition $definition): array
1611
{
1712
return [];
1813
}
1914

20-
/**
21-
* @param ParameterDefinition $definition
22-
*
23-
* @return TransformerInterface
24-
*/
25-
public function getModelTransformer(ParameterDefinition $definition)
15+
public function getModelTransformer(ParameterDefinition $definition): ?TransformerInterface
2616
{
2717
return null;
2818
}

FieldType/CheckboxField.php

+4-12
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,24 @@
99

1010
class CheckboxField extends AbstractField
1111
{
12-
/**
13-
* @return string
14-
*/
15-
public function getFormType(ParameterDefinition $definition)
12+
public function getFormType(ParameterDefinition $definition): string
1613
{
1714
return CheckboxType::class;
1815
}
1916

20-
public function getFormOptions(ParameterDefinition $definition)
17+
public function getFormOptions(ParameterDefinition $definition): array
2118
{
2219
return [
2320
'required' => $definition->getOption('required', false),
2421
];
2522
}
2623

27-
public function getName()
24+
public function getName(): string
2825
{
2926
return 'checkbox';
3027
}
3128

32-
/**
33-
* @param ParameterDefinition $definition
34-
*
35-
* @return TransformerInterface
36-
*/
37-
public function getModelTransformer(ParameterDefinition $definition)
29+
public function getModelTransformer(ParameterDefinition $definition): ?TransformerInterface
3830
{
3931
return new BooleanTransformer();
4032
}

0 commit comments

Comments
 (0)