Skip to content

Commit c4ca077

Browse files
author
roissard
committed
Add support for Symfony 4 (Symfony 2.7 is still supported)
1 parent a8c4cf9 commit c4ca077

File tree

8 files changed

+248
-32
lines changed

8 files changed

+248
-32
lines changed

src/Voryx/ThruwayBundle/Command/ThruwayProcessCommand.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ class ThruwayProcessCommand extends ContainerAwareCommand
4848
*/
4949
private $consoleCommand;
5050

51+
/**
52+
* @var \Psr\Log\LoggerInterface $logger
53+
*/
54+
private $logger;
55+
56+
/**
57+
* @required
58+
*/
59+
public function setLogger(\Psr\Log\LoggerInterface $logger)
60+
{
61+
$this->logger = $logger;
62+
}
63+
5164
/**
5265
* {@inheritdoc}
5366
*/
@@ -143,8 +156,7 @@ private function startManager()
143156
$this->processManager->start();
144157

145158
} catch (\Exception $e) {
146-
$logger = $this->getContainer()->get('logger');
147-
$logger->addCritical('EXCEPTION:' . $e->getMessage());
159+
$this->logger->addCritical('EXCEPTION:' . $e->getMessage());
148160
$this->output->writeln('EXCEPTION:' . $e->getMessage());
149161
}
150162
}

src/Voryx/ThruwayBundle/Command/ThruwayRouterCommand.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99

1010
class ThruwayRouterCommand extends ContainerAwareCommand
1111
{
12+
13+
/**
14+
* @var \Psr\Log\LoggerInterface $logger
15+
*/
16+
private $logger;
17+
18+
/**
19+
* @required
20+
*/
21+
public function setLogger(\Psr\Log\LoggerInterface $logger)
22+
{
23+
$this->logger = $logger;
24+
}
25+
1226
/**
1327
* {@inheritdoc}
1428
*/
@@ -42,8 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4256
$server->start();
4357

4458
} catch (\Exception $e) {
45-
$logger = $this->getContainer()->get('logger');
46-
$logger->addCritical('EXCEPTION:' . $e->getMessage());
59+
$this->logger->addCritical('EXCEPTION:' . $e->getMessage());
4760
$output->writeln('EXCEPTION:' . $e->getMessage());
4861
}
4962
}

src/Voryx/ThruwayBundle/Command/ThruwayWorkerCommand.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111

1212
class ThruwayWorkerCommand extends ContainerAwareCommand
1313
{
14+
15+
/**
16+
* @var \Psr\Log\LoggerInterface $logger
17+
*/
18+
private $logger;
19+
20+
/**
21+
* @required
22+
*/
23+
public function setLogger(\Psr\Log\LoggerInterface $logger)
24+
{
25+
$this->logger = $logger;
26+
}
27+
1428
/**
1529
* {@inheritdoc}
1630
*/
@@ -59,8 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5973
$client->start();
6074

6175
} catch (\Exception $e) {
62-
$logger = $this->getContainer()->get('logger');
63-
$logger->addCritical('EXCEPTION:' . $e->getMessage());
76+
$this->logger->addCritical('EXCEPTION:' . $e->getMessage());
6477
$output->writeln('EXCEPTION:' . $e->getMessage());
6578
}
6679
}

src/Voryx/ThruwayBundle/DependencyInjection/Compiler/AnnotationConfigurationPass.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
use Symfony\Component\DependencyInjection\Definition;
88
use Symfony\Component\DependencyInjection\Reference;
99
use Symfony\Component\Finder\Finder;
10-
use Symfony\Component\HttpKernel\KernelInterface;
1110

1211
/**
1312
* Class AnnotationConfigurationPass
1413
* @package Voryx\ThruwayBundle\DependencyInjection\Compiler
1514
*/
1615
class AnnotationConfigurationPass implements CompilerPassInterface
1716
{
17+
1818
/**
19-
* @var KernelInterface
19+
* @var array
2020
*/
21-
private $kernel;
21+
private $bundles;
2222

2323
/**
24-
* @param KernelInterface $kernel
24+
* @param array $bundles
2525
*/
26-
public function __construct(KernelInterface $kernel)
26+
public function __construct(array $bundles)
2727
{
28-
$this->kernel = $kernel;
28+
$this->bundles = $bundles;
2929
}
3030

3131
/**
@@ -67,7 +67,7 @@ private function getBundleFiles(ContainerBuilder $container)
6767

6868
$config = $container->getParameter('voryx_thruway');
6969
$scanBundles = $config['locations']['bundles'];
70-
$bundles = $this->kernel->getBundles();
70+
$bundles = $this->bundles;
7171
$files = [];
7272

7373
foreach ($bundles as $name => $bundle) {
@@ -76,7 +76,7 @@ private function getBundleFiles(ContainerBuilder $container)
7676
}
7777

7878
$finder = new Finder();
79-
$finder->files()->in($bundle->getPath())->name('*.php')->contains('Voryx\ThruwayBundle\Annotation')->depth('< 5');
79+
$finder->files()->in($bundle['path'])->name('*.php')->contains('Voryx\ThruwayBundle\Annotation')->depth('< 5');
8080

8181
/* @var $file \Symfony\Component\Finder\SplFileInfo */
8282
foreach ($finder as $file) {

src/Voryx/ThruwayBundle/DependencyInjection/VoryxThruwayExtension.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ public function load(array $configs, ContainerBuilder $container)
2727
$config = $this->processConfiguration($configuration, $configs);
2828

2929
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
30-
$loader->load('services.xml');
30+
//var_dump($container);
31+
if (strpos(\Symfony\Component\HttpKernel\Kernel::VERSION, '2.7')===0)
32+
{
33+
$loader->load('services.2.7.xml');
34+
}
35+
else
36+
{
37+
$loader->load('services.xml');
38+
}
3139

3240
$this->validate($config);
3341

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<services>
8+
9+
<service id="voryx.thruway.loop" class="React\EventLoop\LoopInterface">
10+
<factory class="React\EventLoop\Factory" method="create" />
11+
</service>
12+
13+
<service id="voryx.thruway.ratchet.transport"
14+
class="Thruway\Transport\RatchetTransportProvider"
15+
public="false">
16+
<argument type="expression">parameter('voryx_thruway')['router']['ip']</argument>
17+
<argument type="expression">parameter('voryx_thruway')['router']['port']</argument>
18+
</service>
19+
20+
<service id="voryx.thruway.client"
21+
class="Thruway\Peer\Client">
22+
<argument type="expression">parameter('voryx_thruway')['realm']</argument>
23+
</service>
24+
25+
<service id="voryx.thruway.web.push.client"
26+
class="Voryx\ThruwayBundle\Client\WebPushClient"
27+
public="false">
28+
<argument type="expression">parameter('voryx_thruway')['realm']</argument>
29+
</service>
30+
31+
<service id="voryx.thruway.internal.transport"
32+
class="Thruway\Transport\InternalClientTransportProvider"
33+
public="false">
34+
<argument type="service" id="voryx.thruway.client"/>
35+
</service>
36+
37+
<service id="voryx.thruway.internal.manager"
38+
class="Thruway\Transport\InternalClientTransportProvider"
39+
public="false">
40+
</service>
41+
42+
<service id="voryx.thruway.internal.web.push"
43+
class="Thruway\Transport\InternalClientTransportProvider"
44+
public="false">
45+
<argument type="service" id="voryx.thruway.web.push.client"/>
46+
</service>
47+
48+
<service id="voryx.thruway.server" class="Thruway\Peer\Router" public="true">
49+
<argument type="service" id="voryx.thruway.loop"/>
50+
<call method="addTransportProvider">
51+
<argument type="service" id="voryx.thruway.ratchet.transport"/>
52+
</call>
53+
<!--<call method="addTransportProvider">-->
54+
<!--<argument type="service" id="voryx.thruway.internal.transport"/>-->
55+
<!--</call>-->
56+
</service>
57+
58+
<service id="voryx.thruway.resource.mapper"
59+
class="Voryx\ThruwayBundle\ResourceMapper">
60+
<argument type="service" id="annotation_reader"/>
61+
</service>
62+
63+
<service id="get_set_stdClass_normalizer" class="Voryx\ThruwayBundle\Serialization\StdClassNormalizer" public="false">
64+
<tag name="serializer.normalizer" />
65+
</service>
66+
67+
<service id="wamp_kernel" class="Voryx\ThruwayBundle\WampKernel" public="true">
68+
<argument type="service" id="service_container"/>
69+
<argument type="service" id="serializer"/>
70+
<argument type="service" id="voryx.thruway.resource.mapper"/>
71+
<argument type="service" id="event_dispatcher"/>
72+
<argument type="service" id="logger"/>
73+
</service>
74+
75+
<service id="thruway_container" class="Symfony\Component\DependencyInjection\Container">
76+
<factory class="Voryx\ThruwayBundle\ContainerFactory" method="createContainer"/>
77+
<argument type="expression">parameter('kernel.container_class')</argument>
78+
<argument type="service" id="thruway.client"/>
79+
<argument type="service" id="voryx.thruway.loop"/>
80+
<argument type="service" id="service_container"/>
81+
</service>
82+
83+
<service id="thruway.details" class="Voryx\ThruwayBundle\Details"/>
84+
85+
<!--Authentication-->
86+
<service id="voryx.thruway.authentication.manager"
87+
class="Thruway\Authentication\AuthenticationManager"
88+
public="false">
89+
<argument type="service" id="voryx.thruway.client"/>
90+
</service>
91+
92+
<service id="voryx.thruway.auth.manager.transport.provider"
93+
class="Thruway\Transport\InternalClientTransportProvider"
94+
public="false">
95+
<argument type="service" id="voryx.thruway.authentication.manager"/>
96+
</service>
97+
98+
<service id="voryx.thruway.user.db"
99+
class="Voryx\ThruwayBundle\Authentication\UserDB"
100+
public="false">
101+
<argument type="service" id="service_container"/>
102+
</service>
103+
104+
<service id="voryx.thruway.wamp.cra.auth.client"
105+
class="Thruway\Authentication\WampCraAuthProvider">
106+
<argument type="expression">[parameter('voryx_thruway')['realm']]</argument>
107+
<call method="setUserDb">
108+
<argument type="service" id="voryx.thruway.user.db"/>
109+
</call>
110+
</service>
111+
112+
<service id="voryx.thruway.wamp.cra.auth.transport.provider"
113+
class="Thruway\Transport\InternalClientTransportProvider">
114+
<argument type="service" id="voryx.thruway.wamp.cra.auth.client"/>
115+
</service>
116+
117+
<!--Main Thruway Client-->
118+
<service id="thruway.client"
119+
class="Voryx\ThruwayBundle\Client\ClientManager">
120+
<argument type="service" id="service_container"/>
121+
<argument>%voryx_thruway%</argument>
122+
<argument type="service" id="serializer"/>
123+
</service>
124+
125+
<service id="voryx.thruway.topic_state_handler" class="Voryx\ThruwayBundle\TopicStateHandler">
126+
<tag name="kernel.event_listener" event="wamp.open" method="onOpen"/>
127+
</service>
128+
129+
<!-- Topic State Handler -->
130+
<service id="voryx.thruway.topic.state.handler"
131+
class="Thruway\Subscription\StateHandlerRegistry"
132+
public="false">
133+
<argument type="expression">parameter('voryx_thruway')['realm']</argument>
134+
<argument type="service" id="voryx.thruway.loop"/>
135+
</service>
136+
137+
<!-- Register command as public services and enable autowiring -->
138+
<service id="thruway.command.debug" class="Voryx\ThruwayBundle\Command\ThruwayDebugCommand" public="true">
139+
<tag name="console.command" command="thruway:debug" />
140+
</service>
141+
142+
<service id="thruway.command.process" class="Voryx\ThruwayBundle\Command\ThruwayProcessCommand" public="true">
143+
<tag name="console.command" command="thruway:process" />
144+
</service>
145+
146+
<service id="thruway.command.router" class="Voryx\ThruwayBundle\Command\ThruwayRouterCommand" public="true">
147+
<tag name="console.command" command="thruway:router:start" />
148+
</service>
149+
150+
<service id="thruway.command.worker" class="Voryx\ThruwayBundle\Command\ThruwayWorkerCommand" public="true">
151+
<tag name="console.command" command="thruway:worker:start" />
152+
</service>
153+
154+
</services>
155+
</container>

src/Voryx/ThruwayBundle/Resources/config/services.xml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<argument type="service" id="voryx.thruway.web.push.client"/>
4646
</service>
4747

48-
<service id="voryx.thruway.server" class="Thruway\Peer\Router">
48+
<service id="voryx.thruway.server" class="Thruway\Peer\Router" public="true">
4949
<argument type="service" id="voryx.thruway.loop"/>
5050
<call method="addTransportProvider">
5151
<argument type="service" id="voryx.thruway.ratchet.transport"/>
@@ -64,7 +64,7 @@
6464
<tag name="serializer.normalizer" />
6565
</service>
6666

67-
<service id="wamp_kernel" class="Voryx\ThruwayBundle\WampKernel">
67+
<service id="wamp_kernel" class="Voryx\ThruwayBundle\WampKernel" public="true">
6868
<argument type="service" id="service_container"/>
6969
<argument type="service" id="serializer"/>
7070
<argument type="service" id="voryx.thruway.resource.mapper"/>
@@ -133,5 +133,23 @@
133133
<argument type="expression">parameter('voryx_thruway')['realm']</argument>
134134
<argument type="service" id="voryx.thruway.loop"/>
135135
</service>
136+
137+
<!-- Register command as public services and enable autowiring -->
138+
<service id="thruway.command.debug" class="Voryx\ThruwayBundle\Command\ThruwayDebugCommand" autowire="true" public="true">
139+
<tag name="console.command" command="thruway:debug" />
140+
</service>
141+
142+
<service id="thruway.command.process" class="Voryx\ThruwayBundle\Command\ThruwayProcessCommand" autowire="true" public="true">
143+
<tag name="console.command" command="thruway:process" />
144+
</service>
145+
146+
<service id="thruway.command.router" class="Voryx\ThruwayBundle\Command\ThruwayRouterCommand" autowire="true" public="true">
147+
<tag name="console.command" command="thruway:router:start" />
148+
</service>
149+
150+
<service id="thruway.command.worker" class="Voryx\ThruwayBundle\Command\ThruwayWorkerCommand" autowire="true" public="true">
151+
<tag name="console.command" command="thruway:worker:start" />
152+
</service>
153+
136154
</services>
137155
</container>

0 commit comments

Comments
 (0)