security.csrf.token_manager serializer cache_clearer filesystem use Symfony\Component\DependencyInjection\ContainerInterface ; class SomeServic e { private ContainerInterface $container ; public function doSomething(): voi d { $translator = $this->container->get('translator') ; } } // Accessing the "%alias_id%" service directly from the container is deprecated, use dependency injection instead .
class SomeServic e { private Environment $container ; public function doSomething(): voi d { $twig = $this->container->get('twig') ; } } // Accessing the "%alias_id%" service directly from the container is deprecated, use dependency injection instead .
use Symfony\Component\Notifier\Message\MessageInterface ; use Symfony\Component\Notifier\Message\SentMessage ; /* * * @experimental in 5. 1 * / interface TransportInterfac e { // Befor e public function send(MessageInterface $message): void ; // Afte r public function send(MessageInterface $message): ?SentMessage; }
use Symfony\Component\Notifier\Message\MessageInterface ; use Symfony\Component\Notifier\Message\SentMessage ; /* * * @experimental in 5. 1 * / abstract class AbstractTransport implements TransportInterfac e { // Befor e abstract protected function doSend(MessageInterface $message): void ; // Afte r abstract protected function doSend(MessageInterface $message): SentMessage ; // ... }
Symfony\Component\Notifier\Message\EmailMessage ; use Symfony\Component\Notifier\Recipient\EmailRecipientInterface ; use Symfony\Component\Notifier\Recipient\Recipient ; /* * * @experimental in 5. 1 * / interface EmailNotificationInterfac e { // Befor e public function asEmailMessage(Recipient $recipient, string $transport = null): ?EmailMessage ; // Afte r public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage ; }
Symfony\Component\Notifier\Message\SmsMessage ; use Symfony\Component\Notifier\Recipient\Recipient ; use Symfony\Component\Notifier\Recipient\SmsRecipientInterface ; /* * * @experimental in 5. 1 * / interface SmsNotificationInterfac e { // Befor e public function asSmsMessage(Recipient $recipient, string $transport = null): ?SmsMessage ; // Afte r public function asSmsMessage(SmsRecipientInterface $recipient, string $transport = null): ?SmsMessage ; }
Symfony\Component\Notifier\Notification\Notification ; use Symfony\Component\Notifier\Recipient\Recipient ; use Symfony\Component\Notifier\Recipient\RecipientInterface ; /* * * @experimental in 5. 1 * / interface NotifierInterfac e { // Befor e public function send(Notification $notification, Recipient ...$recipients): void ; // Afte r public function send(Notification $notification, RecipientInterface ...$recipients): void ; }
Symfony\Component\Notifier\Recipient\Recipient ; use Symfony\Component\Notifier\Recipient\RecipientInterface ; /* * * @experimental in 5. 1 * / class Notificatio n { // Befor e public function getChannels(Recipient $recipient): array ; // Afte r public function getChannels(RecipientInterface $recipient): array ; }
Symfony\Component\Notifier\Notification\Notification ; use Symfony\Component\Notifier\Recipient\Recipient ; use Symfony\Component\Notifier\Recipient\RecipientInterface ; /* * * @experimental in 5. 1 * / interface ChannelInterfac e { // Before public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void ; public function supports(Notification $notification, Recipient $recipient): bool ; // After public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void ; public function supports(Notification $notification, RecipientInterface $recipient): bool ; }
Use instea d \Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter::PUBLIC_ACCES S https://symfony.com/blog/new-in-symfony-5-1-updated-security-system In the experimental authenticator-based system, * TokenInterface::getUser( ) returns null in case of unauthenticated session.
// using a predefined styl e $output->writeln('<info>... contents ...</>') ; // custom style using basic color s $output->writeln('<fg=green;bg=blue>... contents …</>') ; // custom style using true color s $output->writeln('<fg=#00ff00;bg=#00f>... contents ...</>') ; // the third optional argument defines the style s $color = new Color('#000', '#fff', ['underscore', 'reverse']) ; echo $color->apply('... contents ...') ; Console
#37678 // there are generators for UUID V1 and V6 to o use Symfony\Bridge\Doctrine\IdGenerator\UuidV4Generator; /* * * @ORM\Entit y * / class Produc t { /* * * @ORM\I d * @ORM\Column(type="uuid", unique=true ) * @ORM\GeneratedValue(strategy="CUSTOM" ) * @ORM\CustomIdGenerator(class=UuidV4Generator::class ) * / private $id ; } Doctrine
class MyCustomDataCollector extends AbstractDataCollecto r { public function collect(Request $request, Response $response, \Throwable $exception = null): voi d { $this->data = '...' ; } public static function getTemplate(): ?strin g { return 'data_collector/template.html.twig' ; } public function getName(): strin g { return 'app.my_custom_collector' ; } } WebPro f i lerBundle
PR #36480 provided by Jérémy Romey • Google Chat in PR #36488 provided by Jérôme Tamarelle • Esendex SMS in PR #36573 provided by Olivier Dolbeau • Zulip Chat in PR #36616 provided by Mohammad Emran Hasan • Mobyt SMS in PR #36648 provided by Bastien Durand • SMSAPI SMS in PR #36940 provided by Marcin Szepczynski • LinkedIn in PR #37830 provided by Smaine Milianni • Sendinblue SMS in PR #38298 provided by Pierre Tondereau • Discord Chat in PR #38522 provided by Karoly Gossler and Mathieu Piot • Improved Telegram Chat to allow de f i ne some options in PR #36496 provided by Mihail Krasilnikov
http_client : retry_failed : # only retry errors with these HTTP code s http_codes: [429, 500 ] max_retries: 2 # waiting time between retries (in milliseconds ) delay: 100 0 # if set, the waiting time of each retry increases by this facto r # (e.g. first retry: 1000ms; second retry: 3 * 1000ms; etc. ) multiplier: 3 HttpClient framework : http_client : retry_failed: true # 423, 425, 429, 500, 502, 503, 504, 507, 510
#37351 FrameworkBundle # config/packages/framework.yam l framework : # use the HTTP Cache default s http_cache: tru e # configure every HTTP Cache optio n http_cache : private_headers: ['Authorization', 'Cookie', 'MyCustomHeader' ] default_ttl: 360 0 allow_revalidate: tru e stale_if_error: 600
#37357 FrameworkBundle # config/packages/framework.yam l framework: # configure proxies to trust directly in the config file : trusted_proxies: '127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 ' # or use an env var if this value is dynami c trusted_proxies: '%env(TRUSTED_PROXIES)% ' # you can also define the trusted header s trusted_headers: ['x-forwarded-all', '!x-forwarded-host', '!x-forwarded-prefix']
firewalls : default : # by default, the feature allows 5 login attempts per minut e login_throttling: ~ # configuring the maximum login attempts (per minute ) login_throttling : max_attempts: 1 # you can even use a custom rate limiter via its service I D login_throttling : limiter: app.my_login_rate_limite r
PHP 8 // Befor e use Symfony\Component\Routing\Annotation\Route ; class SomeControlle r { /* * * @Route("/path", name="action" ) * / public function someAction( ) { // .. . } } // Afte r use Symfony\Component\Routing\Annotation\Route ; class SomeControlle r { #[Route(‚/path', name: 'action')] public function someAction( ) { // .. . } }
PHP 8 use Symfony\Contracts\Service\Attribute\Required ; class SomeServic e { /** @Required */ #[Required ] public Bar $bar ; /** @Required */ #[Required ] public function setFoo(Foo $foo): voi d { // .. . } }
use App\Entity\MyUser ; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController ; use Symfony\Component\Security\Http\Attribute\CurrentUser ; class SomeController extends AbstractControlle r { public function index(#[CurrentUser] MyUser $user) { // .. . } }
#38499 PHP 8 // Befor e use Symfony\Component\Validator\Constraints as Assert ; class Autho r { /* * * @Assert\Choice ( * choices = { "fiction", "non-fiction" } , * message = "Choose a valid genre. " * ) * / private $genre ; } // Afte r use Symfony\Component\Validator\Constraints as Assert ; class Autho r { #[Assert\Choice ( choices: ['fiction', 'non-fiction'] , message: 'Choose a valid genre.' , )] private $genre ; } Join the discussion for an alternative of nested attributes in #38503.