Add LazyLocator

This commit is contained in:
Benoît Burnichon
2015-06-02 14:42:00 +02:00
parent fe057a8a6b
commit 7be5e332db
26 changed files with 117 additions and 126 deletions

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2015 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller;
class LazyLocator
{
/** @var \Pimple */
private $pimple;
private $serviceId;
/**
* @param \Pimple $pimple
* @param string $serviceId
*/
public function __construct(\Pimple $pimple, $serviceId)
{
$this->pimple = $pimple;
$this->serviceId = $serviceId;
}
public function __invoke()
{
return $this->pimple->offsetGet($this->serviceId);
}
}

View File

@@ -13,10 +13,12 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Admin\CollectionController; use Alchemy\Phrasea\Controller\Admin\CollectionController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ServiceProviderInterface; use Silex\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\Request;
class Collection implements ControllerProviderInterface, ServiceProviderInterface class Collection implements ControllerProviderInterface, ServiceProviderInterface
{ {
@@ -26,9 +28,7 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac
{ {
$app['controller.admin.collection'] = $app->share(function (PhraseaApplication $app) { $app['controller.admin.collection'] = $app->share(function (PhraseaApplication $app) {
return (new CollectionController($app)) return (new CollectionController($app))
->setUserQueryFactory(function () use ($app) { ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
return $app['phraseanet.user-query'];
})
; ;
}); });
} }
@@ -40,10 +40,12 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac
public function connect(Application $app) public function connect(Application $app)
{ {
$controllers = $this->createAuthenticatedCollection($app); $controllers = $this->createAuthenticatedCollection($app);
$firewall = $this->getFirewall($app);
$controllers->before(function () use ($app) { $controllers->before(function (Request $request) use ($firewall) {
$app['firewall']->requireAccessToModule('admin') $firewall
->requireRightOnBase($app['request']->attributes->get('bas_id'), 'canadmin'); ->requireAccessToModule('admin')
->requireRightOnBase($request->attributes->get('bas_id'), 'canadmin');
}); });
$controllers->get('/{bas_id}/', 'controller.admin.collection:getCollection') $controllers->get('/{bas_id}/', 'controller.admin.collection:getCollection')

View File

@@ -46,9 +46,10 @@ class ConnectedUsers implements ControllerProviderInterface, ServiceProviderInte
public function connect(Application $app) public function connect(Application $app)
{ {
$controllers = $this->createAuthenticatedCollection($app); $controllers = $this->createAuthenticatedCollection($app);
$firewall = $this->getFirewall($app);
$controllers->before(function () use ($app) { $controllers->before(function () use ($firewall) {
$app['firewall']->requireAccessToModule('Admin'); $firewall->requireAccessToModule('Admin');
}); });
$controllers->get('/', 'controller.admin.connected-users:listConnectedUsers') $controllers->get('/', 'controller.admin.connected-users:listConnectedUsers')

View File

@@ -13,6 +13,8 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Admin\DashboardController; use Alchemy\Phrasea\Controller\Admin\DashboardController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
use Silex\ControllerCollection; use Silex\ControllerCollection;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
@@ -20,13 +22,14 @@ use Silex\ServiceProviderInterface;
class Dashboard implements ControllerProviderInterface, ServiceProviderInterface class Dashboard implements ControllerProviderInterface, ServiceProviderInterface
{ {
use ControllerProviderTrait;
public function register(Application $app) public function register(Application $app)
{ {
$app['controller.admin.dashboard'] = $app->share(function (PhraseaApplication $app) { $app['controller.admin.dashboard'] = $app->share(function (PhraseaApplication $app) {
return (new DashboardController($app)) return (new DashboardController($app))
->setDelivererLocator(function () use ($app) { ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
return $app['notification.deliverer']; ;
});
}); });
} }
@@ -36,11 +39,11 @@ class Dashboard implements ControllerProviderInterface, ServiceProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
/** @var ControllerCollection $controllers */ $controllers = $this->createCollection($app);
$controllers = $app['controllers_factory']; $firewall = $this->getFirewall($app);
$controllers->before(function () use ($app) { $controllers->before(function () use ($firewall) {
$app['firewall']->requireAdmin(); $firewall->requireAdmin();
}); });
$controllers->get('/', 'controller.admin.dashboard:slash') $controllers->get('/', 'controller.admin.dashboard:slash')

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Admin\DataboxController; use Alchemy\Phrasea\Controller\Admin\DataboxController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Alchemy\Phrasea\Security\Firewall; use Alchemy\Phrasea\Security\Firewall;
use Silex\Application; use Silex\Application;
@@ -28,9 +29,7 @@ class Databox implements ControllerProviderInterface, ServiceProviderInterface
{ {
$app['controller.admin.databox'] = $app->share(function (PhraseaApplication $app) { $app['controller.admin.databox'] = $app->share(function (PhraseaApplication $app) {
return (new DataboxController($app)) return (new DataboxController($app))
->setUserQueryFactory(function () use ($app) { ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
return $app['phraseanet.user-query'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Admin; namespace Alchemy\Phrasea\ControllerProvider\Admin;
use Alchemy\Phrasea\Controller\Admin\UserController; use Alchemy\Phrasea\Controller\Admin\UserController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
@@ -25,12 +26,8 @@ class Users implements ControllerProviderInterface, ServiceProviderInterface
{ {
$app['controller.admin.users'] = $app->share(function () use ($app) { $app['controller.admin.users'] = $app->share(function () use ($app) {
return (new UserController($app)) return (new UserController($app))
->setDelivererLocator(function () use ($app) { ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
return $app['notification.deliverer']; ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
})
->setUserQueryFactory(function () use ($app) {
return $app['phraseanet.user-query'];
})
; ;
}); });
} }

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\ControllerProvider;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\DatafileController; use Alchemy\Phrasea\Controller\DatafileController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ServiceProviderInterface; use Silex\ServiceProviderInterface;
@@ -25,9 +26,8 @@ class Datafiles implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.datafiles'] = $app->share(function (PhraseaApplication $app) { $app['controller.datafiles'] = $app->share(function (PhraseaApplication $app) {
return (new DatafileController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication'])) return (new DatafileController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication']))
->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDelivererLocator(function () use ($app) { ->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve'))
return $app['phraseanet.file-serve']; ;
});
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider; namespace Alchemy\Phrasea\ControllerProvider;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\PermalinkController; use Alchemy\Phrasea\Controller\PermalinkController;
use Silex\Application; use Silex\Application;
use Silex\ControllerCollection; use Silex\ControllerCollection;
@@ -25,9 +26,8 @@ class Permalink implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.permalink'] = $app->share(function (PhraseaApplication $app) { $app['controller.permalink'] = $app->share(function (PhraseaApplication $app) {
return (new PermalinkController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication'])) return (new PermalinkController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication']))
->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDelivererLocator(function () use ($app) { ->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve'))
return $app['phraseanet.file-serve']; ;
});
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\DoDownloadController; use Alchemy\Phrasea\Controller\Prod\DoDownloadController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -26,13 +27,10 @@ class DoDownload implements ControllerProviderInterface, ServiceProviderInterfac
{ {
$app['controller.prod.do-download'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.do-download'] = $app->share(function (PhraseaApplication $app) {
return (new DoDownloadController($app)) return (new DoDownloadController($app))
->setDelivererLocator(function () use ($app) { ->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve'))
return $app['phraseanet.file-serve'];
})
->setDispatcher($app['dispatcher']) ->setDispatcher($app['dispatcher'])
->setFileSystemLocator(function () use ($app) { ->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
return $app['filesystem']; ;
});
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\EditController; use Alchemy\Phrasea\Controller\Prod\EditController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -28,9 +29,7 @@ class Edit implements ControllerProviderInterface, ServiceProviderInterface
return (new EditController($app)) return (new EditController($app))
->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDispatcher($app['dispatcher']) ->setDispatcher($app['dispatcher'])
->setSubDefinitionSubstituerLocator(function () use ($app) { ->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer'))
return $app['subdef.substituer'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\ExportController; use Alchemy\Phrasea\Controller\Prod\ExportController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -27,12 +28,8 @@ class Export implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.export'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.export'] = $app->share(function (PhraseaApplication $app) {
return (new ExportController($app)) return (new ExportController($app))
->setDispatcher($app['dispatcher']) ->setDispatcher($app['dispatcher'])
->setFileSystemLocator(function () use ($app) { ->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
return $app['filesystem']; ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
})
->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\LazaretController; use Alchemy\Phrasea\Controller\Prod\LazaretController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -27,18 +28,10 @@ class Lazaret implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.lazaret'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.lazaret'] = $app->share(function (PhraseaApplication $app) {
return (new LazaretController($app)) return (new LazaretController($app))
->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDelivererLocator(function () use ($app) { ->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve'))
return $app['phraseanet.file-serve']; ->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
}) ->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
->setEntityManagerLocator(function () use ($app) { ->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer'))
return $app['orm.em'];
})
->setFileSystemLocator(function () use ($app) {
return $app['filesystem'];
})
->setSubDefinitionSubstituerLocator(function () use ($app) {
return $app['subdef.substituer'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\OrderController; use Alchemy\Phrasea\Controller\Prod\OrderController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -27,12 +28,8 @@ class Order implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.order'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.order'] = $app->share(function (PhraseaApplication $app) {
return (new OrderController($app)) return (new OrderController($app))
->setDispatcher($app['dispatcher']) ->setDispatcher($app['dispatcher'])
->setEntityManagerLocator(function () use ($app) { ->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
return $app['orm.em']; ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
})
->setUserQueryFactory(function () use ($app) {
return $app['phraseanet.user-query'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\PushController; use Alchemy\Phrasea\Controller\Prod\PushController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -28,12 +29,8 @@ class Push implements ControllerProviderInterface, ServiceProviderInterface
return (new PushController($app)) return (new PushController($app))
->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDispatcher($app['dispatcher']) ->setDispatcher($app['dispatcher'])
->setEntityManagerLocator(function () use ($app) { ->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
return $app['orm.em']; ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
})
->setUserQueryFactory(function () use ($app) {
return $app['phraseanet.user-query'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\QueryController; use Alchemy\Phrasea\Controller\Prod\QueryController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -26,12 +27,8 @@ class Query implements ControllerProviderInterface, ServiceProviderInterface
{ {
$app['controller.prod.query'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.query'] = $app->share(function (PhraseaApplication $app) {
return (new QueryController($app)) return (new QueryController($app))
->setSearchEngineLocator(function () use ($app) { ->setSearchEngineLocator(new LazyLocator($app, 'phraseanet.SE'))
return $app['phraseanet.SE']; ->setSearchEngineLoggerLocator(new LazyLocator($app, 'phraseanet.SE.logger'))
})
->setSearchEngineLoggerLocator(function () use ($app) {
return $app['phraseanet.SE.logger'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\RecordController; use Alchemy\Phrasea\Controller\Prod\RecordController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -26,12 +27,8 @@ class Record implements ControllerProviderInterface, ServiceProviderInterface
{ {
$app['controller.prod.records'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.records'] = $app->share(function (PhraseaApplication $app) {
return (new RecordController($app)) return (new RecordController($app))
->setEntityManagerLocator(function () use ($app) { ->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
return $app['orm.em']; ->setSearchEngineLocator(new LazyLocator($app, 'phraseanet.SE'))
})
->setSearchEngineLocator(function () use ($app) {
return $app['phraseanet.SE'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\StoryController; use Alchemy\Phrasea\Controller\Prod\StoryController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -27,9 +28,7 @@ class Story implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.story'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.story'] = $app->share(function (PhraseaApplication $app) {
return (new StoryController($app)) return (new StoryController($app))
->setDispatcher($app['dispatcher']) ->setDispatcher($app['dispatcher'])
->setEntityManagerLocator(function () use ($app) { ->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
return $app['orm.em'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\ToolsController; use Alchemy\Phrasea\Controller\Prod\ToolsController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -27,12 +28,8 @@ class Tools implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.tools'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.tools'] = $app->share(function (PhraseaApplication $app) {
return (new ToolsController($app)) return (new ToolsController($app))
->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDataboxLoggerLocator($app['phraseanet.logger'])
->setFileSystemLocator(function () use ($app) { ->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
return $app['filesystem']; ->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer'))
})
->setSubDefinitionSubstituerLocator(function () use ($app) {
return $app['subdef.substituer'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\TooltipController; use Alchemy\Phrasea\Controller\Prod\TooltipController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -26,9 +27,7 @@ class Tooltip implements ControllerProviderInterface, ServiceProviderInterface
{ {
$app['controller.prod.tooltip'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.tooltip'] = $app->share(function (PhraseaApplication $app) {
return (new TooltipController($app)) return (new TooltipController($app))
->setSearchEngineLocator(function () use ($app) { ->setSearchEngineLocator(new LazyLocator($app, 'phraseanet.SE'))
return $app['phraseanet.SE'];
})
; ;
}); });
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\UploadController; use Alchemy\Phrasea\Controller\Prod\UploadController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application; use Silex\Application;
@@ -26,23 +27,13 @@ class Upload implements ControllerProviderInterface, ServiceProviderInterface
{ {
$app['controller.prod.upload'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.upload'] = $app->share(function (PhraseaApplication $app) {
return (new UploadController($app)) return (new UploadController($app))
->setBorderManagerLocator(function () use ($app) { ->setBorderManagerLocator(new LazyLocator($app, 'border-manager'))
return $app['border-manager'];
})
->setDispatcher($app['dispatcher']) ->setDispatcher($app['dispatcher'])
->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDataboxLoggerLocator($app['phraseanet.logger'])
->setEntityManagerLocator(function () use ($app) { ->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
return $app['orm.em']; ->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
}) ->setTemporaryFileSystemLocator(new LazyLocator($app, 'temporary-filesystem'))
->setFileSystemLocator(function () use ($app) { ->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer'))
return $app['filesystem'];
})
->setTemporaryFileSystemLocator(function () use ($app) {
return $app['temporary-filesystem'];
})
->setSubDefinitionSubstituerLocator(function () use ($app) {
return $app['subdef.substituer'];
})
; ;
}); });
} }

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Root;
use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface; use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Application\Helper\NotifierAware; use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Alchemy\Phrasea\ControllerProvider\Root\Login; use Alchemy\Phrasea\ControllerProvider\Root\Login;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
@@ -37,9 +38,7 @@ class Account implements ControllerProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
$app['account.controller'] = $this $app['account.controller'] = $this
->setDelivererLocator(function () use ($app) { ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'));
return $app['notification.deliverer'];
});
$controllers = $this->createAuthenticatedCollection($app); $controllers = $this->createAuthenticatedCollection($app);

View File

@@ -17,6 +17,7 @@ use Alchemy\Phrasea\Authentication\Exception\NotAuthenticatedException;
use Alchemy\Phrasea\Authentication\Exception\AuthenticationException; use Alchemy\Phrasea\Authentication\Exception\AuthenticationException;
use Alchemy\Phrasea\Authentication\Context; use Alchemy\Phrasea\Authentication\Context;
use Alchemy\Phrasea\Authentication\Provider\ProviderInterface; use Alchemy\Phrasea\Authentication\Provider\ProviderInterface;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Core\Event\LogoutEvent; use Alchemy\Phrasea\Core\Event\LogoutEvent;
use Alchemy\Phrasea\Core\Event\PreAuthenticate; use Alchemy\Phrasea\Core\Event\PreAuthenticate;
use Alchemy\Phrasea\Core\Event\PostAuthenticate; use Alchemy\Phrasea\Core\Event\PostAuthenticate;
@@ -99,9 +100,8 @@ class Login implements ControllerProviderInterface
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$app['login.controller'] = $this $app['login.controller'] = $this
->setDelivererLocator(function () use ($app) { ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
return $app['notification.deliverer']; ;
});
$controllers->before(function (Request $request) use ($app) { $controllers->before(function (Request $request) use ($app) {
if ($request->getPathInfo() == $app->path('homepage')) { if ($request->getPathInfo() == $app->path('homepage')) {

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application\Helper\NotifierAware; use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -25,9 +26,7 @@ abstract class AbstractNotificationSubscriber implements EventSubscriberInterfac
public function __construct(Application $app) public function __construct(Application $app)
{ {
$this->app = $app; $this->app = $app;
$this->setDelivererLocator(function () use ($app) { $this->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'));
return $app['notification.deliverer'];
});
} }
protected function shouldSendNotificationFor(User $user, $type) protected function shouldSendNotificationFor(User $user, $type)

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Core\Provider; namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\TaskManager\Job\FtpJob; use Alchemy\Phrasea\TaskManager\Job\FtpJob;
use Alchemy\Phrasea\TaskManager\Job\ArchiveJob; use Alchemy\Phrasea\TaskManager\Job\ArchiveJob;
use Alchemy\Phrasea\TaskManager\Job\BridgeJob; use Alchemy\Phrasea\TaskManager\Job\BridgeJob;
@@ -75,9 +76,8 @@ class TasksServiceProvider implements ServiceProviderInterface
return [ return [
(new FtpJob($app['translator'], $app['dispatcher'], $logger)) (new FtpJob($app['translator'], $app['dispatcher'], $logger))
->setDelivererLocator(function () use ($app) { ->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
return $app['notification.deliverer']; ,
}),
new ArchiveJob($app['translator'], $app['dispatcher'], $logger), new ArchiveJob($app['translator'], $app['dispatcher'], $logger),
new IndexerJob($app['translator'], $app['dispatcher'], $logger), new IndexerJob($app['translator'], $app['dispatcher'], $logger),
new BridgeJob($app['translator'], $app['dispatcher'], $logger), new BridgeJob($app['translator'], $app['dispatcher'], $logger),

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Helper\User;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application\Helper\NotifierAware; use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate; use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate;
@@ -38,9 +39,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
public function __construct(Application $app, Request $Request) public function __construct(Application $app, Request $Request)
{ {
parent::__construct($app, $Request); parent::__construct($app, $Request);
$this->setDelivererLocator(function () use ($app) { $this->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'));
return $app['notification.deliverer'];
});
$this->users = explode(';', $Request->get('users')); $this->users = explode(';', $Request->get('users'));

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Helper\User;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application\Helper\NotifierAware; use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Helper\Helper; use Alchemy\Phrasea\Helper\Helper;
use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Receiver;
@@ -38,9 +39,7 @@ class Manage extends Helper
{ {
parent::__construct($app, $Request); parent::__construct($app, $Request);
$this->setDelivererLocator(function () use ($app) { $this->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'));
return $app['notification.deliverer'];
});
} }
/** /**