aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/container/ContainerBuilder.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-08-27 10:27:34 +0200
committerGitHub <noreply@github.com>2020-08-27 10:27:34 +0200
commitaf41d5ab5d2bd3ba64d052c997bc6afa6966a63c (patch)
tree8fad2829c55f94022e359fa8914e11f80a2afc2a /application/container/ContainerBuilder.php
parentb8e3630f2ecd142d397b1b062a346a667bb78595 (diff)
parent0c6fdbe12bbbb336348666b14b82096f24d5858b (diff)
downloadShaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.tar.gz
Shaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.tar.zst
Shaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.zip
Merge pull request #1511 from ArthurHoaro/wip-slim-routing
Diffstat (limited to 'application/container/ContainerBuilder.php')
-rw-r--r--application/container/ContainerBuilder.php83
1 files changed, 80 insertions, 3 deletions
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php
index e2c78ccc..4a1a6ea7 100644
--- a/application/container/ContainerBuilder.php
+++ b/application/container/ContainerBuilder.php
@@ -7,11 +7,21 @@ namespace Shaarli\Container;
7use Shaarli\Bookmark\BookmarkFileService; 7use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Bookmark\BookmarkServiceInterface; 8use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
10use Shaarli\Feed\FeedBuilder;
11use Shaarli\Formatter\FormatterFactory;
12use Shaarli\Front\Controller\Visitor\ErrorController;
10use Shaarli\History; 13use Shaarli\History;
14use Shaarli\Http\HttpAccess;
15use Shaarli\Netscape\NetscapeBookmarkUtils;
11use Shaarli\Plugin\PluginManager; 16use Shaarli\Plugin\PluginManager;
12use Shaarli\Render\PageBuilder; 17use Shaarli\Render\PageBuilder;
18use Shaarli\Render\PageCacheManager;
19use Shaarli\Security\CookieManager;
13use Shaarli\Security\LoginManager; 20use Shaarli\Security\LoginManager;
14use Shaarli\Security\SessionManager; 21use Shaarli\Security\SessionManager;
22use Shaarli\Thumbnailer;
23use Shaarli\Updater\Updater;
24use Shaarli\Updater\UpdaterUtils;
15 25
16/** 26/**
17 * Class ContainerBuilder 27 * Class ContainerBuilder
@@ -30,22 +40,37 @@ class ContainerBuilder
30 /** @var SessionManager */ 40 /** @var SessionManager */
31 protected $session; 41 protected $session;
32 42
43 /** @var CookieManager */
44 protected $cookieManager;
45
33 /** @var LoginManager */ 46 /** @var LoginManager */
34 protected $login; 47 protected $login;
35 48
36 public function __construct(ConfigManager $conf, SessionManager $session, LoginManager $login) 49 /** @var string|null */
37 { 50 protected $basePath = null;
51
52 public function __construct(
53 ConfigManager $conf,
54 SessionManager $session,
55 CookieManager $cookieManager,
56 LoginManager $login
57 ) {
38 $this->conf = $conf; 58 $this->conf = $conf;
39 $this->session = $session; 59 $this->session = $session;
40 $this->login = $login; 60 $this->login = $login;
61 $this->cookieManager = $cookieManager;
41 } 62 }
42 63
43 public function build(): ShaarliContainer 64 public function build(): ShaarliContainer
44 { 65 {
45 $container = new ShaarliContainer(); 66 $container = new ShaarliContainer();
67
46 $container['conf'] = $this->conf; 68 $container['conf'] = $this->conf;
47 $container['sessionManager'] = $this->session; 69 $container['sessionManager'] = $this->session;
70 $container['cookieManager'] = $this->cookieManager;
48 $container['loginManager'] = $this->login; 71 $container['loginManager'] = $this->login;
72 $container['basePath'] = $this->basePath;
73
49 $container['plugins'] = function (ShaarliContainer $container): PluginManager { 74 $container['plugins'] = function (ShaarliContainer $container): PluginManager {
50 return new PluginManager($container->conf); 75 return new PluginManager($container->conf);
51 }; 76 };
@@ -73,7 +98,59 @@ class ContainerBuilder
73 }; 98 };
74 99
75 $container['pluginManager'] = function (ShaarliContainer $container): PluginManager { 100 $container['pluginManager'] = function (ShaarliContainer $container): PluginManager {
76 return new PluginManager($container->conf); 101 $pluginManager = new PluginManager($container->conf);
102
103 $pluginManager->load($container->conf->get('general.enabled_plugins'));
104
105 return $pluginManager;
106 };
107
108 $container['formatterFactory'] = function (ShaarliContainer $container): FormatterFactory {
109 return new FormatterFactory(
110 $container->conf,
111 $container->loginManager->isLoggedIn()
112 );
113 };
114
115 $container['pageCacheManager'] = function (ShaarliContainer $container): PageCacheManager {
116 return new PageCacheManager(
117 $container->conf->get('resource.page_cache'),
118 $container->loginManager->isLoggedIn()
119 );
120 };
121
122 $container['feedBuilder'] = function (ShaarliContainer $container): FeedBuilder {
123 return new FeedBuilder(
124 $container->bookmarkService,
125 $container->formatterFactory->getFormatter(),
126 $container->environment,
127 $container->loginManager->isLoggedIn()
128 );
129 };
130
131 $container['thumbnailer'] = function (ShaarliContainer $container): Thumbnailer {
132 return new Thumbnailer($container->conf);
133 };
134
135 $container['httpAccess'] = function (): HttpAccess {
136 return new HttpAccess();
137 };
138
139 $container['netscapeBookmarkUtils'] = function (ShaarliContainer $container): NetscapeBookmarkUtils {
140 return new NetscapeBookmarkUtils($container->bookmarkService, $container->conf, $container->history);
141 };
142
143 $container['updater'] = function (ShaarliContainer $container): Updater {
144 return new Updater(
145 UpdaterUtils::read_updates_file($container->conf->get('resource.updates')),
146 $container->bookmarkService,
147 $container->conf,
148 $container->loginManager->isLoggedIn()
149 );
150 };
151
152 $container['errorHandler'] = function (ShaarliContainer $container): ErrorController {
153 return new ErrorController($container);
77 }; 154 };
78 155
79 return $container; 156 return $container;