| 1 |
<?php |
| 2 |
/** |
| 3 |
* Read CSV file |
| 4 |
* |
| 5 |
* @package Timetics |
| 6 |
*/ |
| 7 |
namespace Timetics\Base; |
| 8 |
|
| 9 |
defined( 'ABSPATH' ) || exit; |
| 10 |
|
| 11 |
/** |
| 12 |
* JSON Reader Class |
| 13 |
*/ |
| 14 |
class JsonReader implements FileReaderInterface { |
| 15 |
/** |
| 16 |
* Store file |
| 17 |
* |
| 18 |
* @var string |
| 19 |
*/ |
| 20 |
private static $file; |
| 21 |
|
| 22 |
/** |
| 23 |
* Get data that will be read from json file |
| 24 |
* |
| 25 |
* @param file $file |
| 26 |
* |
| 27 |
* @return array |
| 28 |
*/ |
| 29 |
public static function get_data( $file ) { |
| 30 |
self::$file = $file; |
| 31 |
|
| 32 |
return self::read_file(); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Get from file |
| 37 |
* |
| 38 |
* @return array |
| 39 |
*/ |
| 40 |
private static function read_file() { |
| 41 |
$file = self::$file; |
| 42 |
$data = []; |
| 43 |
$content = file_get_contents( $file ); |
| 44 |
|
| 45 |
if ( $content ) { |
| 46 |
$data = json_decode( $content, true ); |
| 47 |
} |
| 48 |
|
| 49 |
return $data; |
| 50 |
} |
| 51 |
} |
| 52 |
|