Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ApplicationAbstract
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __set
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 __get
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\Application
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace phpOMS\Application;
16
17use phpOMS\Account\AccountManager;
18use phpOMS\Config\SettingsInterface;
19use phpOMS\DataStorage\Cache\CachePool;
20use phpOMS\DataStorage\Cookie\CookieJar;
21use phpOMS\DataStorage\Database\DatabasePool;
22use phpOMS\DataStorage\Session\SessionInterface;
23use phpOMS\Dispatcher\Dispatcher;
24use phpOMS\Event\EventManager;
25use phpOMS\Localization\L11nManager;
26use phpOMS\Localization\Localization;
27use phpOMS\Log\FileLogger;
28use phpOMS\Module\ModuleManager;
29use phpOMS\Router\RouterInterface;
30
31/**
32 * Application class.
33 *
34 * This class contains all necessary application members. Access to them
35 * is restricted to write once in order to prevent manipulation
36 * and afterwards read only.
37 *
38 * @property string                                       $appName
39 * @property int                                          $appId
40 * @property int                                          $unitId
41 * @property \phpOMS\DataStorage\Database\DatabasePool    $dbPool
42 * @property \phpOMS\Localization\L11nManager             $l11nManager
43 * @property \phpOMS\Localization\Localization            $l11nServer
44 * @property \phpOMS\Router\RouterInterface               $router
45 * @property \phpOMS\DataStorage\Session\SessionInterface $sessionManager
46 * @property \phpOMS\DataStorage\Cookie\CookieJar         $cookieJar
47 * @property \phpOMS\Module\ModuleManager                 $moduleManager
48 * @property \phpOMS\Dispatcher\Dispatcher                $dispatcher
49 * @property \phpOMS\DataStorage\Cache\CachePool          $cachePool
50 * @property \phpOMS\Config\SettingsInterface             $appSettings
51 * @property \phpOMS\Event\EventManager                   $eventManager
52 * @property \phpOMS\Account\AccountManager               $accountManager
53 * @property \phpOMS\Log\FileLogger                       $logger
54 *
55 * @package phpOMS\Application
56 * @license OMS License 2.0
57 * @link    https://jingga.app
58 * @since   1.0.0
59 */
60class ApplicationAbstract
61{
62    /**
63     * App name.
64     *
65     * @var string
66     * @since 1.0.0
67     */
68    protected string $appName = '';
69
70    /**
71     * App id.
72     *
73     * @var int
74     * @since 1.0.0
75     */
76    protected int $appId = 0;
77
78    /**
79     * Organization id.
80     *
81     * @var int
82     * @since 1.0.0
83     */
84    protected int $unitId = 0;
85
86    /**
87     * App theme.
88     *
89     * @var string
90     * @since 1.0.0
91     */
92    protected string $theme = '';
93
94    /**
95     * Database object.
96     *
97     * @var DatabasePool
98     * @since 1.0.0
99     */
100    protected DatabasePool $dbPool;
101
102    /**
103     * Application settings object.
104     *
105     * @var SettingsInterface
106     * @since 1.0.0
107     */
108    protected SettingsInterface $appSettings;
109
110    /**
111     * Account manager instance.
112     *
113     * @var AccountManager
114     * @since 1.0.0
115     */
116    protected AccountManager $accountManager;
117
118    /**
119     * Cache instance.
120     *
121     * @var CachePool
122     * @since 1.0.0
123     */
124    protected CachePool $cachePool;
125
126    /**
127     * ModuleManager instance.
128     *
129     * @var ModuleManager
130     * @since 1.0.0
131     */
132    protected ModuleManager $moduleManager;
133
134    /**
135     * Router instance.
136     *
137     * @var RouterInterface
138     * @since 1.0.0
139     */
140    protected RouterInterface $router;
141
142    /**
143     * Dispatcher instance.
144     *
145     * @var Dispatcher
146     * @since 1.0.0
147     */
148    protected Dispatcher $dispatcher;
149
150    /**
151     * Session instance.
152     *
153     * @var SessionInterface
154     * @since 1.0.0
155     */
156    protected SessionInterface $sessionManager;
157
158    /**
159     * Cookie instance.
160     *
161     * @var CookieJar
162     * @since 1.0.0
163     */
164    protected CookieJar $cookieJar;
165
166    /**
167     * Server localization.
168     *
169     * @var Localization
170     * @since 1.0.0
171     */
172    protected Localization $l11nServer;
173
174    /**
175     * Server localization.
176     *
177     * @var FileLogger
178     * @since 1.0.0
179     */
180    protected FileLogger $logger;
181
182    /**
183     * L11n manager.
184     *
185     * @var L11nManager
186     * @since 1.0.0
187     */
188    protected L11nManager $l11nManager;
189
190    /**
191     * Event manager.
192     *
193     * @var EventManager
194     * @since 1.0.0
195     */
196    protected EventManager $eventManager;
197
198    /**
199     * Set values
200     *
201     * @param string $name  Variable name
202     * @param mixed  $value Variable value
203     *
204     * @return void
205     *
206     * @since 1.0.0
207     */
208    public function __set(string $name, mixed $value) : void
209    {
210        if (!empty($this->{$name})) {
211            return;
212        }
213
214        $this->{$name} = $value;
215    }
216
217    /**
218     * Get values
219     *
220     * @param string $name Variable name
221     *
222     * @return mixed Returns the value of the application member
223     *
224     * @since 1.0.0
225     */
226    public function __get(string $name) : mixed
227    {
228        return isset($this->{$name}) ? $this->{$name} : null;
229    }
230}