|
@@ -0,0 +1,55 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace demo\Services;
|
|
|
+
|
|
|
+use Pimple\Container;
|
|
|
+use Pimple\ServiceProviderInterface;
|
|
|
+use Silex\Api\BootableProviderInterface;
|
|
|
+use Silex\Api\EventListenerProviderInterface;
|
|
|
+use Silex\Application;
|
|
|
+use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
|
|
|
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
+use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
|
|
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
|
|
+use Symfony\Component\HttpKernel\KernelEvents;
|
|
|
+
|
|
|
+class NavProvider implements BootableProviderInterface, EventListenerProviderInterface, ServiceProviderInterface {
|
|
|
+
|
|
|
+
|
|
|
+ * Bootstraps the application.
|
|
|
+ *
|
|
|
+ * This method is called after all services are registered
|
|
|
+ * and should be used for "dynamic" configuration (whenever
|
|
|
+ * a service must be requested).
|
|
|
+ *
|
|
|
+ * @param Application $app
|
|
|
+ */
|
|
|
+ public function boot(Application $app) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function subscribe(
|
|
|
+ Container $app,
|
|
|
+ EventDispatcherInterface $dispatcher
|
|
|
+ ) {
|
|
|
+ $dispatcher->addListener(KernelEvents::RESPONSE, [$this, 'onResponse']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Registers services on the given container.
|
|
|
+ *
|
|
|
+ * This method should only be used to configure services and parameters.
|
|
|
+ * It should not get services.
|
|
|
+ *
|
|
|
+ * @param Container $dic A container instance
|
|
|
+ */
|
|
|
+ public function register(Container $dic) {
|
|
|
+ $dic['nav_builder'] = function ($app) {
|
|
|
+ return NavBuilder::create($app);
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ public function onResponse(FilterResponseEvent $event, string $eventName, EventDispatcherInterface $eventDispatcher) {
|
|
|
+ echo "<p>Got a " . $event->getResponse()->getStatusCode() . " response</p>\n";
|
|
|
+ }
|
|
|
+}
|