aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/container
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-18 17:50:11 +0100
committerArthurHoaro <arthur@hoa.ro>2020-01-26 11:34:14 +0100
commit6c50a6ccceecf54850e62c312ab2397b84d89ab4 (patch)
tree3205aa447930eab020ea04bf00082880abec5001 /application/container
parent1410dce2db310e71b5e683b0871c2f28d8807844 (diff)
downloadShaarli-6c50a6ccceecf54850e62c312ab2397b84d89ab4.tar.gz
Shaarli-6c50a6ccceecf54850e62c312ab2397b84d89ab4.tar.zst
Shaarli-6c50a6ccceecf54850e62c312ab2397b84d89ab4.zip
Render login page through Slim controller
Diffstat (limited to 'application/container')
-rw-r--r--application/container/ContainerBuilder.php77
-rw-r--r--application/container/ShaarliContainer.php28
2 files changed, 105 insertions, 0 deletions
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php
new file mode 100644
index 00000000..ff29825c
--- /dev/null
+++ b/application/container/ContainerBuilder.php
@@ -0,0 +1,77 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Container;
6
7use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Config\ConfigManager;
10use Shaarli\History;
11use Shaarli\Plugin\PluginManager;
12use Shaarli\Render\PageBuilder;
13use Shaarli\Security\LoginManager;
14use Shaarli\Security\SessionManager;
15
16/**
17 * Class ContainerBuilder
18 *
19 * Helper used to build a Slim container instance with Shaarli's object dependencies.
20 * Note that most injected objects MUST be added as closures, to let the container instantiate
21 * only the objects it requires during the execution.
22 *
23 * @package Container
24 */
25class ContainerBuilder
26{
27 /** @var ConfigManager */
28 protected $conf;
29
30 /** @var SessionManager */
31 protected $session;
32
33 /** @var LoginManager */
34 protected $login;
35
36 public function __construct(ConfigManager $conf, SessionManager $session, LoginManager $login)
37 {
38 $this->conf = $conf;
39 $this->session = $session;
40 $this->login = $login;
41 }
42
43 public function build(): ShaarliContainer
44 {
45 $container = new ShaarliContainer();
46 $container['conf'] = $this->conf;
47 $container['sessionManager'] = $this->session;
48 $container['loginManager'] = $this->login;
49 $container['plugins'] = function (ShaarliContainer $container): PluginManager {
50 return new PluginManager($container->conf);
51 };
52
53 $container['history'] = function (ShaarliContainer $container): History {
54 return new History($container->conf->get('resource.history'));
55 };
56
57 $container['bookmarkService'] = function (ShaarliContainer $container): BookmarkServiceInterface {
58 return new BookmarkFileService(
59 $container->conf,
60 $container->history,
61 $container->loginManager->isLoggedIn()
62 );
63 };
64
65 $container['pageBuilder'] = function (ShaarliContainer $container): PageBuilder {
66 return new PageBuilder(
67 $container->conf,
68 $container->sessionManager->getSession(),
69 $container->bookmarkService,
70 $container->sessionManager->generateToken(),
71 $container->loginManager->isLoggedIn()
72 );
73 };
74
75 return $container;
76 }
77}
diff --git a/application/container/ShaarliContainer.php b/application/container/ShaarliContainer.php
new file mode 100644
index 00000000..f5483d5e
--- /dev/null
+++ b/application/container/ShaarliContainer.php
@@ -0,0 +1,28 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Container;
6
7use Shaarli\Bookmark\BookmarkServiceInterface;
8use Shaarli\Config\ConfigManager;
9use Shaarli\History;
10use Shaarli\Render\PageBuilder;
11use Shaarli\Security\LoginManager;
12use Shaarli\Security\SessionManager;
13use Slim\Container;
14
15/**
16 * Extension of Slim container to document the injected objects.
17 *
18 * @property ConfigManager $conf
19 * @property SessionManager $sessionManager
20 * @property LoginManager $loginManager
21 * @property History $history
22 * @property BookmarkServiceInterface $bookmarkService
23 * @property PageBuilder $pageBuilder
24 */
25class ShaarliContainer extends Container
26{
27
28}