mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Change DispatcherAware to accept concrete instances
Dispatcher is already instanciated when invoking controller. So useless to lazy load it.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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']);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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']);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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']);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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']);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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']);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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']);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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']);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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'];
|
||||
})
|
||||
|
@@ -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']);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user