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

EntrypointsStrategy::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 8
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
use Cake\Utility\Hash;
19
20
/**
21
 * Entrypoints asset strategy.
22
 * This strategy is based on map produced by Webpack Encore and expects a JSON assets map like
23
 *
24
 * ```
25
 * {
26
 *     "entrypoints": {
27
 *         "app": {
28
 *             "js": [
29
 *                 "/build/runtime.f011bcb1.js",
30
 *                 "/build/0.54651780.js",
31
 *                 "/build/app.82269f26.js"
32
 *             ]
33
 *         },
34
 *         "style": {
35
 *             "js": [
36
 *                 "/build/runtime.f011bcb1.js"
37
 *             ],
38
 *             "css": [
39
 *                 "/build/style.12c5249c.css"
40
 *             ]
41
 *         }
42
 *     }
43
 * }
44
 * ```
45
 *
46
 * @see https://symfony.com/doc/current/frontend.html
47
 */
48
class EntrypointsStrategy extends AssetStrategy
49
{
50
    /**
51
     * {@inheritDoc}
52
     */
53
    protected $_defaultConfig = [
54
        'manifestPath' => WWW_ROOT . 'build' . DS . 'entrypoints.json',
55
    ];
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function get(string $name, ?string $extension = null)
61
    {
62
        $path = sprintf('entrypoints.%s', $name);
63
        if (!empty($extension)) {
64
            $path .= sprintf('.%s', $extension);
65
        }
66
67
        return Hash::get($this->assets, $path);
68
    }
69
}
70