RevManifestStrategy::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * BEdita, API-first content management framework
6
 * Copyright 2020 ChannelWeb Srl, Chialab Srl
7
 *
8
 * This file is part of BEdita: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published
10
 * by the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
14
 */
15
namespace BEdita\WebTools\Utility\Asset\Strategy;
16
17
use BEdita\WebTools\Utility\Asset\AssetStrategy;
18
19
/**
20
 * RevManifest asset strategy.
21
 * This strategy expects a JSON assets map like
22
 *
23
 * ```
24
 * {
25
 *     "app.js": "app.13gdr5.js",
26
 *     "style.css: "style.lgcf6a.js"
27
 * }
28
 * ```
29
 */
30
class RevManifestStrategy extends AssetStrategy
31
{
32
    /**
33
     * @inheritDoc
34
     */
35
    protected array $_defaultConfig = [
36
        'manifestPath' => WWW_ROOT . 'rev-manifest.json',
37
    ];
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public function get(string $name, ?string $extension = null): array|string|null
43
    {
44
        if (!empty($extension)) {
45
            return $this->assets[sprintf('%s.%s', $name, $extension)] ?? null;
46
        }
47
48
        return $this->assets[$name] ?? null;
49
    }
50
}
51