Skip to content

Commit 2cb5457

Browse files
committed
Leverage Symfony 3.3+ Autowiring
1 parent 77e944b commit 2cb5457

File tree

12 files changed

+70
-66
lines changed

12 files changed

+70
-66
lines changed

DependencyInjection/Compiler/CollectFilterPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1212
use Symfony\Component\DependencyInjection\ContainerBuilder;
1313
use Symfony\Component\DependencyInjection\Reference;
14+
use Webfactory\Bundle\LegacyIntegrationBundle\EventListener\LegacyApplicationDispatchingEventListener;
1415

1516
class CollectFilterPass implements CompilerPassInterface
1617
{
1718
public function process(ContainerBuilder $container)
1819
{
19-
$kernelEventListenerDefinition = $container->getDefinition('webfactory_legacy_integration.kernel_event_listener');
20+
$kernelEventListenerDefinition = $container->getDefinition(LegacyApplicationDispatchingEventListener::class);
2021

2122
foreach ($container->findTaggedServiceIds('webfactory_legacy_integration.filter') as $id => $tags) {
2223
$kernelEventListenerDefinition->addMethodCall('addFilter', [

DependencyInjection/WebfactoryLegacyIntegrationExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public function load(array $configs, ContainerBuilder $container)
2727

2828
switch (@$config['parsingMode']) {
2929
case 'html5':
30-
$container->setParameter('webfactory_legacy_integration.parser_class', 'Webfactory\Dom\PolyglotHTML5ParsingHelper');
30+
$container->setParameter('webfactory_legacy_integration.parser_class', Webfactory\Dom\PolyglotHTML5ParsingHelper::class);
3131
break;
3232
case 'xhtml10':
33-
$container->setParameter('webfactory_legacy_integration.parser_class', 'Webfactory\Dom\XHTML10ParsingHelper');
33+
$container->setParameter('webfactory_legacy_integration.parser_class', Webfactory\Dom\XHTML10ParsingHelper::class);
3434
break;
3535
}
3636
}

EventListener/LegacyApplicationDispatchingEventListener.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,30 @@
99
namespace Webfactory\Bundle\LegacyIntegrationBundle\EventListener;
1010

1111
use Doctrine\Common\Annotations\Reader;
12-
use Symfony\Component\DependencyInjection\ContainerInterface;
1312
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
14-
use Symfony\Component\HttpKernel\HttpKernelInterface;
1513
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Dispatch;
1614
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter;
15+
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\LegacyApplication;
1716

1817
class LegacyApplicationDispatchingEventListener
1918
{
20-
protected $container;
19+
/**
20+
* @var LegacyApplication
21+
*/
22+
private $legacyApplication;
23+
2124
protected $reader;
25+
2226
protected $stopwatch;
2327

2428
/**
2529
* @var Filter[]
2630
*/
2731
protected $filters = [];
2832

29-
public function __construct(ContainerInterface $container, Reader $reader)
33+
public function __construct(LegacyApplication $legacyApplication, Reader $reader)
3034
{
31-
$this->container = $container;
35+
$this->legacyApplication = $legacyApplication;
3236
$this->reader = $reader;
3337
}
3438

@@ -55,7 +59,7 @@ public function onKernelController(FilterControllerEvent $event)
5559
}
5660

5761
if ($dispatch) {
58-
$response = $this->getLegacyApplication()->handle($event->getRequest(), $event->getRequestType(), false);
62+
$response = $this->legacyApplication->handle($event->getRequest(), $event->getRequestType(), false);
5963

6064
foreach ($this->filters as $filter) {
6165
$filter->filter($event, $response);
@@ -65,12 +69,4 @@ public function onKernelController(FilterControllerEvent $event)
6569
}
6670
}
6771
}
68-
69-
/**
70-
* @return HttpKernelInterface
71-
*/
72-
protected function getLegacyApplication()
73-
{
74-
return $this->container->get('webfactory_legacy_integration.legacy_application');
75-
}
7672
}

Integration/Annotation/Filter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation;
1010

11-
use Symfony\Component\DependencyInjection\Container;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
1212
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter as FilterInterface;
1313
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory;
1414

@@ -33,7 +33,7 @@ public function __construct($values)
3333
}
3434
}
3535

36-
public function createFilter(Container $container)
36+
public function createFilter(ContainerInterface $container)
3737
{
3838
if ($class = $this->class) {
3939
if (!class_exists($class)) {

Integration/Annotation/IgnoreHeader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation;
1010

11-
use Symfony\Component\DependencyInjection\Container;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
1212
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory;
1313
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\IgnoreHeader as IgnoreHeaderFilter;
1414

@@ -27,7 +27,7 @@ public function __construct(array $values)
2727
}
2828
}
2929

30-
public function createFilter(Container $container)
30+
public function createFilter(ContainerInterface $container)
3131
{
3232
return new IgnoreHeaderFilter($this->header);
3333
}

Integration/Annotation/IgnoreRedirect.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation;
1010

11-
use Symfony\Component\DependencyInjection\Container;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
1212
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory;
1313
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\IgnoreRedirect as IgnoreRedirectFilter;
1414

@@ -17,7 +17,7 @@
1717
*/
1818
class IgnoreRedirect implements Factory
1919
{
20-
public function createFilter(Container $container)
20+
public function createFilter(ContainerInterface $container)
2121
{
2222
return new IgnoreRedirectFilter();
2323
}

Integration/Annotation/Passthru.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation;
1010

11-
use Symfony\Component\DependencyInjection\Container;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
1212
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory;
1313
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\PassthruLegacyResponseFilter;
1414

@@ -17,7 +17,7 @@
1717
*/
1818
class Passthru implements Factory
1919
{
20-
public function createFilter(Container $container)
20+
public function createFilter(ContainerInterface $container)
2121
{
2222
return new PassthruLegacyResponseFilter();
2323
}

Integration/Filter/ControllerAnnotations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter;
1010

1111
use Doctrine\Common\Annotations\Reader;
12-
use Symfony\Component\DependencyInjection\Container;
12+
use Symfony\Component\DependencyInjection\ContainerInterface;
1313
use Symfony\Component\HttpFoundation\Response;
1414
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
1515
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter as FilterInterface;
@@ -19,7 +19,7 @@ class ControllerAnnotations implements FilterInterface
1919
protected $reader;
2020
protected $container;
2121

22-
public function __construct(Reader $reader, Container $container)
22+
public function __construct(Reader $reader, ContainerInterface $container)
2323
{
2424
$this->reader = $reader;
2525
$this->container = $container;

Integration/Filter/Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter;
1010

11-
use Symfony\Component\DependencyInjection\Container;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
1212

1313
interface Factory
1414
{
15-
public function createFilter(Container $container);
15+
public function createFilter(ContainerInterface $container);
1616
}

Resources/config/services.xml

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,51 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66
<services>
7+
<defaults autowire="true" autoconfigure="true" />
78

89
<service id="Webfactory\Bundle\LegacyIntegrationBundle\Integration\BootstrapFileKernelAdaptor">
910
<argument>%webfactory_legacy_integration.legacy_application_bootstrap_file%</argument>
1011
</service>
1112

12-
<service id="webfactory_legacy_integration.legacy_kernel"
13-
alias="Webfactory\Bundle\LegacyIntegrationBundle\Integration\BootstrapFileKernelAdaptor" />
13+
<service id="webfactory_legacy_integration.legacy_kernel" alias="Webfactory\Bundle\LegacyIntegrationBundle\Integration\BootstrapFileKernelAdaptor" />
1414

15-
<service
16-
id="webfactory_legacy_integration.legacy_application"
17-
class="Webfactory\Bundle\LegacyIntegrationBundle\Integration\LegacyApplication"
18-
public="true">
15+
<service id="Webfactory\Bundle\LegacyIntegrationBundle\Integration\LegacyApplication">
1916
<call method="setLegacyKernel">
2017
<argument type="service" id="webfactory_legacy_integration.legacy_kernel" />
2118
</call>
2219
</service>
20+
<service id="webfactory_legacy_integration.legacy_application" alias="Webfactory\Bundle\LegacyIntegrationBundle\Integration\LegacyApplication" public="true" />
2321

24-
<service id="webfactory_legacy_integration.kernel_event_listener"
25-
class="Webfactory\Bundle\LegacyIntegrationBundle\EventListener\LegacyApplicationDispatchingEventListener">
26-
<argument type="service" id="service_container"/>
27-
<argument type="service" id="annotation_reader"/>
22+
<service id="Webfactory\Bundle\LegacyIntegrationBundle\EventListener\LegacyApplicationDispatchingEventListener">
2823
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController" priority="-210" />
2924
</service>
3025

31-
<service id="webfactory_legacy_integration.controller_annotations_filter" class="Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\ControllerAnnotations">
32-
<argument type="service" id="annotation_reader"/>
33-
<argument type="service" id="service_container"/>
26+
<service id="Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\ControllerAnnotations">
3427
<tag name="webfactory_legacy_integration.filter"/>
3528
</service>
3629

37-
<service id="webfactory_legacy_integration.keep_cookies_filter" class="Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\KeepCookiesAndHeadersFilter">
38-
<argument type="service" id="annotation_reader"/>
30+
<service id="Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\KeepCookiesAndHeadersFilter">
3931
<tag name="webfactory_legacy_integration.filter"/>
4032
<tag name="kernel.event_listener" event="kernel.response"/>
4133
</service>
4234

43-
<service id="webfactory_legacy_integration.twig_extension" class="Webfactory\Bundle\LegacyIntegrationBundle\Twig\Extension">
44-
<argument type="service" id="service_container"/>
35+
<service id="Webfactory\Bundle\LegacyIntegrationBundle\Twig\Extension">
4536
<tag name="twig.extension"/>
37+
<tag name="container.service_subscriber" />
4638
</service>
4739

48-
<service id="webfactory_legacy_integration.xpath_helper_factory"
49-
class="Webfactory\Bundle\LegacyIntegrationBundle\Integration\XPathHelperFactory">
40+
<service id="Webfactory\Bundle\LegacyIntegrationBundle\Integration\XPathHelperFactory">
5041
<argument type="service">
5142
<service class="%webfactory_legacy_integration.parser_class%"/>
5243
</argument>
53-
<argument type="service" id="webfactory_legacy_integration.legacy_application"/>
44+
<argument type="service" id="Webfactory\Bundle\LegacyIntegrationBundle\Integration\LegacyApplication"/>
5445
<argument type="service" id="logger" on-invalid="null" />
5546
<tag name="monolog.logger" channel="webfactory_legacy_integration" />
5647
</service>
5748

58-
<service id="webfactory_legacy_integration.xpath_helper" public="true"
59-
class="Webfactory\Bundle\LegacyIntegrationBundle\Integration\XPathHelper">
60-
<factory service="webfactory_legacy_integration.xpath_helper_factory" method="createHelper" />
49+
<service id="Webfactory\Bundle\LegacyIntegrationBundle\Integration\XPathHelper">
50+
<factory service="Webfactory\Bundle\LegacyIntegrationBundle\Integration\XPathHelperFactory" method="createHelper" />
6151
</service>
62-
52+
<service id="webfactory_legacy_integration.xpath_helper" alias="Webfactory\Bundle\LegacyIntegrationBundle\Integration\XPathHelper" public="true" />
6353
</services>
6454
</container>

0 commit comments

Comments
 (0)