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

[Symfony] Do not use Session deprecated features #10345

Closed
brusch opened this issue Sep 17, 2021 · 3 comments · Fixed by #10909
Closed

[Symfony] Do not use Session deprecated features #10345

brusch opened this issue Sep 17, 2021 · 3 comments · Fixed by #10909
Assignees
Milestone

Comments

@brusch
Copy link
Member

brusch commented Sep 17, 2021

Improvement description

\Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag has been deprecated.
We need to provide our own implementation.

See: https://symfony.com/doc/current/session.html#basic-usage

@brusch brusch added this to the 10.3.0 milestone Sep 17, 2021
@langert
Copy link
Contributor

langert commented Sep 19, 2021

Because of the deprecated info, adapting the example of the docs, I simply struggle trying to register a non namespaced AttributeBag in my 10.1 bundle.
"Cannot register a bag when the session is already started.".

I get this Exception when I try to set any value to the bag.

$this->session->getBag('my_name')->set('myparam', 'value#)

Where/when do I have to register the AttributeBag to be before haveing pimcore/symfony started the session? Do I need to use the pimcore SessionConfiguratorInterface or can I just use it like this:

$this->session = $requestStack->getSession(); $bag = new AttributeBag('my_name'); $this->session->registerBag($bag);

@solverat
Copy link
Contributor

@langert besides that your struggle is unrelated to this ticket: you need to register your bag via pimcore.session.configurator tag.

App\Session\SessionConfigurator:
  tags:
      - { name: pimcore.session.configurator } 
<?php

namespace App\Session;

use Pimcore\Session\SessionConfiguratorInterface;
use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

class SessionConfigurator implements SessionConfiguratorInterface
{
    public function configure(SessionInterface $session)
    {
        $bag = new NamespacedAttributeBag('_your_bag');
        $bag->setName('your_bag');
        $session->registerBag($bag);
    }
}

But I would suggest using the $request->getSession() method instead.

@dvesh3
Copy link
Contributor

dvesh3 commented Nov 25, 2021

We are not using namespaces for session storage items in the core, so I would suggest we simply replace the NamespacedAttributeBag usages with AttributeBag instead of re-implementing it in the core.

@dvesh3 dvesh3 changed the title [Improvement]: Implement NamespacedAttributeBag replacement [Symfony] Do not use Session deprecated features Nov 25, 2021
dvesh3 added a commit that referenced this issue Nov 25, 2021
dvesh3 added a commit that referenced this issue Nov 26, 2021
fashxp pushed a commit that referenced this issue Dec 14, 2021
* [Symfony] Session - Do not use deprecated session service - resolves #10345

* [Symfony] Session - use AttributeBag instead of deprecated NamespacedAttributeBag - resolves #10345

* [Symfony] Session - Do not use deprecated session service - resolves #10345

* [Symfony] Session - Do not use deprecated session service - resolves #10345

* [Symfony] Session - Do not use deprecated session service - fix tests resolves #10345

* [Symfony] Session - Do not use deprecated session service - bump symfony/framework-bundle requirement #10345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants