ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
SimpleExcel\Parser\JSONParser Class Reference
+ Inheritance diagram for SimpleExcel\Parser\JSONParser:
+ Collaboration diagram for SimpleExcel\Parser\JSONParser:

Public Member Functions

 loadFile ($file_path)
 Load the JSON file to be parsed. More...
 
 loadString ($str)
 Load the string to be parsed. More...
 
- Public Member Functions inherited from SimpleExcel\Parser\BaseParser
 __construct ($file_url=NULL)
 
 getCell ($row_num, $col_num, $val_only=true)
 Get value of the specified cell. More...
 
 getColumn ($col_num, $val_only=TRUE)
 Get data of the specified column as an array. More...
 
 getField ($val_only=TRUE)
 Get data of all cells as an array. More...
 
 getRow ($row_num, $val_only=TRUE)
 Get data of the specified row as an array. More...
 
 isCellExists ($row_num, $col_num)
 Check whether cell with specified row & column exists. More...
 
 isColumnExists ($col_num)
 Check whether a specified column exists. More...
 
 isRowExists ($row_num)
 Check whether a specified row exists. More...
 
 isFieldExists ()
 Check whether table exists. More...
 
 isFileReady ($file_path)
 Check whether file exists, valid, and readable. More...
 

Protected Attributes

 $file_extension = 'json'
 
- Protected Attributes inherited from SimpleExcel\Parser\BaseParser
 $table_arr
 
 $file_extension = ''
 

Detailed Description

Definition at line 13 of file JSONParser.php.

Member Function Documentation

◆ loadFile()

SimpleExcel\Parser\JSONParser::loadFile (   $file_path)

Load the JSON file to be parsed.

Parameters
string$file_pathPath to JSON file

Implements SimpleExcel\Parser\IParser.

Definition at line 28 of file JSONParser.php.

References SimpleExcel\Parser\BaseParser\isFileReady(), and SimpleExcel\Parser\JSONParser\loadString().

28  {
29 
30  if (!$this->isFileReady($file_path)) {
31  return;
32  }
33 
34  $handle = fopen($file_path, 'r');
35  $this->loadString($handle);
36  fclose($handle);
37  }
isFileReady($file_path)
Check whether file exists, valid, and readable.
Definition: BaseParser.php:169
loadString($str)
Load the string to be parsed.
Definition: JSONParser.php:45
+ Here is the call graph for this function:

◆ loadString()

SimpleExcel\Parser\JSONParser::loadString (   $str)

Load the string to be parsed.

Parameters
string$strString with JSON format
Exceptions
ExceptionIf JSON format is invalid (or too deep)

Implements SimpleExcel\Parser\IParser.

Definition at line 45 of file JSONParser.php.

References $row, and SimpleExcel\Exception\SimpleExcelException\MALFORMED_JSON.

Referenced by SimpleExcel\Parser\JSONParser\loadFile().

45  {
46  $field = array();
47  if (($table = json_decode(utf8_encode($str), false, 4)) === NULL) {
48  throw new \Exception('Invalid JSON format: '.$str, SimpleExcelException::MALFORMED_JSON);
49  } else {
50  foreach ($table as $rows) {
51  $row = array();
52  foreach ($rows as $cell) {
53  array_push($row, $cell);
54  }
55  array_push($field, $row);
56  }
57  }
58  $this->table_arr = $field;
59  }
+ Here is the caller graph for this function:

Field Documentation

◆ $file_extension

SimpleExcel\Parser\JSONParser::$file_extension = 'json'
protected

Definition at line 21 of file JSONParser.php.


The documentation for this class was generated from the following file: