Skip to content

Commit

Permalink
Compatibility with Symfony 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jperovic committed Dec 2, 2023
1 parent a0cda69 commit 7614d0e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 21 deletions.
5 changes: 2 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('exploring_status');
$treeBuilder = new TreeBuilder('exploring_status');

$rootNode
$treeBuilder->getRootNode()
->children()
->enumNode('engine')->values(array('apc', 'session'))->defaultValue("apc")->end()
->end();
Expand Down
5 changes: 0 additions & 5 deletions DependencyInjection/StatusStoreCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,5 @@ public function process(ContainerBuilder $container)
{
$container->getDefinition("exploring_status.manager")
->setArguments(array(new Reference($container->getParameter("exploring_status.engine"))));

// We need to register the custom flash bag
if ( $container->getParameter("exploring_status.engine") == "exploring_status.session_engine" ) {
$container->getDefinition('session')->addMethodCall('registerBag', array(new Reference('exploring_status.flashbag')));
}
}
}
9 changes: 2 additions & 7 deletions Engine/SessionStatusEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use Exploring\StatusBundle\Data\StatusObject;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

class SessionStatusEngine implements StatusEngineInterface
{
Expand All @@ -12,13 +11,9 @@ class SessionStatusEngine implements StatusEngineInterface
*/
private $bag;

/**
* @param SessionInterface $session
* @param string $bagName
*/
function __construct(SessionInterface $session, $bagName)
public function __construct(FlashBag $bag)
{
$this->bag = $session->getBag($bagName);
$this->bag = $bag;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
</service>

<service id="exploring_status.session_engine" class="%exploring_status.session_engine.class%" public="false">
<argument type="service" id="session"/>
<argument type="string">%exploring_status.flashbag_name%</argument>
<argument type="service" id="exploring_status.flashbag"/>
</service>

<service id="exploring_status.apc_engine" class="%exploring_status.apc_engine.class%" public="false">
Expand All @@ -37,5 +36,11 @@
<argument type="string">%exploring_status.flashbag_name%</argument>
</call>
</service>

<service id="exploring_status.request_listener" class="Exploring\StatusBundle\Service\RequestListener">
<argument>%exploring_status.engine%</argument>
<argument type="service" id="exploring_status.flashbag"/>
<tag name="kernel.event_listener" event="kernel.request" priority="15"/>
</service>
</services>
</container>
30 changes: 30 additions & 0 deletions Service/RequestListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Exploring\StatusBundle\Service;

use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpKernel\Event\RequestEvent;

class RequestListener
{
private $statusEngineType;

private $flashBag;

public function __construct($statusEngineType, FlashBag $flashBag)
{
$this->statusEngineType = $statusEngineType;
$this->flashBag = $flashBag;
}

public function onKernelRequest(RequestEvent $event)
{
$session = $event->getRequest()->getSession();

// We need to register the custom flash bag
if ( $this->statusEngineType === "exploring_status.session_engine" && !$session->isStarted() )
{
$session->registerBag($this->flashBag);
}
}
}
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
"type": "library",
"description": "Operation status announcer",
"require": {
"php": ">=5.3.3",
"symfony/http-foundation": "2.*|3.*|4.*|5.*",
"twig/twig": "^1.27|^2.0"
"php": ">=7.1",
"symfony/http-foundation": "^5.4|6.*",
"twig/twig": "^2.0|^3.0",
"symfony/config": "^5.4|6.*",
"symfony/dependency-injection": "^5.4|6.*",
"symfony/http-kernel": "^5.4"
},
"target-dir": "Exploring/StatusBundle",
"minimum-stability": "dev",
"minimum-stability": "stable",
"autoload": {
"psr-0": {
"": "./"
Expand Down

0 comments on commit 7614d0e

Please sign in to comment.