aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/container/ContainerBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/container/ContainerBuilder.php')
-rw-r--r--application/container/ContainerBuilder.php105
1 files changed, 102 insertions, 3 deletions
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php
index e2c78ccc..d84418ad 100644
--- a/application/container/ContainerBuilder.php
+++ b/application/container/ContainerBuilder.php
@@ -4,14 +4,28 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Container; 5namespace Shaarli\Container;
6 6
7use malkusch\lock\mutex\FlockMutex;
8use Psr\Log\LoggerInterface;
7use Shaarli\Bookmark\BookmarkFileService; 9use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Bookmark\BookmarkServiceInterface; 10use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Config\ConfigManager; 11use Shaarli\Config\ConfigManager;
12use Shaarli\Feed\FeedBuilder;
13use Shaarli\Formatter\FormatterFactory;
14use Shaarli\Front\Controller\Visitor\ErrorController;
15use Shaarli\Front\Controller\Visitor\ErrorNotFoundController;
10use Shaarli\History; 16use Shaarli\History;
17use Shaarli\Http\HttpAccess;
18use Shaarli\Http\MetadataRetriever;
19use Shaarli\Netscape\NetscapeBookmarkUtils;
11use Shaarli\Plugin\PluginManager; 20use Shaarli\Plugin\PluginManager;
12use Shaarli\Render\PageBuilder; 21use Shaarli\Render\PageBuilder;
22use Shaarli\Render\PageCacheManager;
23use Shaarli\Security\CookieManager;
13use Shaarli\Security\LoginManager; 24use Shaarli\Security\LoginManager;
14use Shaarli\Security\SessionManager; 25use Shaarli\Security\SessionManager;
26use Shaarli\Thumbnailer;
27use Shaarli\Updater\Updater;
28use Shaarli\Updater\UpdaterUtils;
15 29
16/** 30/**
17 * Class ContainerBuilder 31 * Class ContainerBuilder
@@ -30,22 +44,43 @@ class ContainerBuilder
30 /** @var SessionManager */ 44 /** @var SessionManager */
31 protected $session; 45 protected $session;
32 46
47 /** @var CookieManager */
48 protected $cookieManager;
49
33 /** @var LoginManager */ 50 /** @var LoginManager */
34 protected $login; 51 protected $login;
35 52
36 public function __construct(ConfigManager $conf, SessionManager $session, LoginManager $login) 53 /** @var LoggerInterface */
37 { 54 protected $logger;
55
56 /** @var string|null */
57 protected $basePath = null;
58
59 public function __construct(
60 ConfigManager $conf,
61 SessionManager $session,
62 CookieManager $cookieManager,
63 LoginManager $login,
64 LoggerInterface $logger
65 ) {
38 $this->conf = $conf; 66 $this->conf = $conf;
39 $this->session = $session; 67 $this->session = $session;
40 $this->login = $login; 68 $this->login = $login;
69 $this->cookieManager = $cookieManager;
70 $this->logger = $logger;
41 } 71 }
42 72
43 public function build(): ShaarliContainer 73 public function build(): ShaarliContainer
44 { 74 {
45 $container = new ShaarliContainer(); 75 $container = new ShaarliContainer();
76
46 $container['conf'] = $this->conf; 77 $container['conf'] = $this->conf;
47 $container['sessionManager'] = $this->session; 78 $container['sessionManager'] = $this->session;
79 $container['cookieManager'] = $this->cookieManager;
48 $container['loginManager'] = $this->login; 80 $container['loginManager'] = $this->login;
81 $container['logger'] = $this->logger;
82 $container['basePath'] = $this->basePath;
83
49 $container['plugins'] = function (ShaarliContainer $container): PluginManager { 84 $container['plugins'] = function (ShaarliContainer $container): PluginManager {
50 return new PluginManager($container->conf); 85 return new PluginManager($container->conf);
51 }; 86 };
@@ -58,14 +93,20 @@ class ContainerBuilder
58 return new BookmarkFileService( 93 return new BookmarkFileService(
59 $container->conf, 94 $container->conf,
60 $container->history, 95 $container->history,
96 new FlockMutex(fopen(SHAARLI_MUTEX_FILE, 'r'), 2),
61 $container->loginManager->isLoggedIn() 97 $container->loginManager->isLoggedIn()
62 ); 98 );
63 }; 99 };
64 100
101 $container['metadataRetriever'] = function (ShaarliContainer $container): MetadataRetriever {
102 return new MetadataRetriever($container->conf, $container->httpAccess);
103 };
104
65 $container['pageBuilder'] = function (ShaarliContainer $container): PageBuilder { 105 $container['pageBuilder'] = function (ShaarliContainer $container): PageBuilder {
66 return new PageBuilder( 106 return new PageBuilder(
67 $container->conf, 107 $container->conf,
68 $container->sessionManager->getSession(), 108 $container->sessionManager->getSession(),
109 $container->logger,
69 $container->bookmarkService, 110 $container->bookmarkService,
70 $container->sessionManager->generateToken(), 111 $container->sessionManager->generateToken(),
71 $container->loginManager->isLoggedIn() 112 $container->loginManager->isLoggedIn()
@@ -73,7 +114,65 @@ class ContainerBuilder
73 }; 114 };
74 115
75 $container['pluginManager'] = function (ShaarliContainer $container): PluginManager { 116 $container['pluginManager'] = function (ShaarliContainer $container): PluginManager {
76 return new PluginManager($container->conf); 117 $pluginManager = new PluginManager($container->conf);
118
119 $pluginManager->load($container->conf->get('general.enabled_plugins'));
120
121 return $pluginManager;
122 };
123
124 $container['formatterFactory'] = function (ShaarliContainer $container): FormatterFactory {
125 return new FormatterFactory(
126 $container->conf,
127 $container->loginManager->isLoggedIn()
128 );
129 };
130
131 $container['pageCacheManager'] = function (ShaarliContainer $container): PageCacheManager {
132 return new PageCacheManager(
133 $container->conf->get('resource.page_cache'),
134 $container->loginManager->isLoggedIn()
135 );
136 };
137
138 $container['feedBuilder'] = function (ShaarliContainer $container): FeedBuilder {
139 return new FeedBuilder(
140 $container->bookmarkService,
141 $container->formatterFactory->getFormatter(),
142 $container->environment,
143 $container->loginManager->isLoggedIn()
144 );
145 };
146
147 $container['thumbnailer'] = function (ShaarliContainer $container): Thumbnailer {
148 return new Thumbnailer($container->conf);
149 };
150
151 $container['httpAccess'] = function (): HttpAccess {
152 return new HttpAccess();
153 };
154
155 $container['netscapeBookmarkUtils'] = function (ShaarliContainer $container): NetscapeBookmarkUtils {
156 return new NetscapeBookmarkUtils($container->bookmarkService, $container->conf, $container->history);
157 };
158
159 $container['updater'] = function (ShaarliContainer $container): Updater {
160 return new Updater(
161 UpdaterUtils::read_updates_file($container->conf->get('resource.updates')),
162 $container->bookmarkService,
163 $container->conf,
164 $container->loginManager->isLoggedIn()
165 );
166 };
167
168 $container['notFoundHandler'] = function (ShaarliContainer $container): ErrorNotFoundController {
169 return new ErrorNotFoundController($container);
170 };
171 $container['errorHandler'] = function (ShaarliContainer $container): ErrorController {
172 return new ErrorController($container);
173 };
174 $container['phpErrorHandler'] = function (ShaarliContainer $container): ErrorController {
175 return new ErrorController($container);
77 }; 176 };
78 177
79 return $container; 178 return $container;