Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gertvdb committed Dec 27, 2019
1 parent c3b47d5 commit 991079f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 26 deletions.
3 changes: 1 addition & 2 deletions DependencyInjection/Compiler/KernelConfigurationPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class KernelConfigurationPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{



$kernelId = $container->getParameter('legacy_bridge_bundle.legacy_kernel.id');
$kernelOptions = $container->getParameter('legacy_bridge_bundle.legacy_kernel.options');
$classLoaderId = $this->getClassLoaderId($container);
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Compiler/ReplaceRouterPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function process(ContainerBuilder $container)
if ($container->hasDefinition('legacy_bridge_bundle.router_listener') === true) {
// First get te default router_listener.
$routerListener = $container->getDefinition('router_listener');

// Then get our custom route listener and inject the default route listener.
$definition = $container->getDefinition('legacy_bridge_bundle.router_listener');
$definition->replaceArgument(1, $routerListener);
$definition->replaceArgument(0, $routerListener);

// Remap the route_listener service to our custom route listener.
$container->setAlias('router_listener', 'legacy_bridge_bundle.router_listener');
Expand Down
8 changes: 4 additions & 4 deletions DependencyInjection/LegacyBridgeBundleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;


/**
* This is the class that loads and manages your bundle configuration
Expand All @@ -30,14 +32,12 @@ class LegacyBridgeBundleExtension extends Extension
public function load(array $configs, ContainerBuilder $container)
{

// Get the xml file loader.
$loader = new Loader\XmlFileLoader(
$loader = new XmlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config')
);

// Load the services.xml file.
$loader->load('services.xml');


// Register composer class loader.
$container->register('composer.loader', 'Composer\Autoload\ClassLoader');
Expand Down
2 changes: 1 addition & 1 deletion Event/LegacyKernelBootEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
*
*/
namespace Tactics\LegacyBridgeBundle\Kernel;
namespace Tactics\LegacyBridgeBundle\Event;

/**
* Interface LegacyKernelInterface
Expand Down
2 changes: 2 additions & 0 deletions EventListener/LegacyBooterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public function __construct(
*/
public function onKernelRequest(RequestEvent $event)
{


if ($this->kernel->isBooted() === false) {
$this->kernel->boot($this->container);
}
Expand Down
29 changes: 16 additions & 13 deletions EventListener/RouterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class RouterListener implements EventSubscriberInterface


/**
* @param LegacyKernelInterface $legacyKernel
* @param SymfonyRouterListener $routerListener
* @param LegacyKernelInterface $legacyKernel
* @param LoggerInterface $logger
*/
public function __construct(LegacyKernelInterface $legacyKernel, SymfonyRouterListener $routerListener, LoggerInterface $logger=null)
public function __construct(SymfonyRouterListener $routerListener, LegacyKernelInterface $legacyKernel=null, LoggerInterface $logger=null)
{
$this->legacyKernel = $legacyKernel;
$this->routerListener = $routerListener;
Expand All @@ -68,17 +68,20 @@ public function onKernelRequest(RequestEvent $event)
$this->logger->info($message);
}

// When the request could not be dispatched through symfony 5
// we fallback to our legacy kernel to dispatch the request.
$response = $this->legacyKernel->handle(
$event->getRequest(),
$event->getRequestType(),
true
);

if ($response->getStatusCode() !== 404) {
$event->setResponse($response);
return $event;
if ($this->legacyKernel !== null) {

// When the request could not be dispatched through symfony 5
// we fallback to our legacy kernel to dispatch the request.
$response = $this->legacyKernel->handle(
$event->getRequest(),
$event->getRequestType(),
true
);

if ($response->getStatusCode() !== 404) {
$event->setResponse($response);
return $event;
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion LegacyBridgeBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use Composer\Autoload\ClassLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Tactics\LegacyBridgeBundle\DependencyInjection\Compiler\KernelConfigurationPass;
use Tactics\LegacyBridgeBundle\DependencyInjection\Compiler\LoaderInjectorPass;
use Tactics\LegacyBridgeBundle\DependencyInjection\Compiler\ReplaceRouterPass;
use Tactics\LegacyBridgeBundle\DependencyInjection\LegacyBridgeBundleExtension;

/**
* Class LegacyBridgeBundle
Expand Down Expand Up @@ -41,7 +43,12 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new LoaderInjectorPass($this->loader));
}

//$container->addCompilerPass(new KernelConfigurationPass());
$container->addCompilerPass(new KernelConfigurationPass());
$container->addCompilerPass(new ReplaceRouterPass());
}

public function getContainerExtension()
{
return new LegacyBridgeBundleExtension();
}
}
12 changes: 9 additions & 3 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<parameters>
<parameter key="legacy_bridge_bundle.router_listener.class">Tactics\LegacyBridgeBundle\EventListener\RouterListener</parameter>
<parameter key="legacy_bridge_bundle.legacy_booter_listener.class">Tactics\LegacyBridgeBundle\EventListener\LegacyBooterListener</parameter>
</parameters>

<services>
Expand All @@ -14,14 +15,19 @@
Later on we can dive deeper into the autowire functionality.
-->

<service id="legacy_bridge_bundle.router_listener" class="%legacy_bridge_bundle.router_listener.class%">
<service id="legacy_bridge_bundle.router_listener" class="%legacy_bridge_bundle.router_listener.class%" autowire="true">
<tag name="kernel.event_subscriber" />
<tag name="monolog.logger" channel="event" />
<argument type="service" id="legacy_bridge_bundle.legacy_kernel" />
<argument type="service" id="router_listener" />
<argument type="service" id="legacy_bridge_bundle.legacy_kernel" />
<argument type="service" id="logger" on-invalid="ignore" />
</service>

<service id="legacy_bridge_bundle.router_listener" class="" autowire="false"/>
<service id="legacy_bridge_bundle.legacy_booter_listener" class="%legacy_bridge_bundle.legacy_booter_listener.class%" autowire="true">
<tag name="kernel.event_subscriber" />
<argument type="service" id="legacy_bridge_bundle.legacy_kernel" />
<argument type="service" id="service_container" />
</service>

</services>
</container>

0 comments on commit 991079f

Please sign in to comment.