-
Notifications
You must be signed in to change notification settings - Fork 299
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
use SymfonyBundle for security instead of core #727
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to cover the deprecation notice, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Security
class is only available on Symfony 6.2, this is not the right fix.
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 gets rid of the deprecation error. phpunit tests pass.