diff --git a/lib/Alchemy/Phrasea/Application/Helper/DispatcherAware.php b/lib/Alchemy/Phrasea/Application/Helper/DispatcherAware.php index 93c316abb5..1efe4326e2 100644 --- a/lib/Alchemy/Phrasea/Application/Helper/DispatcherAware.php +++ b/lib/Alchemy/Phrasea/Application/Helper/DispatcherAware.php @@ -17,14 +17,12 @@ trait DispatcherAware private $dispatcher; /** - * Set Locator to use to locate event dispatcher - * - * @param callable $locator + * @param EventDispatcherInterface $dispatcher * @return $this */ - public function setDispatcherLocator(callable $locator) + public function setDispatcher(EventDispatcherInterface $dispatcher) { - $this->dispatcher = $locator; + $this->dispatcher = $dispatcher; return $this; } @@ -34,24 +32,10 @@ trait DispatcherAware */ public function getDispatcher() { - if ($this->dispatcher instanceof EventDispatcherInterface) { - return $this->dispatcher; - } - if (null === $this->dispatcher) { - throw new \LogicException('Dispatcher locator was not set'); + throw new \LogicException('Dispatcher was not set'); } - $dispatcher = call_user_func($this->dispatcher); - if (!$dispatcher instanceof EventDispatcherInterface) { - throw new \LogicException(sprintf( - 'Expects locator to return instance of "%s", got "%s"', - EventDispatcherInterface::class, - is_object($dispatcher) ? get_class($dispatcher) : gettype($dispatcher) - )); - } - $this->dispatcher = $dispatcher; - return $this->dispatcher; } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/FeedController.php b/lib/Alchemy/Phrasea/Controller/Prod/FeedController.php index e15ccb61c4..fa3e397216 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/FeedController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/FeedController.php @@ -10,6 +10,7 @@ namespace Alchemy\Phrasea\Controller\Prod; use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Application\Helper\DispatcherAware; use Alchemy\Phrasea\Application\Helper\FirewallAware; use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Controller\RecordsRequest; @@ -26,6 +27,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; class FeedController extends Controller { + use DispatcherAware; use FirewallAware; public function publishRecordsAction(Application $app, Request $request) diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/TaskManager.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/TaskManager.php index 1e63244359..0d487e680d 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/TaskManager.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/TaskManager.php @@ -26,9 +26,7 @@ class TaskManager implements ControllerProviderInterface, ServiceProviderInterfa { $app['controller.admin.task'] = $app->share(function (\Alchemy\Phrasea\Application $app) { return (new TaskManagerController($app)) - ->setDispatcherLocator(function () use ($app) { - return $app['dispatcher']; - }); + ->setDispatcher($app['dispatcher']); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php index 083bcc63a8..59ff0e64d6 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php @@ -24,9 +24,7 @@ class OAuth2 implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.oauth2'] = $app->share(function (PhraseaApplication $app) { return (new OAuth2Controller($app)) - ->setDispatcherLocator(function () use ($app) { - return $app['dispatcher']; - }); + ->setDispatcher($app['dispatcher']); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php index ecb6a7b4e8..1a0f98652d 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php @@ -32,9 +32,7 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.api.v1'] = $app->share(function (PhraseaApplication $app) { return (new V1Controller($app)) - ->setDispatcherLocator(function () use ($app) { - return $app['dispatcher']; - }); + ->setDispatcher($app['dispatcher']); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php b/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php index a93ddea6c5..42f618d3a2 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php @@ -29,9 +29,7 @@ class Lightbox implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.lightbox'] = $app->share(function (PhraseaApplication $app) { return (new LightboxController($app)) - ->setDispatcherLocator(function () use ($app) { - return $app['dispatcher']; - }); + ->setDispatcher($app['dispatcher']); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/DoDownload.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/DoDownload.php index 228d29b899..c2f71c5279 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/DoDownload.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/DoDownload.php @@ -26,9 +26,7 @@ class DoDownload implements ControllerProviderInterface, ServiceProviderInterfac { $app['controller.prod.do-download'] = $app->share(function (PhraseaApplication $app) { return (new DoDownloadController($app)) - ->setDispatcherLocator(function () use ($app) { - return $app['dispatcher']; - }); + ->setDispatcher($app['dispatcher']); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Download.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Download.php index fbd77305cf..ad7d3680ef 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Download.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Download.php @@ -26,9 +26,7 @@ class Download implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.prod.download'] = $app->share(function (PhraseaApplication $app) { return (new DownloadController($app)) - ->setDispatcherLocator(function () use ($app) { - return $app['dispatcher']; - }); + ->setDispatcher($app['dispatcher']); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php index 8d83fda750..fe67348a6d 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php @@ -26,9 +26,7 @@ class Edit implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.prod.edit'] = $app->share(function (PhraseaApplication $app) { return (new EditController($app)) - ->setDispatcherLocator(function () use ($app) { - return $app['dispatcher']; - }); + ->setDispatcher($app['dispatcher']); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Export.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Export.php index 8cc5550365..e77e0fc601 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Export.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Export.php @@ -26,9 +26,7 @@ class Export implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.prod.export'] = $app->share(function (PhraseaApplication $app) { return (new ExportController($app)) - ->setDispatcherLocator(function () use ($app) { - return $app['dispatcher']; - }) + ->setDispatcher($app['dispatcher']) ->setFileSystemLocator(function () use ($app) { return $app['filesystem']; }) diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Feed.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Feed.php index 1785f3acbc..658f700bf7 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Feed.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Feed.php @@ -26,6 +26,7 @@ class Feed implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.prod.feed'] = $app->share(function (PhraseaApplication $app) { return (new FeedController($app)) + ->setDispatcher($app['dispatcher']) ->setFirewall($app['firewall']); }); }