MetadataBaseProvider::getIsCaching()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlgoWeb\PODataLaravel\Providers;
6
7
use AlgoWeb\PODataLaravel\Controllers\MetadataControllerContainer;
8
use AlgoWeb\PODataLaravel\Models\ClassReflectionHelper;
9
use AlgoWeb\PODataLaravel\Models\IMetadataRelationshipContainer;
10
use AlgoWeb\PODataLaravel\Models\ObjectMap\Map;
11
use Illuminate\Contracts\Foundation\Application;
12
use Illuminate\Support\Facades\App;
13
use Illuminate\Support\Facades\Cache;
14
use Illuminate\Support\ServiceProvider;
15
16
abstract class MetadataBaseProvider extends ServiceProvider
17
{
18
    /** @var Application */
19
    protected $app;
20
21
    /**
22
     * @return bool
23
     */
24
    protected function getIsCaching()
25
    {
26
        return true === env('APP_METADATA_CACHING', false);
27
    }
28
29
    /**
30
     * @param bool          $isCaching
31
     * @param bool|null     $hasCache
32
     * @param string        $key
33
     * @param mixed         $meta
34
     */
35
    protected function handlePostBoot(bool $isCaching, ?bool $hasCache, string $key, $meta): void
36
    {
37
        if (!$isCaching) {
38
            Cache::forget($key);
39
            return;
40
        }
41
        $hasCache = isset($hasCache) ? boolval($hasCache) : false;
42
        if (!$hasCache) {
43
            $cacheTime = abs(intval(env('APP_METADATA_CACHE_DURATION', 10)));
44
            $cacheTime = max($cacheTime, 1);
45
            Cache::put($key, $meta, $cacheTime);
46
        }
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    protected function getAppNamespace(): string
53
    {
54
        return ClassReflectionHelper::getAppNamespace();
55
    }
56
}
57