Completed
Push — master ( 07703f...53d2c5 )
by Stefano
16s queued 14s
created

RevManifestStrategy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 11 3
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 $_defaultConfig = [
36
        'manifestPath' => WWW_ROOT . 'rev-manifest.json',
37
    ];
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function get(string $name, ?string $extension = null)
43
    {
44
        if (!empty($extension)) {
45
            $name .= sprintf('.%s', $extension);
46
        }
47
48
        if (empty($this->assets[$name])) {
49
            return null;
50
        }
51
52
        return $this->assets[$name];
53
    }
54
}
55