Skip to content

Commit

Permalink
Drop support for Symfony 4 and Twig 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Apr 24, 2023
1 parent 1856b9e commit 2bb675b
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 134 deletions.
34 changes: 17 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
"php": "^8.0",
"sonata-project/admin-bundle": "^4.14",
"sonata-project/block-bundle": "^4.11",
"symfony/config": "^4.4 || ^5.4 || ^6.2",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.2",
"symfony/form": "^4.4 || ^5.4 || ^6.2",
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.2",
"symfony/http-foundation": "^4.4 || ^5.4 || ^6.2",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.2",
"symfony/intl": "^4.4 || ^5.4 || ^6.2",
"symfony/options-resolver": "^4.4 || ^5.4 || ^6.2",
"twig/twig": "^2.12 || ^3.0"
"symfony/config": "^5.4 || ^6.2",
"symfony/dependency-injection": "^5.4 || ^6.2",
"symfony/form": "^5.4 || ^6.2",
"symfony/framework-bundle": "^5.4 || ^6.2",
"symfony/http-foundation": "^5.4 || ^6.2",
"symfony/http-kernel": "^5.4 || ^6.2",
"symfony/intl": "^5.4 || ^6.2",
"symfony/options-resolver": "^5.4 || ^6.2",
"twig/twig": "^3.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.7",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"doctrine/orm": "^2.14",
"doctrine/persistence": "^2.0 || ^3.0",
"doctrine/persistence": "^3.0",
"friendsofphp/php-cs-fixer": "^3.4",
"gedmo/doctrine-extensions": "^3.11",
"knplabs/doctrine-behaviors": "^2.2",
Expand All @@ -51,19 +51,19 @@
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^4.0 || ^5.0",
"psalm/plugin-symfony": "^5.0",
"rector/rector": "^0.15",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.4 || ^6.2",
"symfony/css-selector": "^4.4 || ^5.4 || ^6.2",
"symfony/doctrine-bridge": "^4.4.48 || ^5.4 || ^6.2",
"symfony/filesystem": "^4.4 || ^5.4 || ^6.2",
"symfony/browser-kit": "^5.4 || ^6.2",
"symfony/css-selector": "^5.4 || ^6.2",
"symfony/doctrine-bridge": "^5.4 || ^6.2",
"symfony/filesystem": "^5.4 || ^6.2",
"symfony/phpunit-bridge": "^6.2",
"vimeo/psalm": "^4.3.2 || ^5.8",
"vimeo/psalm": "^5.8",
"weirdan/doctrine-psalm-plugin": "^2.0"
},
"conflict": {
"doctrine/persistence": "<2.0",
"doctrine/persistence": "<3.0",
"gedmo/doctrine-extensions": "<3.11",
"knplabs/doctrine-behaviors": "<2.2 || >=3.0"
},
Expand Down
9 changes: 4 additions & 5 deletions src/Resources/config/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sonata\TranslationBundle\Block\LocaleSwitcherBlockService;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
$containerConfigurator->services()

->set('sonata_translation.block.locale_switcher', LocaleSwitcherBlockService::class)
->tag('sonata.block')
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata_translation.admin.provider.request_locale_provider'),
service('twig'),
service('sonata_translation.admin.provider.request_locale_provider'),
]);
};
5 changes: 2 additions & 3 deletions src/Resources/config/checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sonata\TranslationBundle\Checker\TranslatableChecker;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
$containerConfigurator->services()

->set('sonata_translation.checker.translatable', TranslatableChecker::class);
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sonata\TranslationBundle\EventListener\LocaleSwitcherListener;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
$containerConfigurator->services()

->set('sonata_translation.listener.locale_switcher', LocaleSwitcherListener::class)
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/config/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sonata\TranslationBundle\Provider\RequestLocaleProvider;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
Expand All @@ -22,7 +22,7 @@

->set('sonata_translation.admin.provider.request_locale_provider', RequestLocaleProvider::class)
->args([
new ReferenceConfigurator('request_stack'),
'%sonata_translation.default_locale%',
service('request_stack'),
param('sonata_translation.default_locale'),
]);
};
14 changes: 6 additions & 8 deletions src/Resources/config/service_gedmo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sonata\TranslationBundle\Admin\Extension\Gedmo\TranslatableAdminExtension;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
$containerConfigurator->services()

->set('sonata_translation.admin.extension.gedmo_translatable', TranslatableAdminExtension::class)
->tag('sonata.admin.extension')
->args([
new ReferenceConfigurator('sonata_translation.checker.translatable'),
new ReferenceConfigurator('sonata_translation.listener.translatable'),
new ReferenceConfigurator('doctrine'),
new ReferenceConfigurator('sonata_translation.admin.provider.request_locale_provider'),
service('sonata_translation.checker.translatable'),
service('sonata_translation.listener.translatable'),
service('doctrine'),
service('sonata_translation.admin.provider.request_locale_provider'),
]);
};
16 changes: 7 additions & 9 deletions src/Resources/config/service_knplabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,27 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Knp\DoctrineBehaviors\Contract\Provider\LocaleProviderInterface;
use Sonata\TranslationBundle\Admin\Extension\Knplabs\TranslatableAdminExtension;
use Sonata\TranslationBundle\Provider\Knplabs\LocaleProvider;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
$containerConfigurator->services()

->set('sonata_translation.admin.extension.knplabs_translatable', TranslatableAdminExtension::class)
->tag('sonata.admin.extension')
->args([
new ReferenceConfigurator('sonata_translation.checker.translatable'),
new ReferenceConfigurator('sonata_translation.admin.provider.request_locale_provider'),
service('sonata_translation.checker.translatable'),
service('sonata_translation.admin.provider.request_locale_provider'),
])

->set('sonata_translation.admin.provider.knplabs_locale_provider', LocaleProvider::class)
->decorate(LocaleProviderInterface::class)
->args([
new ReferenceConfigurator('request_stack'),
new ReferenceConfigurator('sonata_translation.admin.provider.knplabs_locale_provider.inner'),
new ReferenceConfigurator('sonata_translation.admin.provider.request_locale_provider'),
service('request_stack'),
service('sonata_translation.admin.provider.knplabs_locale_provider.inner'),
service('sonata_translation.admin.provider.request_locale_provider'),
]);
};
7 changes: 3 additions & 4 deletions src/Resources/config/service_locale_switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sonata\TranslationBundle\EventSubscriber\LocaleSubscriber;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
$containerConfigurator->services()

->set('sonata_translation.locale_switcher.locale_subscriber', LocaleSubscriber::class)
->tag('kernel.event_subscriber')
->args([
'%kernel.default_locale%',
param('kernel.default_locale'),
]);
};
7 changes: 3 additions & 4 deletions src/Resources/config/service_orm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sonata\TranslationBundle\Filter\TranslationFieldFilter;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
$containerConfigurator->services()

->set('sonata_translation.filter.type.translation_field', TranslationFieldFilter::class)
->tag('sonata.admin.filter.type')
->args([
'%sonata_translation.default_filter_mode%',
param('sonata_translation.default_filter_mode'),
]);
};
8 changes: 3 additions & 5 deletions src/Resources/config/twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sonata\TranslationBundle\Twig\Extension\SonataTranslationExtension;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
$containerConfigurator->services()

->set('sonata_translation.twig.sonata_translation_extension', SonataTranslationExtension::class)
->tag('twig.extension')
->args([
new ReferenceConfigurator('sonata_translation.checker.translatable'),
service('sonata_translation.checker.translatable'),
]);
};
5 changes: 2 additions & 3 deletions src/Resources/config/twig_intl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sonata\TranslationBundle\Twig\Extension\IntlExtension;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
$containerConfigurator->services()

->set('sonata_translation.twig.intl_extension', IntlExtension::class)
Expand Down
26 changes: 13 additions & 13 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Knp\Bundle\MenuBundle\KnpMenuBundle;
use Knp\DoctrineBehaviors\DoctrineBehaviorsBundle;
use Sonata\AdminBundle\SonataAdminBundle;
use Sonata\BlockBundle\Cache\HttpCacheHandler;
use Sonata\BlockBundle\SonataBlockBundle;
use Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle;
use Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle;
Expand All @@ -26,13 +27,13 @@
use Sonata\Twig\Bridge\Symfony\SonataTwigBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Security\Http\Attribute\IsGranted;

final class AppKernel extends Kernel
{
Expand Down Expand Up @@ -73,26 +74,25 @@ public function getProjectDir(): string
return __DIR__;
}

/**
* TODO: Add typehint when dropping support of symfony < 5.1.
*
* @param RoutingConfigurator $routes
*/
protected function configureRoutes($routes): void
protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import(sprintf('%s/config/routes.yaml', $this->getProjectDir()));
}

/**
* @psalm-suppress DeprecatedClass
*/
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->setParameter('app.base_dir', $this->getBaseDir());

if (interface_exists(AuthenticatorFactoryInterface::class)) {
$loader->load(__DIR__.'/config/config_v5.yml');
$loader->load(__DIR__.'/config/security_v5.yml');
} else {
$loader->load(__DIR__.'/config/config_v4.yml');
$loader->load(__DIR__.'/config/security_v4.yml');
// TODO: Simplify this when dropping support for Symfony 5.4
if (!class_exists(IsGranted::class)) {
$loader->load(__DIR__.'/config/config_symfony_v5.yaml');
}

if (class_exists(HttpCacheHandler::class)) {
$loader->load(__DIR__.'/config/config_sonata_block_v4.yaml');
}

$container
Expand Down
15 changes: 11 additions & 4 deletions tests/App/config/config_v5.yml → tests/App/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
framework:
secret: '$3cr37'
secret: "$3cr37"
assets:
enabled: true
form:
Expand All @@ -13,15 +13,22 @@ framework:
router:
utf8: true

security:
providers:
in_memory:
memory: null
firewalls:
main:
lazy: true

twig:
exception_controller: null
strict_variables: true

parameters:
env(DATABASE_URL): 'sqlite:////%app.base_dir%database.db'
locale: 'en'
env(DATABASE_URL): "sqlite:////%app.base_dir%database.db"
locale: "en"

sonata_block:
http_cache: false
blocks:
sonata_translation.block.locale_switcher: ~
2 changes: 2 additions & 0 deletions tests/App/config/config_sonata_block_v4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sonata_block:
http_cache: false
2 changes: 2 additions & 0 deletions tests/App/config/config_symfony_v5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
security:
enable_authenticator_manager: true
Loading

0 comments on commit 2bb675b

Please sign in to comment.