Rector the Contao\Session class
aschempp opened this issue · 0 comments
aschempp commented
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.