Completed
Push — 4.0 ( 6f2c9f...73108a )
by David
17s queued 11s
created

WebLibrary::setIsAsync()   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 1
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
     * @var string
45
     */
46
    private $rootUrl;
47
48
49
    /**
50
     * Constructor
51
     *
52
     * @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.
53
     * @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.
54
     * @param string $rootUrl The ROOT url of your application. It should not contain the complete domain name, only the path, starting and ending with a /. For instance: '/foo/bar/' or '/'
55
     */
56
    
57
    public function __construct(array $jsFiles = [], array $cssFiles = [], string $rootUrl = '/')
58
    {
59
        $this->jsFiles= $jsFiles;
60
        $this->cssFiles = $cssFiles;
61
        $this->rootUrl = $rootUrl;
62
    }
63
    
64
    /**
65
     * Returns an array of Javascript files to be included for this library.
66
     *
67
     * @return array<string>
68
     */
69
    public function getJsFiles(): array
70
    {
71
        return $this->jsFiles;
72
    }
73
    
74
    /**
75
     * List of JS files to put in the web library.
76
     * <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>
77
     * <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>
78
     *
79
     * @param array<string> $jsFiles
80
     */
81
    public function setJsFiles(array $jsFiles): void
82
    {
83
        $this->jsFiles = $jsFiles;
84
    }
85
    
86
    /**
87
     * Adds a JS file to the web library.
88
     * <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>
89
     * <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>
90
     *
91
     * @param string $jsFile
92
     */
93
    public function addJsFile(string $jsFile): void
94
    {
95
        $this->jsFiles[] = $jsFile;
96
    }
97
    
98
    /**
99
     * Returns an array of CSS files to be included for this library.
100
     *
101
     * @return array<string>
102
     */
103
    public function getCssFiles(): array
104
    {
105
        return $this->cssFiles;
106
    }
107
    
108
    /**
109
     * List of CSS files to add in web library.
110
     * <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>
111
     * <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>
112
     *
113
     * @Property
114
     * @param array<string> $cssFiles
115
     */
116
    public function setCssFiles(array $cssFiles): void
117
    {
118
        $this->cssFiles = $cssFiles;
119
    }
120
    
121
    /**
122
     * Adds a CSS file to the web library.
123
     * <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>
124
     * <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>
125
     *
126
     * @param string $cssFile
127
     */
128
    public function addCssFile(string $cssFile): void
129
    {
130
        $this->cssFiles[] = $cssFile;
131
    }
132
    
133
    /**
134
     * Returns a list of libraries that must be included before this library is included.
135
     *
136
     * @return array<WebLibraryInterface>
137
     */
138
    public function getDependencies(): array
139
    {
140
        return $this->dependencies;
141
    }
142
    
143
    /**
144
     * The list of all libraries that are needed for this library
145
     *
146
     * @Property
147
     * @param array<WebLibraryInterface> $libraries
148
     */
149
    public function setDependencies(array $libraries): void
150
    {
151
        $this->dependencies = $libraries;
152
    }
153
154
    /**
155
     * Returns if the dependencies are loaded asynchronously
156
     *
157
     * @return bool
158
     */
159
    public function isAsync(): bool
160
    {
161
        return $this->async;
162
    }
163
164
    /**
165
     * Set if the dependencies are loaded asynchronously
166
     *
167
     * @Property
168
     * @param bool $async
169
     */
170
    public function setIsAsync(bool $async): void
171
    {
172
        $this->async = $async;
173
    }
174
175
    /**
176
     * @return string
177
     */
178
    public function getRootUrl(): string
179
    {
180
        return $this->rootUrl;
181
    }
182
}
183