Passed
Push — main ( 8fe145...85e465 )
by Thierry
13:46
created

storage()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Jaxon\Storage;
4
5
use Jaxon\Config\Config;
6
use Jaxon\Config\ConfigSetter;
7
use Jaxon\Utils\Translation\Translator;
8
use Lagdo\Facades\ContainerWrapper;
9
10
use function function_exists;
11
use function php_sapi_name;
12
13
/**
14
 * Register the values into the Jaxon container
15
 *
16
 * @return void
17
 */
18
function _register(): void
19
{
20
    $di = jaxon()->di();
21
22
    // Setup the logger facade.
23
    ContainerWrapper::setContainer($di);
24
25
    // File storage
26
    if(!$di->h(StorageManager::class))
27
    {
28
        $di->set(StorageManager::class, function() use($di): StorageManager {
29
            $xConfigGetter = function() use($di): Config {
30
                $aConfigOptions = $di->config()->getAppOption('storage', []);
31
                return (new ConfigSetter())->newConfig($aConfigOptions);
32
            };
33
34
            return new StorageManager($xConfigGetter, $di->g(Translator::class));
35
        });
36
    }
37
}
38
39
function register()
40
{
41
    // Do nothing if running in cli.
42
    if(php_sapi_name() !== 'cli' && function_exists('jaxon'))
43
    {
44
        _register();
45
    };
46
}
47
48
/**
49
 * Get the storage manager
50
 *
51
 * @return StorageManager
52
 */
53
function storage(): StorageManager
54
{
55
    if(function_exists('jaxon'))
56
    {
57
        return jaxon()->di()->g(StorageManager::class);
58
    }
59
60
    static $xStorageManager = null;
61
    return $xStorageManager ?: new StorageManager();
62
}
63
64
register();
65