Skip to content

Commit

Permalink
Fix session bag
Browse files Browse the repository at this point in the history
  • Loading branch information
zonky2 committed May 21, 2024
1 parent df33115 commit 32f7f7d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Contao/Factory/SessionStorageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2023 Contao Community Alliance.
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,7 +13,7 @@
* @package contao-community-alliance/dc-general
* @author Sven Baumann <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2023 Contao Community Alliance.
* @copyright 2013-2024 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand All @@ -34,7 +34,7 @@ class SessionStorageFactory
*
* @var ContainerInterface
*/
private $container;
private ContainerInterface $container;

/**
* SessionStorageFactory constructor.
Expand All @@ -53,7 +53,7 @@ public function __construct(ContainerInterface $container)
*/
public function createService()
{
$session = $this->container->get('session');
$session = $this->container->get('request_stack')?->getSession();
assert($session instanceof SessionInterface);
$keys = $this->container->getParameter('cca.dc-general.session.database_keys');
assert(\is_array($keys));
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ services:
calls:
- ["setName", ["cca_dc_general"]]

ContaoCommunityAlliance\DcGeneral\SymfonyBridge\SessionFactory:
arguments:
- "@ContaoCommunityAlliance\\DcGeneral\\SymfonyBridge\\SessionFactory.inner"
- "@cca.dc-general.session_attribute"
decorates: session.factory

cca.dc-general.edit-information:
class: ContaoCommunityAlliance\DcGeneral\Data\DefaultEditInformation
public: true
Expand Down
44 changes: 44 additions & 0 deletions src/SymfonyBridge/SessionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package contao-community-alliance/dc-general
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2024 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

declare(strict_types=1);

namespace ContaoCommunityAlliance\DcGeneral\SymfonyBridge;

use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionFactoryInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

class SessionFactory implements SessionFactoryInterface
{
public function __construct(
readonly private SessionFactoryInterface $inner,
readonly private SessionBagInterface $dcGeneralBag,
) {
}

public function createSession(): SessionInterface
{
$session = $this->inner->createSession();

$session->registerBag($this->dcGeneralBag);

return $session;
}
}

0 comments on commit 32f7f7d

Please sign in to comment.