From ba6b22fcf18a470fc044a9595ed571952c48c45e Mon Sep 17 00:00:00 2001 From: Selvi ARIK Date: Tue, 14 Jul 2020 23:01:09 +0200 Subject: [PATCH 1/9] chore: support symfony 5 DataCollector::collect method signature change since SF 4.4 --- composer.json | 4 ++-- src/DataCollector/StatsdDataCollector.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index cc3441a..1a256fb 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ }, "require": { "php": "^7.1.3", - "symfony/property-access": "^3.4 || ^4.0", + "symfony/property-access": "^4.4 || ^5.0", "m6web/statsd": "^1.3" }, "require-dev": { "atoum/atoum": "^2.8|^3.0", - "symfony/symfony": "^3.4 || ^4.0 || ^5.0", + "symfony/symfony": "^4.4 || ^5.0", "m6web/coke" : "~1.2", "m6web/symfony2-coding-standard" : "~1.2" }, diff --git a/src/DataCollector/StatsdDataCollector.php b/src/DataCollector/StatsdDataCollector.php index 3a21999..ca34c22 100644 --- a/src/DataCollector/StatsdDataCollector.php +++ b/src/DataCollector/StatsdDataCollector.php @@ -82,9 +82,9 @@ public function addStatsdClient($clientAlias, $statsdClient) * * @param Request $request The request object * @param Response $response The response object - * @param \Exception $exception An exception + * @param \Throwable $exception An exception */ - public function collect(Request $request, Response $response, \Exception $exception = null) + public function collect(Request $request, Response $response, \Throwable $exception = null) { } From 031b5c683d629e76ab5f404bcdd3789383cc77d4 Mon Sep 17 00:00:00 2001 From: Selvi ARIK Date: Wed, 15 Jul 2020 00:04:46 +0200 Subject: [PATCH 2/9] fix: travis config + doc --- .travis.yml | 5 +++-- README.md | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 416abf6..bde56ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,11 @@ language: php php: - 7.1 - 7.2 + - 7.4 env: - - SYMFONY_VERSION=3.4.0 - - SYMFONY_VERSION=4.0.* + - SYMFONY_VERSION=4.4.0 + - SYMFONY_VERSION=5.*.* before_script: - wget http://getcomposer.org/composer.phar diff --git a/README.md b/README.md index 66d6c84..b304a18 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,9 @@ StatsdBundle [![Build Status](https://travis-ci.org/M6Web/StatsdBundle.png?branc ## Bundle easing the [statsd](https://github.com/etsy/statsd/) usage. -This bundle currently supports `php >=7.1.3` and `symfony 3.4/4.x`. +This bundle currently supports `php >=7.1.3` and `symfony 4.4/5.x`. +If you need support for `symfony 3.4/<4.4`, use version [v3.0.0](https://github.com/M6Web/StatsdBundle/tree/v3.0.0). 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). * [about](doc/about.md) From 86a4dd4e1854acf3683e2b06b843e189296a4b2c Mon Sep 17 00:00:00 2001 From: Selvi ARIK Date: Wed, 15 Jul 2020 01:18:20 +0200 Subject: [PATCH 3/9] fix: swap arguments of dispatch() @see https://github.com/symfony/symfony/commit/75369dabb8af73b0d0ad7f206d85c08cf39117f8 --- doc/usage.md | 2 +- src/Client/Client.php | 1 - src/Event/ConsoleEvent.php | 2 +- src/Listener/ConsoleListener.php | 16 ++++++++-------- src/Statsd/Listener.php | 14 +++++++------- src/Tests/Units/Client/Client.php | 18 +++++++++--------- src/Tests/Units/Client/Event.php | 2 +- .../M6WebStatsdExtension.php | 2 +- 8 files changed, 28 insertions(+), 29 deletions(-) diff --git a/doc/usage.md b/doc/usage.md index 56ca842..2ba013d 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -72,7 +72,7 @@ On the Symfony event dispatcher, when the ```forum.read``` event is fired, our s So you can now just fire the event from a controller : ```php -$this->get('event_dispatcher')->dispatch('forum.read', new Symfony\Component\EventDispatcher\Event()); +$this->get('event_dispatcher')->dispatch(new Symfony\Contracts\EventDispatcher\Event(), 'forum.read'); ``` It's also possible to create tokens in the Symfony configuration, allowing you to pass custom value in the node. diff --git a/src/Client/Client.php b/src/Client/Client.php index 8951fa9..b83dc11 100644 --- a/src/Client/Client.php +++ b/src/Client/Client.php @@ -4,7 +4,6 @@ use M6Web\Bundle\StatsdBundle\Statsd\MonitorableEventInterface; use M6Web\Component\Statsd\Client as BaseClient; -use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\PropertyAccess; /** diff --git a/src/Event/ConsoleEvent.php b/src/Event/ConsoleEvent.php index 3a1895b..c080b32 100644 --- a/src/Event/ConsoleEvent.php +++ b/src/Event/ConsoleEvent.php @@ -2,7 +2,7 @@ namespace M6Web\Bundle\StatsdBundle\Event; use Symfony\Component\Console\Event\ConsoleEvent as BaseConsoleEvent; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Base console event diff --git a/src/Listener/ConsoleListener.php b/src/Listener/ConsoleListener.php index bacf94a..3793236 100644 --- a/src/Listener/ConsoleListener.php +++ b/src/Listener/ConsoleListener.php @@ -4,7 +4,7 @@ use M6Web\Bundle\StatsdBundle\Event\ConsoleEvent; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Console\Event\ConsoleEvent as BaseConsoleEvent; use Symfony\Component\Console\Event\ConsoleTerminateEvent; @@ -43,7 +43,7 @@ public function onCommand(BaseConsoleEvent $e) { $this->startTime = microtime(true); - $this->dispatch(ConsoleEvent::COMMAND, $e); + $this->dispatch($e, ConsoleEvent::COMMAND); } /** @@ -53,10 +53,10 @@ public function onTerminate(ConsoleTerminateEvent $e) { // For non-0 exit command, fire an ERROR event if ($e->getExitCode() != 0) { - $this->dispatch(ConsoleEvent::ERROR, $e); + $this->dispatch($e, ConsoleEvent::ERROR); } - $this->dispatch(ConsoleEvent::TERMINATE, $e); + $this->dispatch($e, ConsoleEvent::TERMINATE); } /** @@ -64,18 +64,18 @@ public function onTerminate(ConsoleTerminateEvent $e) */ public function onException(BaseConsoleEvent $e) { - $this->dispatch(ConsoleEvent::EXCEPTION, $e); + $this->dispatch($e, ConsoleEvent::EXCEPTION); } /** * Dispatch custom event * - * @param string $eventName * @param BaseConsoleEvent $e + * @param string $eventName * * @return boolean */ - protected function dispatch($eventName, BaseConsoleEvent $e) + protected function dispatch(BaseConsoleEvent $e, $eventName) { if (!is_null($this->eventDispatcher)) { $class = str_replace( @@ -90,7 +90,7 @@ protected function dispatch($eventName, BaseConsoleEvent $e) !is_null($this->startTime) ? microtime(true) - $this->startTime : null ); - return $this->eventDispatcher->dispatch($eventName, $finaleEvent); + return $this->eventDispatcher->dispatch($finaleEvent, $eventName); } else { return false; } diff --git a/src/Statsd/Listener.php b/src/Statsd/Listener.php index 7a3fe76..dc93c5b 100644 --- a/src/Statsd/Listener.php +++ b/src/Statsd/Listener.php @@ -3,7 +3,7 @@ namespace M6Web\Bundle\StatsdBundle\Statsd; use Symfony\Component\Console\Event\ConsoleTerminateEvent; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Event\PostResponseEvent; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; @@ -43,8 +43,8 @@ public function onKernelException(GetResponseForExceptionEvent $event) $code = 'unknown'; } $this->eventDispatcher->dispatch( - 'statsd.exception', - new StatsdEvent($code) + new StatsdEvent($code), + 'statsd.exception' ); } @@ -93,8 +93,8 @@ private function dispatchMemory() $memory = ($memory > 1024 ? intval($memory / 1024) : 0); $this->eventDispatcher->dispatch( - 'statsd.memory_usage', - new StatsdEvent($memory) + new StatsdEvent($memory), + 'statsd.memory_usage' ); } @@ -113,8 +113,8 @@ private function dispatchRequestTime(PostResponseEvent $event) $time = round($time * 1000); $this->eventDispatcher->dispatch( - 'statsd.time', - new StatsdEvent($time) + new StatsdEvent($time), + 'statsd.time' ); } } diff --git a/src/Tests/Units/Client/Client.php b/src/Tests/Units/Client/Client.php index c8b5576..76cb73e 100644 --- a/src/Tests/Units/Client/Client.php +++ b/src/Tests/Units/Client/Client.php @@ -35,7 +35,7 @@ public function testHandleEventWithValidConfigIncrement() $client = $this->getMockedClient(); - $event = new \Symfony\Component\EventDispatcher\Event(); + $event = new \Symfony\Contracts\EventDispatcher\Event(); $client->addEventToListen('test', array( 'increment' => 'stats.' @@ -59,7 +59,7 @@ public function testHandleEventWithValidConfigDecrement() { $client = $this->getMockedClient(); - $event = new \Symfony\Component\EventDispatcher\Event(); + $event = new \Symfony\Contracts\EventDispatcher\Event(); $client->addEventToListen('test', array( 'decrement' => 'stats.' @@ -83,7 +83,7 @@ public function testHandleEventWithImmediateSend() $client = $this->getMockedClient(); - $event = new \Symfony\Component\EventDispatcher\Event(); + $event = new \Symfony\Contracts\EventDispatcher\Event(); $client->addEventToListen('test', array( 'increment' => 'stats.', @@ -109,7 +109,7 @@ public function testHandleEventWithToSendLimit() $client = $this->getMockedClient(); $client->setToSendLimit(3); - $event = new \Symfony\Component\EventDispatcher\Event(); + $event = new \Symfony\Contracts\EventDispatcher\Event(); $queue = new \SPLQueue; @@ -148,7 +148,7 @@ public function testHandleEventWithInvalidConfigIncrement() )); $this->exception(function () use ($client) { - $event = new \Symfony\Component\EventDispatcher\Event(); + $event = new \Symfony\Contracts\EventDispatcher\Event(); $client->handleEvent($event, 'test'); }); @@ -166,7 +166,7 @@ public function testHandleEventWithInvalidEventTiming() )); $this->exception(function () use ($client) { - $event = new \Symfony\Component\EventDispatcher\Event(); + $event = new \Symfony\Contracts\EventDispatcher\Event(); $client->handleEvent($event, 'test'); }); @@ -178,7 +178,7 @@ public function testHandleEventWithInvalidEventTiming() )); $this->exception(function () use ($client) { - $event = new \Symfony\Component\EventDispatcher\Event(); + $event = new \Symfony\Contracts\EventDispatcher\Event(); $client->handleEvent($event, 'test'); }); @@ -253,7 +253,7 @@ public function testHandleEventCallsConfiguredTiming() $dispatcher->addListener('test.event.name', [$client, 'handleEvent']); $this - ->if($dispatcher->dispatch('test.event.name', $event)) + ->if($dispatcher->dispatch($event, 'test.event.name')) ->mock($client) ->call('timing') ->withArguments('my.statsd.node', 101, 1.0) @@ -278,7 +278,7 @@ public function testHandleEventDontCallTimingOnUnconfiguredEvent() $dispatcher->addListener('test.event.name', [$client, 'handleEvent']); $this - ->if($dispatcher->dispatch('test.event.other.name', $event)) + ->if($dispatcher->dispatch($event, 'test.event.other.name')) ->mock($client) ->call('timing') ->never(); diff --git a/src/Tests/Units/Client/Event.php b/src/Tests/Units/Client/Event.php index 453bebc..036467d 100644 --- a/src/Tests/Units/Client/Event.php +++ b/src/Tests/Units/Client/Event.php @@ -2,7 +2,7 @@ namespace M6Web\Bundle\StatsdBundle\Tests\Units\Client; -class Event extends \Symfony\Component\EventDispatcher\Event +class Event extends \Symfony\Contracts\EventDispatcher\Event { private $name = ''; diff --git a/src/Tests/Units/DependencyInjection/M6WebStatsdExtension.php b/src/Tests/Units/DependencyInjection/M6WebStatsdExtension.php index 0f1be92..c90f9c6 100644 --- a/src/Tests/Units/DependencyInjection/M6WebStatsdExtension.php +++ b/src/Tests/Units/DependencyInjection/M6WebStatsdExtension.php @@ -19,7 +19,7 @@ class M6WebStatsdExtension extends atoum\test protected function initContainer($resource, $debug = false) { $this->container = new ContainerBuilder(); - $this->container->register('event_dispatcher', new EventDispatcher()); + $this->container->register('event_dispatcher', EventDispatcher::class); $this->container->registerExtension(new BaseM6WebStatsdExtension()); $this->loadConfiguration($this->container, $resource); $this->container->setParameter('kernel.debug', $debug); From 95e808edc1b464def96d728539a34b4abdc95d6d Mon Sep 17 00:00:00 2001 From: Selvi ARIK Date: Wed, 15 Jul 2020 01:28:39 +0200 Subject: [PATCH 4/9] fix: renamed events GetResponseForExceptionEvent replaced by ExceptionEvent; PostResponseEvent replaced by TerminateEvent; --- src/Statsd/Listener.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Statsd/Listener.php b/src/Statsd/Listener.php index dc93c5b..28d2eac 100644 --- a/src/Statsd/Listener.php +++ b/src/Statsd/Listener.php @@ -4,8 +4,8 @@ use Symfony\Component\Console\Event\ConsoleTerminateEvent; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; -use Symfony\Component\HttpKernel\Event\PostResponseEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Symfony\Component\HttpKernel\Event\TerminateEvent; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use M6Web\Component\Statsd\Client; @@ -32,13 +32,13 @@ public function __construct(Client $statsdClient, EventDispatcherInterface $even /** * onKernelException * - * @param GetResponseForExceptionEvent $event + * @param ExceptionEvent $event */ - public function onKernelException(GetResponseForExceptionEvent $event) + public function onKernelException(ExceptionEvent $event) { - $exception = $event->getException(); + $exception = $event->getThrowable(); if ($exception instanceof HttpExceptionInterface) { - $code = $event->getException()->getStatusCode(); + $code = $event->getThrowable()->getStatusCode(); } else { $code = 'unknown'; } @@ -51,11 +51,11 @@ public function onKernelException(GetResponseForExceptionEvent $event) /** * method called on the kernel.terminate event * - * @param PostResponseEvent $event event + * @param TerminateEvent $event event * * @return void */ - public function onKernelTerminate(PostResponseEvent $event) + public function onKernelTerminate(TerminateEvent $event) { $this->statsdClient->send(); } @@ -76,9 +76,9 @@ public function onConsoleTerminate(ConsoleTerminateEvent $event) * method called if base_collectors = true in config to dispatch base events * (you still have to catch them) * - * @param PostResponseEvent $event + * @param TerminateEvent $event */ - public function dispatchBaseEvents(PostResponseEvent $event) + public function dispatchBaseEvents(TerminateEvent $event) { $this->dispatchMemory(); $this->dispatchRequestTime($event); @@ -103,9 +103,9 @@ private function dispatchMemory() * This time is a "fake" one, because some actions are performed before the initialization of the request * It is ~100ms smaller than the real kernel time. * - * @param PostResponseEvent $event + * @param TerminateEvent $event */ - private function dispatchRequestTime(PostResponseEvent $event) + private function dispatchRequestTime(TerminateEvent $event) { $request = $event->getRequest(); $startTime = $request->server->get('REQUEST_TIME_FLOAT', $request->server->get('REQUEST_TIME')); From 20531b1a4595eb96043e7e8a00bb811d39b581cb Mon Sep 17 00:00:00 2001 From: Selvi ARIK Date: Wed, 15 Jul 2020 01:46:22 +0200 Subject: [PATCH 5/9] refactor: use the spaceless filter instead of spaceless tag (since Twig 1.38) --- src/Resources/views/Collector/statsd.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Resources/views/Collector/statsd.html.twig b/src/Resources/views/Collector/statsd.html.twig index 3426f57..fb539bb 100644 --- a/src/Resources/views/Collector/statsd.html.twig +++ b/src/Resources/views/Collector/statsd.html.twig @@ -19,9 +19,9 @@ {% block menu %} - {% spaceless %} + {% apply spaceless %} Statsd - {% endspaceless %} + {% endapply %} Statsd {{ collector.operations }} From 57273b9830f4b681e1f19c3c019591d8e920a0c9 Mon Sep 17 00:00:00 2001 From: Selvi ARIK Date: Wed, 15 Jul 2020 02:08:19 +0200 Subject: [PATCH 6/9] chore: only needed symfony dependencies --- composer.json | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 1a256fb..b7177d1 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ ], "config": { "bin-dir": "bin", - "vendor-dir": "vendor" + "vendor-dir": "vendor", + "sort-packages": true }, "require": { "php": "^7.1.3", @@ -22,9 +23,14 @@ }, "require-dev": { "atoum/atoum": "^2.8|^3.0", - "symfony/symfony": "^4.4 || ^5.0", - "m6web/coke" : "~1.2", - "m6web/symfony2-coding-standard" : "~1.2" + "m6web/coke": "~1.2", + "m6web/symfony2-coding-standard": "~1.2", + "symfony/config": "^4.4 || ^5.0", + "symfony/console": "^4.4 || ^5.0", + "symfony/dependency-injection": "^4.4 || ^5.0", + "symfony/event-dispatcher-contracts": "^1.1 || ^2.1", + "symfony/http-foundation": "^4.4 || ^5.0", + "symfony/http-kernel": "^4.4 || ^5.0" }, "autoload": { "psr-4": { "M6Web\\Bundle\\StatsdBundle\\": "src/" } From 5100c35b0ef0c4e2221d9d5284856b6a03dfa3f0 Mon Sep 17 00:00:00 2001 From: Selvi ARIK Date: Wed, 15 Jul 2020 09:53:33 +0200 Subject: [PATCH 7/9] chore: CI : php compatibility for SF5 (>=7.2.5) --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index bde56ff..b7b7e2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,3 +17,8 @@ before_script: script: - bin/coke - bin/atoum + +jobs: + exclude: + - php: 7.1 + env: SYMFONY_VERSION=5.*.* \ No newline at end of file From fa61474348899479a2a46907e49f67b5df64452f Mon Sep 17 00:00:00 2001 From: Selvi ARIK Date: Fri, 17 Jul 2020 17:20:24 +0200 Subject: [PATCH 8/9] style: remove spaceless filter --- src/Resources/views/Collector/statsd.html.twig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Resources/views/Collector/statsd.html.twig b/src/Resources/views/Collector/statsd.html.twig index fb539bb..20a4879 100644 --- a/src/Resources/views/Collector/statsd.html.twig +++ b/src/Resources/views/Collector/statsd.html.twig @@ -19,9 +19,7 @@ {% block menu %} - {% apply spaceless %} - Statsd - {% endapply %} + Statsd Statsd {{ collector.operations }} From dab43a9048a9bc311bebd03f3904ea35ebadf9d0 Mon Sep 17 00:00:00 2001 From: Selvi ARIK Date: Wed, 22 Jul 2020 11:53:13 +0200 Subject: [PATCH 9/9] add new line at the end of the file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 160368f..c33fa42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,4 +22,4 @@ script: jobs: exclude: - php: 7.1 - env: SYMFONY_VERSION=5.*.* \ No newline at end of file + env: SYMFONY_VERSION=5.*.*