Completed
Push — master ( 3c1969...5b5792 )
by Schlaefer
03:16 queued 10s
created

Plugin::bootstrap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace ImageUploader;
14
15
use Cake\Cache\Cache;
16
use Cake\Core\BasePlugin;
17
use Cake\Core\PluginApplicationInterface;
18
19
class Plugin extends BasePlugin
20
{
21
    /**
22
     * Cache key for image thumbnails
23
     */
24
    public const CACHE_KEY = 'uploadsThumbnails';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function bootstrap(PluginApplicationInterface $app)
30
    {
31
        // Add constants, load configuration defaults.
32
        // By default will load `config/bootstrap.php` in the plugin.
33
        parent::bootstrap($app);
34
35
        self::configureCache();
36
    }
37
38
    /**
39
     * Configures the thumbnail cache
40
     *
41
     * @return void
42
     */
43
    public static function configureCache(): void
44
    {
45
        if (Cache::getConfig(self::CACHE_KEY) !== null) {
46
            return;
47
        }
48
49
        Cache::setConfig(
50
            self::CACHE_KEY,
51
            [
52
                'className' => 'File',
53
                'prefix' => 'saito_thumbnails-',
54
                'path' => CACHE,
55
                'groups' => ['uploads'],
56
                'duration' => '+1 year'
57
            ]
58
        );
59
    }
60
}
61