Passed
Push — develop ( 6f08cb...267f63 )
by Andrew
03:33
created

Manifest::getCssRelPreloadPolyfill()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Twigpack plugin for Craft CMS 3.x
4
 *
5
 * Twigpack is the conduit between Twig and webpack, with manifest.json &
6
 * webpack-dev-server HMR support
7
 *
8
 * @link      https://nystudio107.com/
9
 * @copyright Copyright (c) 2018 nystudio107
10
 */
11
12
namespace nystudio107\twigpack\services;
13
14
use nystudio107\twigpack\Twigpack;
15
use nystudio107\twigpack\helpers\Manifest as ManifestHelper;
16
17
use craft\base\Component;
18
19
/** @noinspection MissingPropertyAnnotationsInspection */
20
21
/**
22
 * @author    nystudio107
23
 * @package   Twigpack
24
 * @since     1.0.0
25
 */
26
class Manifest extends Component
27
{
28
    // Public Methods
29
    // =========================================================================
30
31
    /**
32
     * Return the HTML tags to include the CSS
33
     *
34
     * @param string     $moduleName
35
     * @param bool       $async
36
     * @param null|array $config
37
     *
38
     * @return null|string
39
     * @throws \yii\web\NotFoundHttpException
40
     */
41
    public function getCssModuleTags(string $moduleName, bool $async = false, $config = null)
42
    {
43
        $settings = Twigpack::$plugin->getSettings();
44
        $config = $config ?? $settings->getAttributes();
45
46
        return ManifestHelper::getCssModuleTags($config, $moduleName, $async);
47
    }
48
49
    /**
50
     * Returns the uglified loadCSS rel=preload Polyfill as per:
51
     * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
52
     *
53
     * @return string
54
     */
55
    public function getCssRelPreloadPolyfill(): string
56
    {
57
        return ManifestHelper::getCssRelPreloadPolyfill();
58
    }
59
60
    /**
61
     * Return the HTML tags to include the JavaScript module
62
     *
63
     * @param string     $moduleName
64
     * @param bool       $async
65
     * @param null|array $config
66
     *
67
     * @return null|string
68
     * @throws \yii\web\NotFoundHttpException
69
     */
70
    public function getJsModuleTags(string $moduleName, bool $async = false, $config = null)
71
    {
72
        $settings = Twigpack::$plugin->getSettings();
73
        $config = $config ?? $settings->getAttributes();
74
75
        return ManifestHelper::getJsModuleTags($config, $moduleName, $async);
76
    }
77
78
    /**
79
     * Return the Safari 10.1 nomodule JavaScript fix
80
     *
81
     * @return string
82
     */
83
    public function getSafariNomoduleFix(): string
84
    {
85
        return ManifestHelper::getSafariNomoduleFix();
86
    }
87
88
    /**
89
     * Return the URI to a module
90
     *
91
     * @param string $moduleName
92
     * @param string $type
93
     * @param null   $config
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $config is correct as it would always require null to be passed?
Loading history...
94
     *
95
     * @return null|string
96
     * @throws \yii\web\NotFoundHttpException
97
     */
98
    public function getModule(string $moduleName, string $type = 'modern', $config = null)
99
    {
100
        return ManifestHelper::getModule($config, $moduleName, $type);
101
    }
102
103
    /**
104
     * Invalidate the manifest cache
105
     */
106
    public function invalidateCaches()
107
    {
108
        ManifestHelper::invalidateCaches();
109
    }
110
}
111