]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Core/LightSlimApp.php
21d5f96ccddf5427ddf354441c95983342f9f424
[galette.git] / galette / lib / Galette / Core / LightSlimApp.php
1 <?php
2
3 /**
4 * Copyright © 2003-2024 The Galette Team
5 *
6 * This file is part of Galette (https://galette.eu).
7 *
8 * Galette is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Galette is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 namespace Galette\Core;
23
24 use DI\Bridge\Slim\Bridge;
25 use DI\ContainerBuilder;
26 use Slim\App;
27
28 /**
29 * Light Slim application
30 *
31 * @author Johan Cwiklinski <johan@x-tnd.be>
32 */
33 class LightSlimApp
34 {
35 private string $mode;
36 /** @var App */
37 private App $app;
38
39 /**
40 * Create a new Slim application
41 *
42 * @param string $mode Galette mode
43 */
44 public function __construct(string $mode = 'NEED_UPDATE')
45 {
46 $this->mode = $mode;
47
48 $builder = new ContainerBuilder();
49 $builder->useAttributes(true);
50 $builder->addDefinitions([
51 'templates.path' => GALETTE_ROOT . GALETTE_THEME,
52 'settings.displayErrorDetails' => Galette::isDebugEnabled(),
53 'settings.addContentLengthHeader' => false,
54 'galette' => [
55 'mode' => $this->mode,
56 'logger' => [
57 'name' => 'galette',
58 'level' => \Monolog\Logger::DEBUG,
59 'path' => GALETTE_LOGS_PATH . '/galette_slim.log',
60 ]
61 ],
62 'mode' => $this->mode,
63 'galette.mode' => $this->mode,
64 'session' => \DI\autowire('\RKA\Session')
65 ]);
66 $container = $builder->build();
67
68 $this->app = Bridge::create($container);
69 }
70
71 /**
72 * Get Slim application
73 *
74 * @return App
75 */
76 public function getApp(): App
77 {
78 return $this->app;
79 }
80 }