aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/container
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
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')
-rw-r--r--application/container/ContainerBuilder.php83
-rw-r--r--application/container/ShaarliContainer.php26
2 files changed, 103 insertions, 6 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;
diff --git a/application/container/ShaarliContainer.php b/application/container/ShaarliContainer.php
index 3fa9116e..c4fe753e 100644
--- a/application/container/ShaarliContainer.php
+++ b/application/container/ShaarliContainer.php
@@ -4,25 +4,45 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Container; 5namespace Shaarli\Container;
6 6
7use http\Cookie;
7use Shaarli\Bookmark\BookmarkServiceInterface; 8use Shaarli\Bookmark\BookmarkServiceInterface;
8use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
10use Shaarli\Feed\FeedBuilder;
11use Shaarli\Formatter\FormatterFactory;
9use Shaarli\History; 12use Shaarli\History;
13use Shaarli\Http\HttpAccess;
14use Shaarli\Netscape\NetscapeBookmarkUtils;
10use Shaarli\Plugin\PluginManager; 15use Shaarli\Plugin\PluginManager;
11use Shaarli\Render\PageBuilder; 16use Shaarli\Render\PageBuilder;
17use Shaarli\Render\PageCacheManager;
18use Shaarli\Security\CookieManager;
12use Shaarli\Security\LoginManager; 19use Shaarli\Security\LoginManager;
13use Shaarli\Security\SessionManager; 20use Shaarli\Security\SessionManager;
21use Shaarli\Thumbnailer;
22use Shaarli\Updater\Updater;
14use Slim\Container; 23use Slim\Container;
15 24
16/** 25/**
17 * Extension of Slim container to document the injected objects. 26 * Extension of Slim container to document the injected objects.
18 * 27 *
28 * @property string $basePath Shaarli's instance base path (e.g. `/shaarli/`)
29 * @property BookmarkServiceInterface $bookmarkService
30 * @property CookieManager $cookieManager
19 * @property ConfigManager $conf 31 * @property ConfigManager $conf
20 * @property SessionManager $sessionManager 32 * @property mixed[] $environment $_SERVER automatically injected by Slim
21 * @property LoginManager $loginManager 33 * @property callable $errorHandler Overrides default Slim error display
34 * @property FeedBuilder $feedBuilder
35 * @property FormatterFactory $formatterFactory
22 * @property History $history 36 * @property History $history
23 * @property BookmarkServiceInterface $bookmarkService 37 * @property HttpAccess $httpAccess
38 * @property LoginManager $loginManager
39 * @property NetscapeBookmarkUtils $netscapeBookmarkUtils
24 * @property PageBuilder $pageBuilder 40 * @property PageBuilder $pageBuilder
41 * @property PageCacheManager $pageCacheManager
25 * @property PluginManager $pluginManager 42 * @property PluginManager $pluginManager
43 * @property SessionManager $sessionManager
44 * @property Thumbnailer $thumbnailer
45 * @property Updater $updater
26 */ 46 */
27class ShaarliContainer extends Container 47class ShaarliContainer extends Container
28{ 48{