44
55use Helldar \PrettyArray \Exceptions \FileDoesntExistsException ;
66use Helldar \Support \Facades \File as FileSupport ;
7+ use Helldar \Support \Facades \Str ;
78use Helldar \Support \Tools \Stub ;
89
910class File
@@ -21,19 +22,26 @@ public static function make(string $content = null)
2122 }
2223
2324 /**
24- * @param string $filename
25+ * @param string $filename
2526 *
2627 * @throws \Helldar\PrettyArray\Exceptions\FileDoesntExistsException
2728 *
28- * @return array
29+ * @return mixed
2930 */
30- public function load (string $ filename ): array
31+ public function load (string $ filename )
3132 {
3233 if (! file_exists ($ filename )) {
3334 throw new FileDoesntExistsException ($ filename );
3435 }
3536
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 );
3745 }
3846
3947 public function store (string $ path )
@@ -44,4 +52,11 @@ public function store(string $path)
4452
4553 FileSupport::store ($ path , $ content );
4654 }
55+
56+ public function isJson (string $ filename ): bool
57+ {
58+ $ extension = pathinfo ($ filename , PATHINFO_EXTENSION );
59+
60+ return Str::lower ($ extension ) === 'json ' ;
61+ }
4762}
0 commit comments