Completed
Pull Request — 4.0 (#11)
by David
01:17
created

WebLibrary::getRootUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Mouf\Html\Utils\WebLibraryManager;
3
4
/**
5
 * A WebLibrary represents a set of CSS and JS files that can be integrated into your web application.
6
 *
7
 * @author David Négrier
8
 */
9
class WebLibrary implements WebLibraryInterface
10
{
11
    
12
    
13
    /**
14
     * List of JS files to add in header.
15
     * If you don't specify http:// or https:// and if your URL does not start with /, the file is considered to be relative to ROOT_URL.
16
     *
17
     * @var array<string>
18
     */
19
    private $jsFiles = array();
20
21
    /**
22
     * List of CSS files to add in header.
23
     * If you don't specify http:// or https:// and if your URL does not start with /, the file is considered to be relative to ROOT_URL.
24
     *
25
     * @var array<string>
26
     */
27
    private $cssFiles = array();
28
29
    /**
30
     * List of libraries this library depends on.
31
     *
32
     * @var array<WebLibraryInterface>
33
     */
34
    private $dependencies = array();
35
36
    /**
37
     * Boolean whether the dependencies are called asynchronously
38
     *
39
     * @var bool
40
     */
41
    private $async = false;
42
43
    /**
44
     * Constructor
45
     *
46
     * @param string[] $jsFiles List of JS files to add in header. If you don't specify http:// or https:// and if your URL does not start with /, the file is considered to be relative to ROOT_URL.
47
     * @param string[] $cssFiles List of CSS files to add in header. If you don't specify http:// or https:// and if your URL does not start with /, the file is considered to be relative to ROOT_URL.
48
     */
49
    
50
    public function __construct(array $jsFiles = [], array $cssFiles = [])
51
    {
52
        $this->jsFiles= $jsFiles;
53
        $this->cssFiles = $cssFiles;
54
    }
55
    
56
    /**
57
     * Returns an array of Javascript files to be included for this library.
58
     *
59
     * @return array<string>
60
     */
61
    public function getJsFiles(): array
62
    {
63
        return $this->jsFiles;
64
    }
65
    
66
    /**
67
     * List of JS files to put in the web library.
68
     * <p>If you don't specify http:// or https:// and if the file does not start with /, the file is considered to be relative to ROOT_URL.</p>
69
     * <div class="info">It is a good practice to make sure the file does not start with /, http:// or https:// (unless you are using a CDN).</div>
70
     *
71
     * @param array<string> $jsFiles
72
     */
73
    public function setJsFiles(array $jsFiles): void
74
    {
75
        $this->jsFiles = $jsFiles;
76
    }
77
    
78
    /**
79
     * Adds a JS file to the web library.
80
     * <p>If you don't specify http:// or https:// and if the file does not start with /, the file is considered to be relative to ROOT_URL.</p>
81
     * <div class="info">It is a good practice to make sure the file does not start with /, http:// or https:// (unless you are using a CDN).</div>
82
     *
83
     * @param string $jsFile
84
     */
85
    public function addJsFile(string $jsFile): void
86
    {
87
        $this->jsFiles[] = $jsFile;
88
    }
89
    
90
    /**
91
     * Returns an array of CSS files to be included for this library.
92
     *
93
     * @return array<string>
94
     */
95
    public function getCssFiles(): array
96
    {
97
        return $this->cssFiles;
98
    }
99
    
100
    /**
101
     * List of CSS files to add in web library.
102
     * <p>If you don't specify http:// or https:// and if the file does not start with /, the file is considered to be relative to ROOT_URL.</p>
103
     * <div class="info">It is a good practice to make sure the file does not start with /, http:// or https:// (unless you are using a CDN).</div>
104
     *
105
     * @Property
106
     * @param array<string> $cssFiles
107
     */
108
    public function setCssFiles(array $cssFiles): void
109
    {
110
        $this->cssFiles = $cssFiles;
111
    }
112
    
113
    /**
114
     * Adds a CSS file to the web library.
115
     * <p>If you don't specify http:// or https:// and if the file does not start with /, the file is considered to be relative to ROOT_URL.</p>
116
     * <div class="info">It is a good practice to make sure the file does not start with /, http:// or https:// (unless you are using a CDN).</div>
117
     *
118
     * @param string $cssFile
119
     */
120
    public function addCssFile(string $cssFile): void
121
    {
122
        $this->cssFiles[] = $cssFile;
123
    }
124
    
125
    /**
126
     * Returns a list of libraries that must be included before this library is included.
127
     *
128
     * @return array<WebLibraryInterface>
129
     */
130
    public function getDependencies(): array
131
    {
132
        return $this->dependencies;
133
    }
134
    
135
    /**
136
     * The list of all libraries that are needed for this library
137
     *
138
     * @Property
139
     * @param array<WebLibraryInterface> $libraries
140
     */
141
    public function setDependencies(array $libraries): void
142
    {
143
        $this->dependencies = $libraries;
144
    }
145
146
    /**
147
     * Returns if the dependencies are loaded asynchronously
148
     *
149
     * @return bool
150
     */
151
    public function isAsync(): bool
152
    {
153
        return $this->async;
154
    }
155
156
    /**
157
     * Set if the dependencies are loaded asynchronously
158
     *
159
     * @Property
160
     * @param bool $async
161
     */
162
    public function setIsAsync(bool $async): void
163
    {
164
        $this->async = $async;
165
    }
166
}
167