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

[AllBundles] Cleanup of symfony 3.4 compatibility layers #2991

Merged
merged 2 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('kunstmaan_admin');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('kunstmaan_admin');
}
$rootNode = $treeBuilder->getRootNode();

$rootNode
->fixXmlConfig('admin_locale')
Expand Down
3 changes: 2 additions & 1 deletion src/Kunstmaan/AdminBundle/Event/AdaptSimpleFormEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\TabPane;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\EventDispatcher\Event;

final class AdaptSimpleFormEvent extends BcEvent
final class AdaptSimpleFormEvent extends Event
{
/**
* @var Request
Expand Down
26 changes: 0 additions & 26 deletions src/Kunstmaan/AdminBundle/Event/BcEvent.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use Kunstmaan\AdminBundle\Entity\UserInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\EventDispatcher\Event;

final class ChangePasswordSuccessEvent extends BcEvent
final class ChangePasswordSuccessEvent extends Event
{
/** @var UserInterface */
private $user;
Expand Down
4 changes: 3 additions & 1 deletion src/Kunstmaan/AdminBundle/Event/DeepCloneAndSaveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Kunstmaan\AdminBundle\Event;

use Symfony\Contracts\EventDispatcher\Event;

/**
* This event wil be used to pass metadata when the deep clone event is triggered.
*/
final class DeepCloneAndSaveEvent extends BcEvent
final class DeepCloneAndSaveEvent extends Event
{
/**
* @var mixed
Expand Down
18 changes: 3 additions & 15 deletions src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,16 @@ private function getPermittedAclIdsSQLForUser(Query $query): string
$user = null;
if (!\is_null($token)) {
$user = $token->getUser();
if (method_exists($this->roleHierarchy, 'getReachableRoleNames')) {
$userRoles = $this->roleHierarchy->getReachableRoleNames($token->getRoleNames());
} else {
// Symfony 3.4 compatibility
$userRoles = $this->roleHierarchy->getReachableRoles($token->getRoles());
}
$userRoles = $this->roleHierarchy->getReachableRoleNames($token->getRoleNames());
}

// Security context does not provide anonymous role automatically.
$uR = [$databasePlatform->quoteStringLiteral('IS_AUTHENTICATED_ANONYMOUSLY')];

foreach ($userRoles as $role) {
// The reason we ignore this is because by default FOSUserBundle adds ROLE_USER for every user
if (is_string($role)) {
if ($role !== 'ROLE_USER') {
$uR[] = $databasePlatform->quoteStringLiteral($role);
}
} else {
// Symfony 3.4 compatibility
if ($role->getRole() !== 'ROLE_USER') {
$uR[] = $databasePlatform->quoteStringLiteral($role->getRole());
}
if ($role !== 'ROLE_USER') {
$uR[] = $databasePlatform->quoteStringLiteral($role);
}
}
$uR = array_unique($uR);
Expand Down
18 changes: 3 additions & 15 deletions src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclNativeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,16 @@ public function apply(QueryBuilder $queryBuilder, PermissionDefinition $permissi
$user = null;
if (!\is_null($token)) {
$user = $token->getUser();
if (method_exists($this->roleHierarchy, 'getReachableRoleNames')) {
$userRoles = $this->roleHierarchy->getReachableRoleNames($token->getRoleNames());
} else {
// Symfony 3.4 compatibility
$userRoles = $this->roleHierarchy->getReachableRoles($token->getRoles());
}
$userRoles = $this->roleHierarchy->getReachableRoleNames($token->getRoleNames());
}

// Security context does not provide anonymous role automatically.
$uR = [$databasePlatform->quoteStringLiteral('IS_AUTHENTICATED_ANONYMOUSLY')];

foreach ($userRoles as $role) {
// The reason we ignore this is because by default FOSUserBundle adds ROLE_USER for every user
if (is_string($role)) {
if ($role !== 'ROLE_USER') {
$uR[] = $databasePlatform->quoteStringLiteral($role);
}
} else {
// Symfony 3.4 compatibility
if ($role->getRole() !== 'ROLE_USER') {
$uR[] = $databasePlatform->quoteStringLiteral($role->getRole());
}
if ($role !== 'ROLE_USER') {
$uR[] = $databasePlatform->quoteStringLiteral($role);
}
}
$uR = array_unique($uR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\MaskBuilder;
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionDefinition;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\Role\RoleHierarchy;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;

Expand Down Expand Up @@ -316,17 +314,10 @@ public function testGetTokenStorage()

private function getRoleMockData($anonymous = false)
{
if (Kernel::VERSION_ID >= 40300) {
$rolesMethodName = 'getRoleNames';
$reachableRolesMethodName = 'getReachableRoleNames';
$roles = ['ROLE_KING'];
$allRoles = [$roles[0], 'ROLE_SUBJECT'];
} else {
$rolesMethodName = 'getRoles';
$reachableRolesMethodName = 'getReachableRoles';
$roles = $anonymous ? [] : [new Role('ROLE_KING')];
$allRoles = $anonymous ? [] : [$roles[0], new Role('ROLE_SUBJECT')];
}
$rolesMethodName = 'getRoleNames';
$reachableRolesMethodName = 'getReachableRoleNames';
$roles = $anonymous ? [] : ['ROLE_KING'];
$allRoles = $anonymous ? [] : [$roles[0], 'ROLE_SUBJECT'];

return [
$rolesMethodName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclNativeHelper;
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionDefinition;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\Role\RoleHierarchy;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;

Expand Down Expand Up @@ -191,17 +189,10 @@ public function testGetTokenStorage()

private function getRoleMockData($anonymous = false)
{
if (Kernel::VERSION_ID >= 40300) {
$rolesMethodName = 'getRoleNames';
$reachableRolesMethodName = 'getReachableRoleNames';
$roles = ['ROLE_KING'];
$allRoles = [$roles[0], 'ROLE_SUBJECT'];
} else {
$rolesMethodName = 'getRoles';
$reachableRolesMethodName = 'getReachableRoles';
$roles = $anonymous ? [] : [new Role('ROLE_KING')];
$allRoles = $anonymous ? [] : [$roles[0], new Role('ROLE_SUBJECT')];
}
$rolesMethodName = 'getRoleNames';
$reachableRolesMethodName = 'getReachableRoleNames';
$roles = $anonymous ? [] : ['ROLE_KING'];
$allRoles = $anonymous ? [] : [$roles[0], 'ROLE_SUBJECT'];

return [
$rolesMethodName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public function collectData()
];
}

/**
* NEXT_MAJOR Add \Throwable $exception typehint when symfony version < 5 support is removed
*/
public function collect(Request $request, Response $response, $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
if (!$this->isEnabled()) {
$this->data = [];
Expand Down
5 changes: 1 addition & 4 deletions src/Kunstmaan/AdminBundle/Toolbar/ExceptionDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ public function collectData()
}
}

/**
* NEXT_MAJOR Add \Throwable $exception typehint when symfony version < 5 support is removed
*/
public function collect(Request $request, Response $response, $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
if (false === $this->isEnabled()) {
$this->data = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('kunstmaan_k_admin_list');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('kunstmaan_k_admin_list');
}
$rootNode = $treeBuilder->getRootNode();

/* @var ArrayNodeDefinition $pages */
$rootNode
->children()
->arrayNode('lock')
Expand Down
4 changes: 2 additions & 2 deletions src/Kunstmaan/AdminListBundle/Event/AdminListEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Kunstmaan\AdminListBundle\Event;

use Kunstmaan\AdminBundle\Event\BcEvent;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\EventDispatcher\Event;

final class AdminListEvent extends BcEvent
final class AdminListEvent extends Event
{
/**
* @var object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('kunstmaan_article');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('kunstmaan_article');
}

return $treeBuilder;
return new TreeBuilder('kunstmaan_article');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('kunstmaan_config');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('kunstmaan_config');
}
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('kunstmaan_dashboard');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('kunstmaan_dashboard');
}
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('kunstmaan_fixtures');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('kunstmaan_fixtures');
}
$rootNode = $treeBuilder->getRootNode();

return $treeBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('kunstmaan_form');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('kunstmaan_form');
}
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;

class KunstmaanFormExtension extends Extension implements PrependExtensionInterface
{
Expand All @@ -26,7 +25,7 @@ public function prepend(ContainerBuilder $container)
{
if (!$container->hasParameter('form_submission_rootdir')) {
$container->setParameter('form_submission_rootdir',
sprintf('%s/%s/uploads/formsubmissions', $container->getParameter('kernel.project_dir'), Kernel::VERSION_ID >= 40000 ? 'public' : 'web'));
sprintf('%s/%s/uploads/formsubmissions', $container->getParameter('kernel.project_dir'), 'public'));
}

if (!$container->hasParameter('form_submission_webdir')) {
Expand Down
4 changes: 2 additions & 2 deletions src/Kunstmaan/FormBundle/Event/SubmissionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Kunstmaan\FormBundle\Event;

use Kunstmaan\AdminBundle\Event\BcEvent;
use Kunstmaan\FormBundle\Entity\FormSubmission;
use Kunstmaan\FormBundle\Helper\FormPageInterface;
use Symfony\Contracts\EventDispatcher\Event;

final class SubmissionEvent extends BcEvent
final class SubmissionEvent extends Event
{
/**
* @var FormSubmission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Kunstmaan\FormBundle\DependencyInjection\KunstmaanFormExtension;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Kernel;

class KunstmaanFormExtensionTest extends AbstractExtensionTestCase
{
Expand All @@ -22,10 +21,6 @@ public function testCorrectParametersHaveBeenSet()
$this->container->setParameter('kernel.project_dir', '/somewhere/over/the/rainbow');
$this->load();

$expectedFormSubmissionPath = '/somewhere/over/the/rainbow/web/uploads/formsubmissions';
if (Kernel::VERSION_ID >= 40000) {
$expectedFormSubmissionPath = '/somewhere/over/the/rainbow/public/uploads/formsubmissions';
}
$this->assertContainerBuilderHasParameter('form_submission_rootdir', $expectedFormSubmissionPath);
$this->assertContainerBuilderHasParameter('form_submission_rootdir', '/somewhere/over/the/rainbow/public/uploads/formsubmissions');
}
}
Loading