anonymous()
last analyzed

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 21
c 0
b 0
f 0
nc 3
nop 0
1
<?php
2
/**
3
 * Configuration file for DI container.
4
 */
5
return [
6
7
    // Services to add to the container.
8
    "services" => [
9
        "cache" => [
10
            "shared" => true,
11
            "callback" => function () {
12
                $cache = new \Anax\Cache\FileCache();
13
14
                // Load the configuration files
15
                $cfg = $this->get("configuration");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
16
                $config = $cfg->load("cache.php");
17
                $file = $config["file"] ?? null;
18
                $config = $config["config"] ?? null;
19
20
                $path = $config["basePath"] ?? null;
21
                if (!$path || !is_dir($path) || !is_writable($path)) {
22
                    throw new Exception("Configuration file '$file': Cachedir '$path' is not a writable directory.");
23
                }
24
                $cache->setPath($path);
25
26
                $timeToLive = $config["timeToLive"] ?? null;
27
                if ($timeToLive) {
28
                    $cache->setTimeToLive($timeToLive);
29
                }
30
31
                return $cache;
32
            }
33
        ],
34
    ],
35
];
36