Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility for Symfony 6 #329

Merged
merged 28 commits into from
Jul 15, 2022
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7e4277b
Add compatibility for Symfony 6
alexander-schranz Jul 14, 2022
0718841
Check for swiftmailer to disable swiftmailer emails for tests
alexander-schranz Jul 14, 2022
9bfab2d
Update symfony translation package
alexander-schranz Jul 14, 2022
46a0d9b
Missing void return type
alexander-schranz Jul 14, 2022
399f168
Move lint to an own task
alexander-schranz Jul 14, 2022
b8e9f0c
Update configuration deprecation
alexander-schranz Jul 14, 2022
2314ef2
Update service deprecation
alexander-schranz Jul 14, 2022
76b94d8
Fix compatibility
alexander-schranz Jul 14, 2022
6344c5d
Use password hasher for checksum
alexander-schranz Jul 14, 2022
e6352a6
Check for isMasterRequest
alexander-schranz Jul 14, 2022
aee1fdd
Check for getMasterRequest
alexander-schranz Jul 14, 2022
43258fe
Fix compatibility of DisabledCsrfTokenManager
alexander-schranz Jul 14, 2022
268dcd0
Skip Swiftmailer test when not installed
alexander-schranz Jul 14, 2022
5990615
Fix composer json duplicated entry
alexander-schranz Jul 14, 2022
88699eb
Check if has swiftmailer
alexander-schranz Jul 14, 2022
be8aeb6
Require latest version of dantleech/phpcr-migrations-bundle to fix lo…
alexander-schranz Jul 14, 2022
631a03d
Fix lowest dependency configuraiton
alexander-schranz Jul 14, 2022
36a721e
Fix compatibility
alexander-schranz Jul 14, 2022
58f0349
Upgrade baseline
alexander-schranz Jul 14, 2022
98603dc
Fix code style
alexander-schranz Jul 14, 2022
4fa60c5
Fix lowest tests
alexander-schranz Jul 14, 2022
a879a46
Set requirement for symfony-dependency-injeciton package
alexander-schranz Jul 14, 2022
3965eaf
Move deprecation of service to php
alexander-schranz Jul 14, 2022
0827b1a
Add deprecation bridge
alexander-schranz Jul 14, 2022
49b7961
Upgrade baseline
alexander-schranz Jul 14, 2022
3042ada
Fix code
alexander-schranz Jul 14, 2022
cf0bff2
Remove not required kernel.root_dir
alexander-schranz Jul 14, 2022
747b413
Mark disabledcsrftokenmanager as final
alexander-schranz Jul 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ on:
- '[0-9]+.[0-9]+'

jobs:
test:
name: 'PHP ${{ matrix.php-version }} (${{ matrix.database }}, ${{ matrix.dependency-versions }}, Lint ${{ matrix.lint }})'
php:
name: 'PHP ${{ matrix.php-version }} (${{ matrix.database }}, ${{ matrix.dependency-versions }})'
runs-on: ubuntu-latest

strategy:
@@ -19,8 +19,7 @@ jobs:
- php-version: '7.2'
database: postgres
dependency-versions: 'lowest'
tools: 'composer:v1'
lint: false
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled
DATABASE_URL: postgres://postgres:[email protected]/sulu_form_test?serverVersion=12.5
@@ -31,7 +30,6 @@ jobs:
database: mysql
dependency-versions: 'highest'
tools: 'composer:v2'
lint: false
env:
SYMFONY_DEPRECATIONS_HELPER: weak
DATABASE_URL: mysql://root:[email protected]/sulu_form_test?serverVersion=5.7
@@ -42,7 +40,6 @@ jobs:
database: mysql
dependency-versions: 'highest'
tools: 'composer:v2'
lint: false
env:
SYMFONY_DEPRECATIONS_HELPER: weak
DATABASE_URL: mysql://root:[email protected]/sulu_form_test?serverVersion=5.7
@@ -53,7 +50,6 @@ jobs:
database: mysql
dependency-versions: 'highest'
tools: 'composer:v2'
lint: true
env:
SYMFONY_DEPRECATIONS_HELPER: weak
DATABASE_URL: mysql://root:[email protected]/sulu_form_test?serverVersion=5.7
@@ -104,7 +100,30 @@ jobs:
run: time composer test
env: ${{ matrix.env }}

lint:
name: 'PHP Lint'
runs-on: ubuntu-latest
env:
DATABASE_URL: mysql://root:[email protected]/sulu_form_test?serverVersion=5.7

steps:
- name: Checkout project
uses: actions/checkout@v2

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: 'imagick'
tools: 'composer:v2'
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
dependency-versions: ${{matrix.dependency-versions}}
composer-options: ${{ matrix.composer-options }}


- name: Lint code
if: ${{ matrix.lint }}
run: composer lint
env: ${{ matrix.env }}
20 changes: 10 additions & 10 deletions Controller/FormWebsiteController.php
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ public function __construct()
);
}

public static function getSubscribedServices()
public static function getSubscribedServices(): array
{
$subscribesServices = parent::getSubscribedServices();
$subscribesServices['form.registry'] = FormRegistryInterface::class;
@@ -75,11 +75,11 @@ public function formAction(Request $request, StructureInterface $structure, bool

$typeClass = $this->getTypeClass($template);
/** @var AbstractType $type */
$type = $this->get('form.registry')->getType($typeClass)->getInnerType();
$type = $this->container->get('form.registry')->getType($typeClass)->getInnerType();
$type->setAttributes($attributes);

$this->form = $this->get('form.factory')->create($typeClass, [], [
'csrf_token_manager' => new DisabledCsrfTokenManager($this->get('security.csrf.token_manager')),
$this->form = $this->container->get('form.factory')->create($typeClass, [], [
'csrf_token_manager' => new DisabledCsrfTokenManager($this->container->get('security.csrf.token_manager')),
]);
$this->form->handleRequest($request);

@@ -110,8 +110,8 @@ public function onlyAction(Request $request, string $key): Response

$typeClass = $this->getTypeClass($key);
/** @var AbstractType $type */
$type = $this->get('form.registry')->getType($typeClass)->getInnerType();
$this->form = $this->get('form.factory')->create($typeClass);
$type = $this->container->get('form.registry')->getType($typeClass)->getInnerType();
$this->form = $this->container->get('form.factory')->create($typeClass);
$this->form->handleRequest($request);

if ($this->form->isSubmitted()
@@ -136,14 +136,14 @@ public function onlyAction(Request $request, string $key): Response
private function handleFormSubmit(Request $request, AbstractType $type, array $attributes): ?Response
{
// handle form submit
$configuration = $this->get('sulu_form.configuration.form_configuration_factory')->buildByType(
$configuration = $this->container->get('sulu_form.configuration.form_configuration_factory')->buildByType(
$type,
$this->form->getData(),
$request->getLocale(),
$attributes
);

$success = $this->get('sulu_form.handler')->handle($this->form, $configuration);
$success = $this->container->get('sulu_form.handler')->handle($this->form, $configuration);

if ($success) {
if ($request->isXmlHttpRequest()) {
@@ -169,14 +169,14 @@ private function handleFormSubmit(Request $request, AbstractType $type, array $a
private function handleFormOnlySubmit(Request $request, AbstractType $type): ?RedirectResponse
{
// handle form submit
$configuration = $this->get('sulu_form.configuration.form_configuration_factory')->buildByType(
$configuration = $this->container->get('sulu_form.configuration.form_configuration_factory')->buildByType(
$type,
$this->form->getData(),
$request->getLocale(),
[]
);

if ($this->get('sulu_form.handler')->handle($this->form, $configuration)) {
if ($this->container->get('sulu_form.handler')->handle($this->form, $configuration)) {
return new RedirectResponse('?send=true');
}

11 changes: 7 additions & 4 deletions Csrf/DisabledCsrfTokenManager.php
Original file line number Diff line number Diff line change
@@ -14,6 +14,9 @@
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;

/**
* @final
*/
class DisabledCsrfTokenManager implements CsrfTokenManagerInterface
{
/**
@@ -29,28 +32,28 @@ public function __construct(CsrfTokenManagerInterface $csrfTokenManager)
/**
* @param string $tokenId
*/
public function refreshToken($tokenId)
public function refreshToken($tokenId): CsrfToken
{
return $this->csrfTokenManager->refreshToken($tokenId);
}

/**
* @param string $tokenId
*/
public function removeToken($tokenId)
public function removeToken($tokenId): ?string
{
return $this->csrfTokenManager->removeToken($tokenId);
}

public function isTokenValid(CsrfToken $token)
public function isTokenValid(CsrfToken $token): bool
{
return $this->csrfTokenManager->isTokenValid($token);
}

/**
* @param string $tokenId
*/
public function getToken($tokenId)
public function getToken($tokenId): CsrfToken
{
return new CsrfToken('', null);
}
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ class Configuration implements ConfigurationInterface
public const SWIFT_MAILER_HELPER = 'swift_mailer';
public const MAILER_HELPER = 'mailer';

public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sulu_form');
$rootNode = $treeBuilder->getRootNode();
@@ -47,7 +47,7 @@ public function getConfigTreeBuilder()
SuluFormExtension::MEDIA_COLLECTION_STRATEGY_TREE,
])
->defaultValue(null)
->setDeprecated()
->setDeprecated('sulu/form-bundle', '2.2.0')
->end()
->arrayNode('media')
->addDefaultsIfNotSet()
11 changes: 11 additions & 0 deletions DependencyInjection/SuluFormExtension.php
Original file line number Diff line number Diff line change
@@ -185,6 +185,17 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('types.xml');
$loader->load('title-providers.xml');

$definition = $container->getDefinition('sulu_mail.null_helper');

$reflection = new \ReflectionClass($definition);
$reflectionMethod = $reflection->getMethod('setDeprecated');

if (isset($reflectionMethod->getParameters()[1]) && 'version' === $reflectionMethod->getParameters()[1]->getName()) {
$definition->setDeprecated('sulu/form-bundle', '2.3', 'The "%service_id%" is deprecated use the mailer configuration instead.');
} else {
$definition->setDeprecated(true, 'The "%service_id%" is deprecated use the mailer configuration instead.');
}

if ($config['sendinblue_api_key']) {
if (!\class_exists(\SendinBlue\Client\Configuration::class)) {
throw new \LogicException('You need to install the "sendinblue/api-v3-sdk" package to use the sendinblue type.');
19 changes: 15 additions & 4 deletions Dynamic/Checksum.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

namespace Sulu\Bundle\FormBundle\Dynamic;

use Symfony\Component\PasswordHasher\Hasher\MessageDigestPasswordHasher;
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;

/**
@@ -24,14 +25,16 @@ class Checksum
private $secret;

/**
* @var MessageDigestPasswordEncoder
* @var MessageDigestPasswordEncoder|MessageDigestPasswordHasher
*/
private $encoder;

public function __construct(string $secret)
{
$this->secret = $secret;
$this->encoder = new MessageDigestPasswordEncoder();
$this->encoder = \class_exists(MessageDigestPasswordEncoder::class)
? new MessageDigestPasswordEncoder()
: new MessageDigestPasswordHasher();
}

/**
@@ -41,7 +44,11 @@ public function check(string $checksum, string $type, string $typeId, int $formI
{
$checksumRaw = $this->createKey($type, $typeId, $formId, $formName);

return $this->encoder->isPasswordValid($checksum, $checksumRaw, $this->secret);
if (\class_exists(MessageDigestPasswordEncoder::class)) {
return $this->encoder->isPasswordValid($checksum, $checksumRaw, $this->secret);
}

return $this->encoder->verify($checksum, $checksumRaw, $this->secret);
}

/**
@@ -59,6 +66,10 @@ public function get(string $type, string $typeId, int $formId, string $formName)
{
$checksumRaw = $this->createKey($type, $typeId, $formId, $formName);

return $this->encoder->encodePassword($checksumRaw, $this->secret);
if (\class_exists(MessageDigestPasswordEncoder::class)) {
return $this->encoder->encodePassword($checksumRaw, $this->secret);
}

return $this->encoder->hash($checksumRaw, $this->secret);
}
}
2 changes: 1 addition & 1 deletion Event/ProtectedMediaSubscriber.php
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ public static function getSubscribedEvents()

public function onRequest(RequestEvent $event): void
{
if (!$event->isMasterRequest()) {
if (\method_exists($event, 'isMainRequest') ? !$event->isMainRequest() : !$event->isMasterRequest()) {
return;
}

2 changes: 1 addition & 1 deletion Event/RequestListener.php
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ public function __construct(

public function onKernelRequest(RequestEvent $event): void
{
if (!$event->isMasterRequest()) {
if (\method_exists($event, 'isMainRequest') ? !$event->isMainRequest() : !$event->isMasterRequest()) {
// do nothing if it's not the master request
return;
}
1 change: 0 additions & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
<!-- Mail-->
<service id="sulu_mail.null_helper" class="Sulu\Bundle\FormBundle\Mail\NullHelper">
<argument type="service" id="logger" />
<deprecated />
</service>

<!-- Admin -->
8 changes: 7 additions & 1 deletion Tests/Application/Kernel.php
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@

use Sulu\Bundle\FormBundle\SuluFormBundle;
use Sulu\Bundle\TestBundle\Kernel\SuluTestKernel;
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
use Symfony\Component\Config\Loader\LoaderInterface;

class Kernel extends SuluTestKernel
@@ -32,11 +33,16 @@ public function registerBundles(): iterable
);
}

public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);

$loader->load(__DIR__ . '/config/config_' . $this->getContext() . '.yml');

$parameters = $this->getKernelParameters();
if (isset($parameters['kernel.bundles'][SwiftmailerBundle::class])) {
$loader->load(__DIR__ . '/config/swiftmailer.yml'); // @deprecated
}
}

protected function getKernelParameters(): array
2 changes: 1 addition & 1 deletion Tests/Application/MailerKernel.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@

class MailerKernel extends Kernel
{
public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);

3 changes: 0 additions & 3 deletions Tests/Application/config/config.yml
Original file line number Diff line number Diff line change
@@ -22,6 +22,3 @@ sulu_form:
mail:
from: "[email protected]"
to: "[email protected]"

swiftmailer:
disable_delivery: true
2 changes: 2 additions & 0 deletions Tests/Application/config/swiftmailer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
swiftmailer:
disable_delivery: true
4 changes: 2 additions & 2 deletions Tests/Functional/Controller/FormControllerTest.php
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ public function testFormMetadata(): void
$this->assertHttpStatusCode(200, $this->client->getResponse());
}

public function testGetNotFound()
public function testGetNotFound(): void
{
$this->client->request(
'GET',
@@ -340,7 +340,7 @@ private function assertFullForm($response)
$this->assertCountFields(18, $response);
}

private function assertCountFields($expectedCount, $haystack)
private function assertCountFields($expectedCount, $haystack): void
{
$this->assertCount(
$expectedCount,
8 changes: 8 additions & 0 deletions Tests/Functional/Mail/HelperTest.php
Original file line number Diff line number Diff line change
@@ -12,11 +12,19 @@
namespace Sulu\Bundle\FormBundle\Tests\Functional\Mail;

use Sulu\Bundle\FormBundle\Entity\FormTranslation;
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;

/**
* @deprecated
*/
class HelperTest extends HelperTestCase
{
public function testSendsEmailUsingSwiftmailer()
{
if (!\class_exists(SwiftmailerBundle::class)) {
$this->markTestSkipped('Swiftmailer is not installed.');
}

$formTranslationRepository = $this->entityManager->getRepository(FormTranslation::class);
/** @var FormTranslation $formTranslation */
$formTranslation = $formTranslationRepository->findOneBy(['title' => 'Title', 'locale' => 'de']);
Loading