diff --git a/lib/Alchemy/Phrasea/Controller/LazyLocator.php b/lib/Alchemy/Phrasea/Controller/LazyLocator.php new file mode 100644 index 0000000000..825178f4fc --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/LazyLocator.php @@ -0,0 +1,32 @@ +pimple = $pimple; + $this->serviceId = $serviceId; + } + + public function __invoke() + { + return $this->pimple->offsetGet($this->serviceId); + } +} diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php index cf95eb7c87..5534416c23 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php @@ -13,10 +13,12 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Admin\CollectionController; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; use Silex\ControllerProviderInterface; use Silex\ServiceProviderInterface; +use Symfony\Component\HttpFoundation\Request; class Collection implements ControllerProviderInterface, ServiceProviderInterface { @@ -26,9 +28,7 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac { $app['controller.admin.collection'] = $app->share(function (PhraseaApplication $app) { return (new CollectionController($app)) - ->setUserQueryFactory(function () use ($app) { - return $app['phraseanet.user-query']; - }) + ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query')) ; }); } @@ -40,10 +40,12 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac public function connect(Application $app) { $controllers = $this->createAuthenticatedCollection($app); + $firewall = $this->getFirewall($app); - $controllers->before(function () use ($app) { - $app['firewall']->requireAccessToModule('admin') - ->requireRightOnBase($app['request']->attributes->get('bas_id'), 'canadmin'); + $controllers->before(function (Request $request) use ($firewall) { + $firewall + ->requireAccessToModule('admin') + ->requireRightOnBase($request->attributes->get('bas_id'), 'canadmin'); }); $controllers->get('/{bas_id}/', 'controller.admin.collection:getCollection') diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/ConnectedUsers.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/ConnectedUsers.php index a81a02caa7..47c668616d 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/ConnectedUsers.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/ConnectedUsers.php @@ -46,9 +46,10 @@ class ConnectedUsers implements ControllerProviderInterface, ServiceProviderInte public function connect(Application $app) { $controllers = $this->createAuthenticatedCollection($app); + $firewall = $this->getFirewall($app); - $controllers->before(function () use ($app) { - $app['firewall']->requireAccessToModule('Admin'); + $controllers->before(function () use ($firewall) { + $firewall->requireAccessToModule('Admin'); }); $controllers->get('/', 'controller.admin.connected-users:listConnectedUsers') diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Dashboard.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Dashboard.php index 90eb56ae23..a2f66455e4 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Dashboard.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Dashboard.php @@ -13,6 +13,8 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Admin\DashboardController; +use Alchemy\Phrasea\Controller\LazyLocator; +use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; use Silex\ControllerCollection; use Silex\ControllerProviderInterface; @@ -20,13 +22,14 @@ use Silex\ServiceProviderInterface; class Dashboard implements ControllerProviderInterface, ServiceProviderInterface { + use ControllerProviderTrait; + public function register(Application $app) { $app['controller.admin.dashboard'] = $app->share(function (PhraseaApplication $app) { return (new DashboardController($app)) - ->setDelivererLocator(function () use ($app) { - return $app['notification.deliverer']; - }); + ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer')) + ; }); } @@ -36,11 +39,11 @@ class Dashboard implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { - /** @var ControllerCollection $controllers */ - $controllers = $app['controllers_factory']; + $controllers = $this->createCollection($app); + $firewall = $this->getFirewall($app); - $controllers->before(function () use ($app) { - $app['firewall']->requireAdmin(); + $controllers->before(function () use ($firewall) { + $firewall->requireAdmin(); }); $controllers->get('/', 'controller.admin.dashboard:slash') diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databox.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databox.php index 317e477197..18925ea9f9 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databox.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databox.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Admin\DataboxController; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\Security\Firewall; use Silex\Application; @@ -28,9 +29,7 @@ class Databox implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.admin.databox'] = $app->share(function (PhraseaApplication $app) { return (new DataboxController($app)) - ->setUserQueryFactory(function () use ($app) { - return $app['phraseanet.user-query']; - }) + ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php index 8952e8a887..6896148537 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin; use Alchemy\Phrasea\Controller\Admin\UserController; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; use Silex\ControllerProviderInterface; @@ -25,12 +26,8 @@ class Users implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.admin.users'] = $app->share(function () use ($app) { return (new UserController($app)) - ->setDelivererLocator(function () use ($app) { - return $app['notification.deliverer']; - }) - ->setUserQueryFactory(function () use ($app) { - return $app['phraseanet.user-query']; - }) + ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer')) + ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Datafiles.php b/lib/Alchemy/Phrasea/ControllerProvider/Datafiles.php index 93bcf4d1fd..c1e7757438 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Datafiles.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Datafiles.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\ControllerProvider; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\DatafileController; +use Alchemy\Phrasea\Controller\LazyLocator; use Silex\Application; use Silex\ControllerProviderInterface; use Silex\ServiceProviderInterface; @@ -25,9 +26,8 @@ class Datafiles implements ControllerProviderInterface, ServiceProviderInterface $app['controller.datafiles'] = $app->share(function (PhraseaApplication $app) { return (new DatafileController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication'])) ->setDataboxLoggerLocator($app['phraseanet.logger']) - ->setDelivererLocator(function () use ($app) { - return $app['phraseanet.file-serve']; - }); + ->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve')) + ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Permalink.php b/lib/Alchemy/Phrasea/ControllerProvider/Permalink.php index 06364f4a93..72bcdf08fe 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Permalink.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Permalink.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\PermalinkController; use Silex\Application; use Silex\ControllerCollection; @@ -25,9 +26,8 @@ class Permalink implements ControllerProviderInterface, ServiceProviderInterface $app['controller.permalink'] = $app->share(function (PhraseaApplication $app) { return (new PermalinkController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication'])) ->setDataboxLoggerLocator($app['phraseanet.logger']) - ->setDelivererLocator(function () use ($app) { - return $app['phraseanet.file-serve']; - }); + ->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve')) + ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/DoDownload.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/DoDownload.php index 7d217ae12a..251e075c75 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/DoDownload.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/DoDownload.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\DoDownloadController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -26,13 +27,10 @@ class DoDownload implements ControllerProviderInterface, ServiceProviderInterfac { $app['controller.prod.do-download'] = $app->share(function (PhraseaApplication $app) { return (new DoDownloadController($app)) - ->setDelivererLocator(function () use ($app) { - return $app['phraseanet.file-serve']; - }) + ->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve')) ->setDispatcher($app['dispatcher']) - ->setFileSystemLocator(function () use ($app) { - return $app['filesystem']; - }); + ->setFileSystemLocator(new LazyLocator($app, 'filesystem')) + ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php index 8503615f07..e0919be956 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\EditController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -28,9 +29,7 @@ class Edit implements ControllerProviderInterface, ServiceProviderInterface return (new EditController($app)) ->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDispatcher($app['dispatcher']) - ->setSubDefinitionSubstituerLocator(function () use ($app) { - return $app['subdef.substituer']; - }) + ->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Export.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Export.php index e77e0fc601..4da64bf878 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Export.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Export.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\ExportController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -27,12 +28,8 @@ class Export implements ControllerProviderInterface, ServiceProviderInterface $app['controller.prod.export'] = $app->share(function (PhraseaApplication $app) { return (new ExportController($app)) ->setDispatcher($app['dispatcher']) - ->setFileSystemLocator(function () use ($app) { - return $app['filesystem']; - }) - ->setDelivererLocator(function () use ($app) { - return $app['notification.deliverer']; - }) + ->setFileSystemLocator(new LazyLocator($app, 'filesystem')) + ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php index a70aa9e757..170637a9dc 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\LazaretController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -27,18 +28,10 @@ class Lazaret implements ControllerProviderInterface, ServiceProviderInterface $app['controller.prod.lazaret'] = $app->share(function (PhraseaApplication $app) { return (new LazaretController($app)) ->setDataboxLoggerLocator($app['phraseanet.logger']) - ->setDelivererLocator(function () use ($app) { - return $app['phraseanet.file-serve']; - }) - ->setEntityManagerLocator(function () use ($app) { - return $app['orm.em']; - }) - ->setFileSystemLocator(function () use ($app) { - return $app['filesystem']; - }) - ->setSubDefinitionSubstituerLocator(function () use ($app) { - return $app['subdef.substituer']; - }) + ->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve')) + ->setEntityManagerLocator(new LazyLocator($app, 'orm.em')) + ->setFileSystemLocator(new LazyLocator($app, 'filesystem')) + ->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php index 5c00c5fccc..17f5a1888a 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\OrderController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -27,12 +28,8 @@ class Order implements ControllerProviderInterface, ServiceProviderInterface $app['controller.prod.order'] = $app->share(function (PhraseaApplication $app) { return (new OrderController($app)) ->setDispatcher($app['dispatcher']) - ->setEntityManagerLocator(function () use ($app) { - return $app['orm.em']; - }) - ->setUserQueryFactory(function () use ($app) { - return $app['phraseanet.user-query']; - }) + ->setEntityManagerLocator(new LazyLocator($app, 'orm.em')) + ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Push.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Push.php index bf24f3fe28..3c8f0373e4 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Push.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Push.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\PushController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -28,12 +29,8 @@ class Push implements ControllerProviderInterface, ServiceProviderInterface return (new PushController($app)) ->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDispatcher($app['dispatcher']) - ->setEntityManagerLocator(function () use ($app) { - return $app['orm.em']; - }) - ->setUserQueryFactory(function () use ($app) { - return $app['phraseanet.user-query']; - }) + ->setEntityManagerLocator(new LazyLocator($app, 'orm.em')) + ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Query.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Query.php index c225e58265..7310077e82 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Query.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Query.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\QueryController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -26,12 +27,8 @@ class Query implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.prod.query'] = $app->share(function (PhraseaApplication $app) { return (new QueryController($app)) - ->setSearchEngineLocator(function () use ($app) { - return $app['phraseanet.SE']; - }) - ->setSearchEngineLoggerLocator(function () use ($app) { - return $app['phraseanet.SE.logger']; - }) + ->setSearchEngineLocator(new LazyLocator($app, 'phraseanet.SE')) + ->setSearchEngineLoggerLocator(new LazyLocator($app, 'phraseanet.SE.logger')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Record.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Record.php index c91c936a40..25bc501751 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Record.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Record.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\RecordController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -26,12 +27,8 @@ class Record implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.prod.records'] = $app->share(function (PhraseaApplication $app) { return (new RecordController($app)) - ->setEntityManagerLocator(function () use ($app) { - return $app['orm.em']; - }) - ->setSearchEngineLocator(function () use ($app) { - return $app['phraseanet.SE']; - }) + ->setEntityManagerLocator(new LazyLocator($app, 'orm.em')) + ->setSearchEngineLocator(new LazyLocator($app, 'phraseanet.SE')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Story.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Story.php index 811345c59e..6fc324d5db 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Story.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Story.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\StoryController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -27,9 +28,7 @@ class Story implements ControllerProviderInterface, ServiceProviderInterface $app['controller.prod.story'] = $app->share(function (PhraseaApplication $app) { return (new StoryController($app)) ->setDispatcher($app['dispatcher']) - ->setEntityManagerLocator(function () use ($app) { - return $app['orm.em']; - }) + ->setEntityManagerLocator(new LazyLocator($app, 'orm.em')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php index e9a689c1b8..d908cbae06 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\ToolsController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -27,12 +28,8 @@ class Tools implements ControllerProviderInterface, ServiceProviderInterface $app['controller.prod.tools'] = $app->share(function (PhraseaApplication $app) { return (new ToolsController($app)) ->setDataboxLoggerLocator($app['phraseanet.logger']) - ->setFileSystemLocator(function () use ($app) { - return $app['filesystem']; - }) - ->setSubDefinitionSubstituerLocator(function () use ($app) { - return $app['subdef.substituer']; - }) + ->setFileSystemLocator(new LazyLocator($app, 'filesystem')) + ->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tooltip.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tooltip.php index 9b766b2750..bad59209f8 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tooltip.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tooltip.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\TooltipController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -26,9 +27,7 @@ class Tooltip implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.prod.tooltip'] = $app->share(function (PhraseaApplication $app) { return (new TooltipController($app)) - ->setSearchEngineLocator(function () use ($app) { - return $app['phraseanet.SE']; - }) + ->setSearchEngineLocator(new LazyLocator($app, 'phraseanet.SE')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php index 498c78a843..f008f71c1b 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\Prod\UploadController; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; @@ -26,23 +27,13 @@ class Upload implements ControllerProviderInterface, ServiceProviderInterface { $app['controller.prod.upload'] = $app->share(function (PhraseaApplication $app) { return (new UploadController($app)) - ->setBorderManagerLocator(function () use ($app) { - return $app['border-manager']; - }) + ->setBorderManagerLocator(new LazyLocator($app, 'border-manager')) ->setDispatcher($app['dispatcher']) ->setDataboxLoggerLocator($app['phraseanet.logger']) - ->setEntityManagerLocator(function () use ($app) { - return $app['orm.em']; - }) - ->setFileSystemLocator(function () use ($app) { - return $app['filesystem']; - }) - ->setTemporaryFileSystemLocator(function () use ($app) { - return $app['temporary-filesystem']; - }) - ->setSubDefinitionSubstituerLocator(function () use ($app) { - return $app['subdef.substituer']; - }) + ->setEntityManagerLocator(new LazyLocator($app, 'orm.em')) + ->setFileSystemLocator(new LazyLocator($app, 'filesystem')) + ->setTemporaryFileSystemLocator(new LazyLocator($app, 'temporary-filesystem')) + ->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer')) ; }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Root/Account.php b/lib/Alchemy/Phrasea/ControllerProvider/Root/Account.php index f62a83e16d..bd27c0f118 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Root/Account.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Root/Account.php @@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Root; use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application\Helper\NotifierAware; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\Root\Login; use Alchemy\Phrasea\Exception\InvalidArgumentException; @@ -37,9 +38,7 @@ class Account implements ControllerProviderInterface public function connect(Application $app) { $app['account.controller'] = $this - ->setDelivererLocator(function () use ($app) { - return $app['notification.deliverer']; - }); + ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer')); $controllers = $this->createAuthenticatedCollection($app); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Root/Login.php b/lib/Alchemy/Phrasea/ControllerProvider/Root/Login.php index 2cca9141cc..e8f14c7c41 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Root/Login.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Root/Login.php @@ -17,6 +17,7 @@ use Alchemy\Phrasea\Authentication\Exception\NotAuthenticatedException; use Alchemy\Phrasea\Authentication\Exception\AuthenticationException; use Alchemy\Phrasea\Authentication\Context; use Alchemy\Phrasea\Authentication\Provider\ProviderInterface; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Core\Event\LogoutEvent; use Alchemy\Phrasea\Core\Event\PreAuthenticate; use Alchemy\Phrasea\Core\Event\PostAuthenticate; @@ -99,9 +100,8 @@ class Login implements ControllerProviderInterface $controllers = $app['controllers_factory']; $app['login.controller'] = $this - ->setDelivererLocator(function () use ($app) { - return $app['notification.deliverer']; - }); + ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer')) + ; $controllers->before(function (Request $request) use ($app) { if ($request->getPathInfo() == $app->path('homepage')) { diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/AbstractNotificationSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/AbstractNotificationSubscriber.php index f5c4224d9f..10f6ee5748 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/AbstractNotificationSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/AbstractNotificationSubscriber.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Core\Event\Subscriber; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application\Helper\NotifierAware; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Model\Entities\User; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -25,9 +26,7 @@ abstract class AbstractNotificationSubscriber implements EventSubscriberInterfac public function __construct(Application $app) { $this->app = $app; - $this->setDelivererLocator(function () use ($app) { - return $app['notification.deliverer']; - }); + $this->setDelivererLocator(new LazyLocator($app, 'notification.deliverer')); } protected function shouldSendNotificationFor(User $user, $type) diff --git a/lib/Alchemy/Phrasea/Core/Provider/TasksServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/TasksServiceProvider.php index 0289d81f99..da0e5f09a6 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/TasksServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/TasksServiceProvider.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\Core\Provider; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\TaskManager\Job\FtpJob; use Alchemy\Phrasea\TaskManager\Job\ArchiveJob; use Alchemy\Phrasea\TaskManager\Job\BridgeJob; @@ -75,9 +76,8 @@ class TasksServiceProvider implements ServiceProviderInterface return [ (new FtpJob($app['translator'], $app['dispatcher'], $logger)) - ->setDelivererLocator(function () use ($app) { - return $app['notification.deliverer']; - }), + ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer')) + , new ArchiveJob($app['translator'], $app['dispatcher'], $logger), new IndexerJob($app['translator'], $app['dispatcher'], $logger), new BridgeJob($app['translator'], $app['dispatcher'], $logger), diff --git a/lib/Alchemy/Phrasea/Helper/User/Edit.php b/lib/Alchemy/Phrasea/Helper/User/Edit.php index 9341b204be..69fd1e48b4 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Edit.php +++ b/lib/Alchemy/Phrasea/Helper/User/Edit.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Helper\User; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application\Helper\NotifierAware; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate; @@ -38,9 +39,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper public function __construct(Application $app, Request $Request) { parent::__construct($app, $Request); - $this->setDelivererLocator(function () use ($app) { - return $app['notification.deliverer']; - }); + $this->setDelivererLocator(new LazyLocator($app, 'notification.deliverer')); $this->users = explode(';', $Request->get('users')); diff --git a/lib/Alchemy/Phrasea/Helper/User/Manage.php b/lib/Alchemy/Phrasea/Helper/User/Manage.php index 24ec52107e..b18c6a5cb9 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Manage.php +++ b/lib/Alchemy/Phrasea/Helper/User/Manage.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Helper\User; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application\Helper\NotifierAware; +use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Helper\Helper; use Alchemy\Phrasea\Notification\Receiver; @@ -38,9 +39,7 @@ class Manage extends Helper { parent::__construct($app, $Request); - $this->setDelivererLocator(function () use ($app) { - return $app['notification.deliverer']; - }); + $this->setDelivererLocator(new LazyLocator($app, 'notification.deliverer')); } /**