diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-18 17:50:11 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-01-26 11:34:14 +0100 |
commit | 6c50a6ccceecf54850e62c312ab2397b84d89ab4 (patch) | |
tree | 3205aa447930eab020ea04bf00082880abec5001 /application/container | |
parent | 1410dce2db310e71b5e683b0871c2f28d8807844 (diff) | |
download | Shaarli-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.php | 77 | ||||
-rw-r--r-- | application/container/ShaarliContainer.php | 28 |
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 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Container; | ||
6 | |||
7 | use Shaarli\Bookmark\BookmarkFileService; | ||
8 | use Shaarli\Bookmark\BookmarkServiceInterface; | ||
9 | use Shaarli\Config\ConfigManager; | ||
10 | use Shaarli\History; | ||
11 | use Shaarli\Plugin\PluginManager; | ||
12 | use Shaarli\Render\PageBuilder; | ||
13 | use Shaarli\Security\LoginManager; | ||
14 | use 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 | */ | ||
25 | class 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 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Container; | ||
6 | |||
7 | use Shaarli\Bookmark\BookmarkServiceInterface; | ||
8 | use Shaarli\Config\ConfigManager; | ||
9 | use Shaarli\History; | ||
10 | use Shaarli\Render\PageBuilder; | ||
11 | use Shaarli\Security\LoginManager; | ||
12 | use Shaarli\Security\SessionManager; | ||
13 | use 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 | */ | ||
25 | class ShaarliContainer extends Container | ||
26 | { | ||
27 | |||
28 | } | ||