6
6
namespace Magento \Deploy \Service ;
7
7
8
8
use Magento \Framework \App \Filesystem \DirectoryList ;
9
+ use Magento \Framework \Exception \FileSystemException ;
10
+ use Magento \Framework \Exception \LocalizedException ;
9
11
use Magento \Framework \Filesystem ;
10
12
use Magento \Framework \Filesystem \File \WriteInterface ;
11
13
use Magento \Framework \View \Asset \Minification ;
@@ -83,8 +85,9 @@ public function __construct(
83
85
* @param string $fileName
84
86
* @param array $params ['area' =>, 'theme' =>, 'locale' =>, 'module' =>]
85
87
* @return string
88
+ * @throws LocalizedException
86
89
*/
87
- public function deployFile ($ fileName , array $ params = [])
90
+ public function deployFile (string $ fileName , array $ params = []): string
88
91
{
89
92
$ params ['publish ' ] = true ;
90
93
$ asset = $ this ->assetRepo ->createAsset ($ this ->resolveFile ($ fileName ), $ params );
@@ -97,8 +100,9 @@ public function deployFile($fileName, array $params = [])
97
100
/**
98
101
* @param string $path
99
102
* @return void
103
+ * @throws FileSystemException
100
104
*/
101
- public function deleteFile ($ path )
105
+ public function deleteFile (string $ path )
102
106
{
103
107
if ($ this ->pubStaticDir ->isExist ($ path )) {
104
108
$ absolutePath = $ this ->pubStaticDir ->getAbsolutePath ($ path );
@@ -120,8 +124,9 @@ public function deleteFile($path)
120
124
* @param string $fileName
121
125
* @param string $filePath
122
126
* @return string|false
127
+ * @throws FileSystemException
123
128
*/
124
- public function readFile ($ fileName , $ filePath )
129
+ public function readFile (string $ fileName , string $ filePath ): bool | string
125
130
{
126
131
$ fileName = $ this ->minification ->addMinifiedSign ($ fileName );
127
132
$ relativePath = $ filePath . DIRECTORY_SEPARATOR . $ this ->resolveFile ($ fileName );
@@ -137,7 +142,7 @@ public function readFile($fileName, $filePath)
137
142
* @param string $filePath
138
143
* @return WriteInterface
139
144
*/
140
- public function openFile ($ fileName , $ filePath )
145
+ public function openFile (string $ fileName , string $ filePath ): WriteInterface
141
146
{
142
147
$ relativePath = $ filePath . DIRECTORY_SEPARATOR . $ this ->resolveFile ($ fileName );
143
148
return $ this ->pubStaticDir ->openFile ($ relativePath , 'w+ ' );
@@ -150,8 +155,9 @@ public function openFile($fileName, $filePath)
150
155
* @param string $filePath
151
156
* @param string $content
152
157
* @return int The number of bytes that were written.
158
+ * @throws FileSystemException
153
159
*/
154
- public function writeFile ($ fileName , $ filePath , $ content )
160
+ public function writeFile (string $ fileName , string $ filePath , string $ content ): int
155
161
{
156
162
$ relativePath = $ filePath . DIRECTORY_SEPARATOR . $ this ->resolveFile ($ fileName );
157
163
return $ this ->pubStaticDir ->writeFile ($ relativePath , $ content );
@@ -164,8 +170,9 @@ public function writeFile($fileName, $filePath, $content)
164
170
* @param string $sourcePath
165
171
* @param string $targetPath
166
172
* @return bool
173
+ * @throws FileSystemException
167
174
*/
168
- public function copyFile ($ fileName , $ sourcePath , $ targetPath )
175
+ public function copyFile (string $ fileName , string $ sourcePath , string $ targetPath ): bool
169
176
{
170
177
$ fileName = $ this ->minification ->addMinifiedSign ($ fileName );
171
178
return $ this ->pubStaticDir ->copyFile (
@@ -179,9 +186,10 @@ public function copyFile($fileName, $sourcePath, $targetPath)
179
186
*
180
187
* @param string $fileName
181
188
* @param string $filePath
182
- * @return string
189
+ * @return bool|string
190
+ * @throws FileSystemException
183
191
*/
184
- public function readTmpFile ($ fileName , $ filePath )
192
+ public function readTmpFile (string $ fileName , string $ filePath ): bool | string
185
193
{
186
194
$ relativePath = $ filePath . DIRECTORY_SEPARATOR . $ fileName ;
187
195
return $ this ->tmpDir ->isFile ($ relativePath ) ? $ this ->tmpDir ->readFile ($ relativePath ) : false ;
@@ -194,10 +202,12 @@ public function readTmpFile($fileName, $filePath)
194
202
* @param string $filePath
195
203
* @param string $content
196
204
* @return int The number of bytes that were written.
205
+ * @throws FileSystemException
197
206
*/
198
- public function writeTmpFile ($ fileName , $ filePath , $ content )
207
+ public function writeTmpFile (string $ fileName , string $ filePath , string $ content ): int
199
208
{
200
209
$ relativePath = $ filePath . DIRECTORY_SEPARATOR . $ this ->resolveFile ($ fileName );
210
+
201
211
return $ this ->tmpDir ->writeFile ($ relativePath , $ content );
202
212
}
203
213
@@ -207,14 +217,12 @@ public function writeTmpFile($fileName, $filePath, $content)
207
217
* @param string $fileName
208
218
* @return string
209
219
*/
210
- private function resolveFile ($ fileName )
220
+ private function resolveFile (string $ fileName ): string
211
221
{
212
- $ compiledFile = str_replace (
222
+ return str_replace (
213
223
Repository::FILE_ID_SEPARATOR ,
214
224
'/ ' ,
215
225
$ this ->fileNameResolver ->resolve ($ fileName )
216
226
);
217
-
218
- return $ compiledFile ;
219
227
}
220
228
}
0 commit comments