4
4
5
5
use Helldar \PrettyArray \Exceptions \FileDoesntExistsException ;
6
6
use Helldar \Support \Facades \File as FileSupport ;
7
+ use Helldar \Support \Facades \Str ;
7
8
use Helldar \Support \Tools \Stub ;
8
9
9
10
class File
@@ -21,19 +22,26 @@ public static function make(string $content = null)
21
22
}
22
23
23
24
/**
24
- * @param string $filename
25
+ * @param string $filename
25
26
*
26
27
* @throws \Helldar\PrettyArray\Exceptions\FileDoesntExistsException
27
28
*
28
- * @return array
29
+ * @return mixed
29
30
*/
30
- public function load (string $ filename ): array
31
+ public function load (string $ filename )
31
32
{
32
33
if (! file_exists ($ filename )) {
33
34
throw new FileDoesntExistsException ($ filename );
34
35
}
35
36
36
- return require $ filename ;
37
+ return $ this ->isJson ($ filename )
38
+ ? $ this ->loadJson ($ filename )
39
+ : require $ filename ;
40
+ }
41
+
42
+ public function loadJson (string $ filename )
43
+ {
44
+ return json_decode (file_get_contents ($ filename ), true );
37
45
}
38
46
39
47
public function store (string $ path )
@@ -44,4 +52,11 @@ public function store(string $path)
44
52
45
53
FileSupport::store ($ path , $ content );
46
54
}
55
+
56
+ public function isJson (string $ filename ): bool
57
+ {
58
+ $ extension = pathinfo ($ filename , PATHINFO_EXTENSION );
59
+
60
+ return Str::lower ($ extension ) === 'json ' ;
61
+ }
47
62
}
0 commit comments