Skip to content

Commit 319f7fc

Browse files
authored
chore: support symfony 5 (#75)
* chore: support symfony 5 DataCollector::collect method signature change since SF 4.4 * fix: travis config + doc * fix: swap arguments of dispatch() @see symfony/symfony@75369da * fix: renamed events GetResponseForExceptionEvent replaced by ExceptionEvent; PostResponseEvent replaced by TerminateEvent; * refactor: use the spaceless filter instead of spaceless tag (since Twig 1.38) * chore: only needed symfony dependencies * chore: CI : php compatibility for SF5 (>=7.2.5) * style: remove spaceless filter * add new line at the end of the file
1 parent 94941d9 commit 319f7fc

13 files changed

Lines changed: 63 additions & 54 deletions

File tree

.travis.yml

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

99
env:
10-
- SYMFONY_VERSION=3.4.0
11-
- SYMFONY_VERSION=4.0.*
10+
- SYMFONY_VERSION=4.4.0
11+
- SYMFONY_VERSION=5.*.*
1212

1313
before_script:
1414
- wget http://getcomposer.org/composer.phar
@@ -18,3 +18,8 @@ before_script:
1818
script:
1919
- bin/coke
2020
- bin/atoum
21+
22+
jobs:
23+
exclude:
24+
- php: 7.1
25+
env: SYMFONY_VERSION=5.*.*

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ StatsdBundle [![Build Status](https://travis-ci.org/M6Web/StatsdBundle.png?branc
33

44
## Bundle easing the [statsd](https://github.com/etsy/statsd/) usage.
55

6-
This bundle currently supports `php >=7.1.3` and `symfony 3.4/4.x`.
6+
This bundle currently supports `php >=7.1.3` and `symfony 4.4/5.x`.
77

8+
If you need support for `symfony 3.4/<4.4`, use version [v3.0.0](https://github.com/M6Web/StatsdBundle/tree/v3.0.0).
89
If you need support for `php >=5.4.0` and `symfony 2.x/3.x`, use version [v2.15.1](https://github.com/M6Web/StatsdBundle/tree/v2.15.1).
910

1011
* [about](doc/about.md)

composer.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@
1313
],
1414
"config": {
1515
"bin-dir": "bin",
16-
"vendor-dir": "vendor"
16+
"vendor-dir": "vendor",
17+
"sort-packages": true
1718
},
1819
"require": {
1920
"php": "^7.1.3",
20-
"symfony/property-access": "^3.4 || ^4.0",
21+
"symfony/property-access": "^4.4 || ^5.0",
2122
"m6web/statsd": "^1.3"
2223
},
2324
"require-dev": {
2425
"atoum/atoum": "^2.8|^3.0",
25-
"symfony/symfony": "^3.4 || ^4.0 || ^5.0",
26-
"m6web/coke" : "~1.2",
27-
"m6web/symfony2-coding-standard" : "~1.2"
26+
"m6web/coke": "~1.2",
27+
"m6web/symfony2-coding-standard": "~1.2",
28+
"symfony/config": "^4.4 || ^5.0",
29+
"symfony/console": "^4.4 || ^5.0",
30+
"symfony/dependency-injection": "^4.4 || ^5.0",
31+
"symfony/event-dispatcher-contracts": "^1.1 || ^2.1",
32+
"symfony/http-foundation": "^4.4 || ^5.0",
33+
"symfony/http-kernel": "^4.4 || ^5.0"
2834
},
2935
"autoload": {
3036
"psr-4": {

doc/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ On the Symfony event dispatcher, when the ```forum.read``` event is fired, our s
7272

7373
So you can now just fire the event from a controller :
7474
```php
75-
$this->get('event_dispatcher')->dispatch('forum.read', new Symfony\Component\EventDispatcher\Event());
75+
$this->get('event_dispatcher')->dispatch(new Symfony\Contracts\EventDispatcher\Event(), 'forum.read');
7676
```
7777

7878
It's also possible to create tokens in the Symfony configuration, allowing you to pass custom value in the node.

src/Client/Client.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use M6Web\Bundle\StatsdBundle\Statsd\MonitorableEventInterface;
66
use M6Web\Component\Statsd\Client as BaseClient;
7-
use Symfony\Component\EventDispatcher\GenericEvent;
87
use Symfony\Component\PropertyAccess;
98

109
/**

src/DataCollector/StatsdDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ public function addStatsdClient($clientAlias, $statsdClient)
8282
*
8383
* @param Request $request The request object
8484
* @param Response $response The response object
85-
* @param \Exception $exception An exception
85+
* @param \Throwable $exception An exception
8686
*/
87-
public function collect(Request $request, Response $response, \Exception $exception = null)
87+
public function collect(Request $request, Response $response, \Throwable $exception = null)
8888
{
8989
}
9090

src/Event/ConsoleEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace M6Web\Bundle\StatsdBundle\Event;
33

44
use Symfony\Component\Console\Event\ConsoleEvent as BaseConsoleEvent;
5-
use Symfony\Component\EventDispatcher\Event;
5+
use Symfony\Contracts\EventDispatcher\Event;
66

77
/**
88
* Base console event

src/Listener/ConsoleListener.php

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

55
use M6Web\Bundle\StatsdBundle\Event\ConsoleEvent;
66

7-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
88
use Symfony\Component\Console\Event\ConsoleEvent as BaseConsoleEvent;
99
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
1010

@@ -43,7 +43,7 @@ public function onCommand(BaseConsoleEvent $e)
4343
{
4444
$this->startTime = microtime(true);
4545

46-
$this->dispatch(ConsoleEvent::COMMAND, $e);
46+
$this->dispatch($e, ConsoleEvent::COMMAND);
4747
}
4848

4949
/**
@@ -53,29 +53,29 @@ public function onTerminate(ConsoleTerminateEvent $e)
5353
{
5454
// For non-0 exit command, fire an ERROR event
5555
if ($e->getExitCode() != 0) {
56-
$this->dispatch(ConsoleEvent::ERROR, $e);
56+
$this->dispatch($e, ConsoleEvent::ERROR);
5757
}
5858

59-
$this->dispatch(ConsoleEvent::TERMINATE, $e);
59+
$this->dispatch($e, ConsoleEvent::TERMINATE);
6060
}
6161

6262
/**
6363
* @param BaseConsoleEvent $e
6464
*/
6565
public function onException(BaseConsoleEvent $e)
6666
{
67-
$this->dispatch(ConsoleEvent::EXCEPTION, $e);
67+
$this->dispatch($e, ConsoleEvent::EXCEPTION);
6868
}
6969

7070
/**
7171
* Dispatch custom event
7272
*
73-
* @param string $eventName
7473
* @param BaseConsoleEvent $e
74+
* @param string $eventName
7575
*
7676
* @return boolean
7777
*/
78-
protected function dispatch($eventName, BaseConsoleEvent $e)
78+
protected function dispatch(BaseConsoleEvent $e, $eventName)
7979
{
8080
if (!is_null($this->eventDispatcher)) {
8181
$class = str_replace(
@@ -90,7 +90,7 @@ protected function dispatch($eventName, BaseConsoleEvent $e)
9090
!is_null($this->startTime) ? microtime(true) - $this->startTime : null
9191
);
9292

93-
return $this->eventDispatcher->dispatch($eventName, $finaleEvent);
93+
return $this->eventDispatcher->dispatch($finaleEvent, $eventName);
9494
} else {
9595
return false;
9696
}

src/Resources/views/Collector/statsd.html.twig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
{% block menu %}
2121
<span class="label">
22-
<span class="icon">{% spaceless %}
23-
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAEVUlEQVRYhe2Wz0sVaxjHP+/8OOdM53SmOJwgMTtYSHBBTLDFrUjolmvBIxiCFLhI6F5xIbToD3Aj6d3VQgqiRYu6riJaWd3ERUq20pQDSgv1kkiemTMzZ9670JnrHH9gxPXehQ8MM/N93/f5fp8f78wLh3Zo/7GJ4OGXa9cWTPNY9UGQuq5rj/7xwgDQAtA0j1X/Pjx0EPzc+fW3RPCsVQ52dXWRSqWIxWJomkYul2NhYSEcF0Jw6tSpCAaEmJQyxKqrqykUCnieh+M4WJbFyMhIZF0oIFiYTCZZXV0lk8lgGAZCCJLJJIqi/LNI0zh69GjUkaaRSqXCd9/3EUKgqirFYpHl5WWqqqoiXBEBvu+HjtLpN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84wNzfHkSNH6OnpYXBwEMuyKBQKEaHBPNd1+fbtG47jRLgAws9buaIETU1N5PN5Xr58iWEYDA8P09XVRTKZDEtw+/Zt3r59y8TEBJ7nUSwWI1cwz7IsbNumXC5HuCIZCAZ93+fSpUt0dnbS399PLBZjdnaWx48fc+PGDe7fv8+nT58oFApomsaDBw9wHGfPXgmaORSweY9moFxGSklTUxPd3d309vYyMzODEALHcfjy5QsDAwN0dHRQKBRoaGhgYGCAr1+/RqKtzMD6+jqWZYVbUkoZERCeB36+eFG+eP6clZUV7t69y8rKCqqqUmlSSlzXxXVdDMOI/KR2s4C0vr6ee/fukW9v589370SkBH7ZZ3V1lb6+Pl6/fo0QAiEEjY2NfPjwIeKwsbGR6enpbVjlvPPnzzM5OYmUEikl8Xh8YzuWd+gBr1wmmUyGNQvMdd2we78XC84BWzMhpcTbrQeAfaX0R21rD2wpQTn85zc3N4cT6urqth0+fgTbKMFOAjb35pMnT74vnO+0jfOEhI3s+xqgqaqatWzrr+vXWzL/KvumlX3f1XX9J8/zZg+C79D+3/Y3WY+lvPQgrdQAAAAASUVORK5CYII=" alt="Statsd" /></span>
2523
<strong>Statsd</strong>
2624
<span class="count">
2725
<span>{{ collector.operations }}</span>

src/Statsd/Listener.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace M6Web\Bundle\StatsdBundle\Statsd;
44

55
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
6-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7-
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
8-
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
6+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
7+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
8+
use Symfony\Component\HttpKernel\Event\TerminateEvent;
99
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
1010

1111
use M6Web\Component\Statsd\Client;
@@ -32,30 +32,30 @@ public function __construct(Client $statsdClient, EventDispatcherInterface $even
3232
/**
3333
* onKernelException
3434
*
35-
* @param GetResponseForExceptionEvent $event
35+
* @param ExceptionEvent $event
3636
*/
37-
public function onKernelException(GetResponseForExceptionEvent $event)
37+
public function onKernelException(ExceptionEvent $event)
3838
{
39-
$exception = $event->getException();
39+
$exception = $event->getThrowable();
4040
if ($exception instanceof HttpExceptionInterface) {
41-
$code = $event->getException()->getStatusCode();
41+
$code = $event->getThrowable()->getStatusCode();
4242
} else {
4343
$code = 'unknown';
4444
}
4545
$this->eventDispatcher->dispatch(
46-
'statsd.exception',
47-
new StatsdEvent($code)
46+
new StatsdEvent($code),
47+
'statsd.exception'
4848
);
4949
}
5050

5151
/**
5252
* method called on the kernel.terminate event
5353
*
54-
* @param PostResponseEvent $event event
54+
* @param TerminateEvent $event event
5555
*
5656
* @return void
5757
*/
58-
public function onKernelTerminate(PostResponseEvent $event)
58+
public function onKernelTerminate(TerminateEvent $event)
5959
{
6060
$this->statsdClient->send();
6161
}
@@ -76,9 +76,9 @@ public function onConsoleTerminate(ConsoleTerminateEvent $event)
7676
* method called if base_collectors = true in config to dispatch base events
7777
* (you still have to catch them)
7878
*
79-
* @param PostResponseEvent $event
79+
* @param TerminateEvent $event
8080
*/
81-
public function dispatchBaseEvents(PostResponseEvent $event)
81+
public function dispatchBaseEvents(TerminateEvent $event)
8282
{
8383
$this->dispatchMemory();
8484
$this->dispatchRequestTime($event);
@@ -93,8 +93,8 @@ private function dispatchMemory()
9393
$memory = ($memory > 1024 ? intval($memory / 1024) : 0);
9494

9595
$this->eventDispatcher->dispatch(
96-
'statsd.memory_usage',
97-
new StatsdEvent($memory)
96+
new StatsdEvent($memory),
97+
'statsd.memory_usage'
9898
);
9999
}
100100

@@ -103,18 +103,18 @@ private function dispatchMemory()
103103
* This time is a "fake" one, because some actions are performed before the initialization of the request
104104
* It is ~100ms smaller than the real kernel time.
105105
*
106-
* @param PostResponseEvent $event
106+
* @param TerminateEvent $event
107107
*/
108-
private function dispatchRequestTime(PostResponseEvent $event)
108+
private function dispatchRequestTime(TerminateEvent $event)
109109
{
110110
$request = $event->getRequest();
111111
$startTime = $request->server->get('REQUEST_TIME_FLOAT', $request->server->get('REQUEST_TIME'));
112112
$time = microtime(true) - $startTime;
113113
$time = round($time * 1000);
114114

115115
$this->eventDispatcher->dispatch(
116-
'statsd.time',
117-
new StatsdEvent($time)
116+
new StatsdEvent($time),
117+
'statsd.time'
118118
);
119119
}
120120
}

0 commit comments

Comments
 (0)