@@ -16,138 +16,138 @@ |
||
16 | 16 | abstract class BrowserAsset extends Asset |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var string $source |
|
21 | - */ |
|
22 | - private $source; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var array $dependencies |
|
26 | - */ |
|
27 | - private $dependencies; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string $version |
|
31 | - */ |
|
32 | - private $version; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Asset constructor. |
|
37 | - * |
|
38 | - * @param string $type |
|
39 | - * @param string $handle |
|
40 | - * @param string $source |
|
41 | - * @param array $dependencies |
|
42 | - * @param DomainInterface $domain |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain) |
|
46 | - { |
|
47 | - parent::__construct($type, $handle, $domain); |
|
48 | - $this->setSource($source); |
|
49 | - $this->setDependencies($dependencies); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @since 4.9.62.p |
|
55 | - */ |
|
56 | - abstract public function enqueueAsset(); |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function dependencies() |
|
63 | - { |
|
64 | - return $this->dependencies; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @param array $dependencies |
|
70 | - */ |
|
71 | - private function setDependencies(array $dependencies) |
|
72 | - { |
|
73 | - $this->dependencies = $dependencies; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @since 4.9.62.p |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - public function hasDependencies() |
|
82 | - { |
|
83 | - return count($this->dependencies) > 0; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function source() |
|
91 | - { |
|
92 | - return $this->source; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @param string $source |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - */ |
|
100 | - private function setSource($source) |
|
101 | - { |
|
102 | - if (! is_string($source)) { |
|
103 | - throw new InvalidDataTypeException( |
|
104 | - '$source', |
|
105 | - $source, |
|
106 | - 'string' |
|
107 | - ); |
|
108 | - } |
|
109 | - $this->source = $source; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @todo investigate why this isn't working as expected. We're seeing `?ver=` strings output for the url path with |
|
115 | - * core version even though for built hash assets this should not be the case. |
|
116 | - * @return string |
|
117 | - * @throws InvalidDataTypeException |
|
118 | - */ |
|
119 | - public function version() |
|
120 | - { |
|
121 | - // if version is NOT set and this asset was NOT built for distribution, |
|
122 | - // then set the version equal to the EE core plugin version |
|
123 | - if ( |
|
124 | - $this->version === null |
|
125 | - && ( |
|
126 | - substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
127 | - || substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS |
|
128 | - ) |
|
129 | - ) { |
|
130 | - $this->setVersion(); |
|
131 | - } |
|
132 | - return $this->version; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $version |
|
138 | - * @return BrowserAsset |
|
139 | - * @throws InvalidDataTypeException |
|
140 | - */ |
|
141 | - public function setVersion($version = EVENT_ESPRESSO_VERSION) |
|
142 | - { |
|
143 | - if (! is_string($version)) { |
|
144 | - throw new InvalidDataTypeException( |
|
145 | - '$version', |
|
146 | - $version, |
|
147 | - 'string' |
|
148 | - ); |
|
149 | - } |
|
150 | - $this->version = $version; |
|
151 | - return $this; |
|
152 | - } |
|
19 | + /** |
|
20 | + * @var string $source |
|
21 | + */ |
|
22 | + private $source; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var array $dependencies |
|
26 | + */ |
|
27 | + private $dependencies; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string $version |
|
31 | + */ |
|
32 | + private $version; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Asset constructor. |
|
37 | + * |
|
38 | + * @param string $type |
|
39 | + * @param string $handle |
|
40 | + * @param string $source |
|
41 | + * @param array $dependencies |
|
42 | + * @param DomainInterface $domain |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain) |
|
46 | + { |
|
47 | + parent::__construct($type, $handle, $domain); |
|
48 | + $this->setSource($source); |
|
49 | + $this->setDependencies($dependencies); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @since 4.9.62.p |
|
55 | + */ |
|
56 | + abstract public function enqueueAsset(); |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function dependencies() |
|
63 | + { |
|
64 | + return $this->dependencies; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @param array $dependencies |
|
70 | + */ |
|
71 | + private function setDependencies(array $dependencies) |
|
72 | + { |
|
73 | + $this->dependencies = $dependencies; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @since 4.9.62.p |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + public function hasDependencies() |
|
82 | + { |
|
83 | + return count($this->dependencies) > 0; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function source() |
|
91 | + { |
|
92 | + return $this->source; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @param string $source |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + */ |
|
100 | + private function setSource($source) |
|
101 | + { |
|
102 | + if (! is_string($source)) { |
|
103 | + throw new InvalidDataTypeException( |
|
104 | + '$source', |
|
105 | + $source, |
|
106 | + 'string' |
|
107 | + ); |
|
108 | + } |
|
109 | + $this->source = $source; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @todo investigate why this isn't working as expected. We're seeing `?ver=` strings output for the url path with |
|
115 | + * core version even though for built hash assets this should not be the case. |
|
116 | + * @return string |
|
117 | + * @throws InvalidDataTypeException |
|
118 | + */ |
|
119 | + public function version() |
|
120 | + { |
|
121 | + // if version is NOT set and this asset was NOT built for distribution, |
|
122 | + // then set the version equal to the EE core plugin version |
|
123 | + if ( |
|
124 | + $this->version === null |
|
125 | + && ( |
|
126 | + substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
127 | + || substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS |
|
128 | + ) |
|
129 | + ) { |
|
130 | + $this->setVersion(); |
|
131 | + } |
|
132 | + return $this->version; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $version |
|
138 | + * @return BrowserAsset |
|
139 | + * @throws InvalidDataTypeException |
|
140 | + */ |
|
141 | + public function setVersion($version = EVENT_ESPRESSO_VERSION) |
|
142 | + { |
|
143 | + if (! is_string($version)) { |
|
144 | + throw new InvalidDataTypeException( |
|
145 | + '$version', |
|
146 | + $version, |
|
147 | + 'string' |
|
148 | + ); |
|
149 | + } |
|
150 | + $this->version = $version; |
|
151 | + return $this; |
|
152 | + } |
|
153 | 153 | } |