use SymfonyBundle for security instead of core#727
use SymfonyBundle for security instead of core#727tacman wants to merge 2 commits intoKnpLabs:masterfrom
Conversation
GerB
left a comment
There was a problem hiding this comment.
This seems to cover the deprecation notice, thanks!
|
I thought the way Symfony deprecations worked is that they back-ported the new classes to the supported versions. What is the proper way to fix this then? |
Nope it does not work like that, only 6.2 and high versions are affected. Anyway, even if you requires To me, there are two solutions. 1. Create a breaking changesWe can restrict the usage of It means that we must a new major release, and I'm not a big fan just for a deprecation. 2. Create a BC-layerWe can add a BC-layer to keep compatibility for Symfony 5.4/6.0/6.1 and 6.2. First, you must move Then, you must write a wrapper around I don't have tested it, but it should do the job: <?php
declare(strict_types=1);
namespace Knp\DoctrineBehaviors\Security;
use Symfony\Bundle\SecurityBundle\Security as SecurityBundle;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Security as SecurityCore;
if (class_exists(SecurityBundle::class)) {
final class Security {
public function __construct(
private SecurityBundle $security,
) {
}
public function getToken(): ?TokenInterface
{
return $this->security->getToken();
}
}
} elseif (class_exists(SecurityCore::class)) {
final class Security {
public function __construct(
private SecurityCore $security,
) {
}
public function getToken(): ?TokenInterface
{
return $this->security->getToken();
}
}
} else {
throw new \LogicException(sprintf('You cannot use "%s" because either the Symfony Security Bundle or Symfony Security Core is not installed. If you use Symfony 6.2+, try running "composer require symfony/security-bundle", otherwise run "composer require symfony/security-core".', __CLASS__));
}Finally, in the Anyway, it would be nice if the CI can install and run tests on many Symfony and PHP versions, and also with a |
|
For information I've done it as suggested in my repo raziel057@1fa7b2c and it's working fine whether the https://github.com/symfony/security-bundle/blob/6.3/Security.php class is present or not. I can create a PR in this repository but it would be nice if you could first accept the following PR:
Please note that it's not a problem to let the symfony/security-core dependency because it's also required by other packages. |
Symfony 7 is just around the corner. How about a major release then, supporting ^6.4 || ^7? |
|
This change was covered in #782, see https://github.com/KnpLabs/DoctrineBehaviors/pull/782/files#diff-e0aeaf20449a86f651188526e6ad497a93e002be452d92892a49edf82fd55526 And it is release as v3.0.0 |
This gets rid of the deprecation error. phpunit tests pass.