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

Rector the Contao\Session class #12

Open
aschempp opened this issue Aug 19, 2024 · 0 comments
Open

Rector the Contao\Session class #12

aschempp opened this issue Aug 19, 2024 · 0 comments

Comments

@aschempp
Copy link
Member

Deprecated since Contao: 4.0

Before:

\Contao\Session::getInstance()->get('foo');
\Contao\Session::getInstance()->set('foo', 'bar');
\Contao\Session::getInstance()->remove('foo');
\Contao\Session::getInstance()->getData();
\Contao\Session::getInstance()->setData($foo);

After:

// $sesionBag would need to be an inline call I guess
$sessionBag = \System::getContainer()->get('request_stack')->getSession()->getBag(
    \Contao\System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest(
        \Contao\System::getContainer()->get('request_stack')->getCurrentRequest() ?? \Symfony\Component\HttpFoundation\Request::create('')
    ) ? 'contao_backend' : (
        \Contao\System::getContainer()->get('contao.routing.scope_matcher')->isFrontendRequest(
            \Contao\System::getContainer()->get('request_stack')->getCurrentRequest() ?? \Symfony\Component\HttpFoundation\Request::create('')
        ) ? 'contao_frontend' : 'attributes'
    )
);

$sessionBag->get('foo');

$sessionBag->set('foo', 'bar');

$sessionBag->remove('foo');

$sessionBag->all();

$sessionBag->replace($foo);

Additional information:

If $key if referer, popupReferer or CURRENT_ID, the access should be to $session->get(...) instead of the session bag. Not sure if that's really worth it though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant