Completed
Push — master ( 05a043...a79f71 )
by Tim
15:11
created

AutoloaderFileBackend::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace HDNET\Autoloader\Cache;
6
7
use TYPO3\CMS\Core\Core\Environment;
8
use TYPO3\CMS\Core\Utility\GeneralUtility;
9
10
/**
11
 * AutoloaderFileBackend.
12
 *
13
 * Note: This backend is usable without the caching framework
14
 */
15
class AutoloaderFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
21
    {
22
        if (\is_array($data)) {
23
            $cacheFile = $this->getCacheFileName($entryIdentifier);
24
            GeneralUtility::writeFile($cacheFile, '<?php return ' . var_export($data, true) . ';');
25
        }
26
27
        return null;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function get($entryIdentifier)
34
    {
35
        if ($this->has($entryIdentifier)) {
36
            $content = include $this->getCacheFileName($entryIdentifier);
37
38
            return $content;
39
        }
40
41
        return null;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function has($entryIdentifier)
48
    {
49
        return is_file($this->getCacheFileName($entryIdentifier));
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function remove($entryIdentifier)
56
    {
57
        return null;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function flush(): void
64
    {
65
        var_dump(Environment::getVarPath());
0 ignored issues
show
Security Debugging Code introduced by
var_dump(\TYPO3\CMS\Core...ronment::getVarPath()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
66
67
        exit();
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function collectGarbage()
74
    {
75
        // Write by Loader::class
76
        return null;
77
    }
78
79
    protected function getCacheFileName($entryIdentifier): string
80
    {
81
        return Environment::getVarPath() . '/autoloader_' . $entryIdentifier . '.php';
82
    }
83
}
84