ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
ILIAS\UI\Implementation\Crawler\EntriesYamlParser Class Reference
+ Inheritance diagram for ILIAS\UI\Implementation\Crawler\EntriesYamlParser:
+ Collaboration diagram for ILIAS\UI\Implementation\Crawler\EntriesYamlParser:

Public Member Functions

 __construct ()
 FactoryCrawler constructor. More...
 
 parseYamlStringArrayFromFile ($filePath)
 
 parseArrayFromFile ($filePath)
 
 parseEntriesFromFile ($filePath)
 
 parseYamlStringArrayFromString ($content)
 
 parseArrayFromString ($content)
 
 parseEntriesFromString ($content)
 

Static Public Member Functions

static toUpperCamelCase ($string, $seperator)
 
static toLowerCamelCase ($string, $seperator)
 
static fromCamelCaseToWords ($camelCaseString)
 

Data Fields

const PARSER_STATE_OUTSIDE = 1
 
const PARSER_STATE_ENTRY = 2
 
const PARSER_STATE_SEEKING_RETURN = 3
 
const PARSER_STATE_SEEKING_FUNCTION_NAME = 4
 

Protected Member Functions

 getFileContentAsString ($filePath)
 
 getYamlEntriesFromString ($content)
 
 purifyYamlLine ($line)
 
 getPHPArrayFromYamlArray ($yaml_entries)
 
 getEntriesFromArray (array $entries_array)
 
 getEntryFromData (array $entry_data)
 

Protected Attributes

 $items = array()
 
 $ef = null
 
 $file_path = "none"
 

Detailed Description

Definition at line 12 of file EntriesYamlParser.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::__construct ( )

FactoryCrawler constructor.

Definition at line 39 of file EntriesYamlParser.php.

39  {
40  $this->ef = new Exception\Factory();
41  }

Member Function Documentation

◆ fromCamelCaseToWords()

static ILIAS\UI\Implementation\Crawler\EntriesYamlParser::fromCamelCaseToWords (   $camelCaseString)
static
Parameters
$camelCaseString
Returns
string

Definition at line 303 of file EntriesYamlParser.php.

303  {
304  return join(preg_split('/(?<=[a-z])(?=[A-Z])/x', ucwords($camelCaseString)), " " );
305  }

◆ getEntriesFromArray()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::getEntriesFromArray ( array  $entries_array)
protected
Parameters
array$entries_array
Returns
Entry

Definition at line 239 of file EntriesYamlParser.php.

References ILIAS\UI\Implementation\Crawler\EntriesYamlParser\getEntryFromData().

Referenced by ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseEntriesFromString().

239  {
240  $entries = new Entry\ComponentEntries();
241 
242  foreach($entries_array as $entry_data){
243  $entries->addEntry($this->getEntryFromData($entry_data));
244  }
245 
246  return $entries;
247  }
Container storing a list of UI Component Entries, can act as Iterator, countable and is serializable...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getEntryFromData()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::getEntryFromData ( array  $entry_data)
protected
Parameters
array$entry_data
Returns
Entry
Exceptions
Exception

Definition at line 254 of file EntriesYamlParser.php.

References ILIAS\UI\Implementation\Crawler\EntriesYamlParser\$file_path.

Referenced by ILIAS\UI\Implementation\Crawler\EntriesYamlParser\getEntriesFromArray().

254  {
255 
256  $entry_data['title'] = self::fromCamelCaseToWords($entry_data['function_name']);
257 
258  if(!array_key_exists("title",$entry_data) || !$entry_data['title'] || $entry_data['title'] ==""){
259  throw $this->ef->exception(Exception\CrawlerException::ENTRY_TITLE_MISSING," File: ".$this->file_path);
260  }
261  if(!array_key_exists("namespace",$entry_data) || !$entry_data['namespace'] || $entry_data['namespace'] ==""){
262  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT," File: ".$this->file_path);
263  }
264 
265  $entry_data['id'] = str_replace("\\","",
266  str_replace("\\ILIAS\\UI\\","", str_replace("\\ILIAS\\UI\\Component\\","",$entry_data['namespace'])) )
267  .self::toUpperCamelCase($entry_data['title'], ' ');
268  $entry_data['abstract'] = preg_match("/Factory/",$entry_data['namespace']);
269  $entry_data['path'] = str_replace("/ILIAS","src",str_replace("\\","/",$entry_data['namespace']));
270 
271  try{
272  $entry = new Entry\ComponentEntry($entry_data);
273  }catch(\Exception $e){
274  throw $this->ef->exception(Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED,
275  " could not convert data to entry, message: '".$e->getMessage()."' file: ".$this->file_path);
276  }
277 
278  return $entry;
279  }
Stores Information of UI Components parsed from YAML, examples and less files.
+ Here is the caller graph for this function:

◆ getFileContentAsString()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::getFileContentAsString (   $filePath)
protected
Parameters
string$filePath
Returns
string
Exceptions
Exception

Definition at line 110 of file EntriesYamlParser.php.

Referenced by ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseArrayFromFile(), ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseEntriesFromFile(), and ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseYamlStringArrayFromFile().

110  {
111  if ( !file_exists($filePath) ) {
112  throw $this->ef->exception(Exception\CrawlerException::INVALID_FILE_PATH,$filePath);
113  }
114  $content = file_get_contents($filePath);
115  if ( !$content ) {
116  throw $this->ef->exception(Exception\CrawlerException::FILE_OPENING_FAILED,$filePath);
117  }
118  return $content;
119  }
+ Here is the caller graph for this function:

◆ getPHPArrayFromYamlArray()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::getPHPArrayFromYamlArray (   $yaml_entries)
protected
Parameters
string$yaml_entries
Returns
array
Exceptions
Exception

Definition at line 214 of file EntriesYamlParser.php.

References $parser, array, and PHP_EOL.

Referenced by ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseArrayFromString().

214  {
215  $entries = array();
216  $parser = new Yaml\Parser();
217 
218  foreach($yaml_entries as $yaml_entry){
219  try{
220  $entries[] = $parser->parse($yaml_entry);
221  }catch(\Exception $e){
222 
223  throw $this->ef->exception(Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED," file: ".$this->file_path."; ".$e);
224  }
225  }
226 
227 
228  array_walk_recursive($entries, function(&$item){
229  $item = rtrim($item,PHP_EOL);
230  });
231 
232  return $entries;
233  }
if($is_dev) echo "Review changes write something in WHATSNEW and and then commit with log PHP_EOL
Create styles array
The data for the language used.
$parser
Definition: BPMN2Parser.php:24
+ Here is the caller graph for this function:

◆ getYamlEntriesFromString()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::getYamlEntriesFromString (   $content)
protected
Parameters
string$content
Returns
array
Exceptions
Exception

Definition at line 126 of file EntriesYamlParser.php.

References array, and ILIAS\UI\Implementation\Crawler\EntriesYamlParser\purifyYamlLine().

Referenced by ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseArrayFromString(), and ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseYamlStringArrayFromString().

126  {
127  $parser_state = self::PARSER_STATE_OUTSIDE;
128  $current_entry = "";
129  $yaml_entries = array();
130 
131  foreach(preg_split("/((\r?\n)|(\r\n?))/", $content) as $line){
132  if($parser_state === self::PARSER_STATE_OUTSIDE ){
133  if(preg_match('/---/', $line)) {
134  $current_entry = "";
135  $parser_state = self::PARSER_STATE_ENTRY;
136 
137  }
138  if(preg_match('/\@return/', $line)) {
139  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
140  " in file: ".$this->file_path.", ".$line);
141  }
142  if(preg_match('/public function (.*)\(/', $line)) {
143  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
144  " in file: ".$this->file_path.", ".$line);
145  }
146  }else if($parser_state === self::PARSER_STATE_ENTRY){
147  if(!preg_match('/(\*$)|(---)/', $line)){
148  $current_entry .= $this->purifyYamlLine($line);
149  }
150  if(preg_match('/---/', $line)) {
151  $parser_state = self::PARSER_STATE_SEEKING_RETURN;
152  }
153  if(preg_match('/\@return/', $line)) {
154  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
155  " in file: ".$this->file_path.", ".$line);
156  }
157  if(preg_match('/public function (.*)\(/', $line)) {
158  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
159  " in file: ".$this->file_path.", ".$line);
160  }
161  }else if($parser_state === self::PARSER_STATE_SEEKING_RETURN) {
162  if(preg_match('/\@return/', $line)) {
163  $current_entry .= "namespace: ".ltrim($this->purifyYamlLine($line),'@return');
164  $parser_state = self::PARSER_STATE_SEEKING_FUNCTION_NAME;
165  }
166  if(preg_match('/---/', $line)) {
167  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
168  " in file: ".$this->file_path." line ".$current_entry);
169  }
170  if(preg_match('/public function (.*)\(/', $line)) {
171  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
172  " in file: ".$this->file_path." line ".$current_entry);
173  }
174  }else{
175  if(preg_match('/public function (.*)\(/', $line,$matches)) {
176  preg_match('/public function (.*)\(/',$line, $matches);
177  $current_entry .= "function_name: ".$matches[1];
178  $yaml_entries[] = $current_entry;
179  $parser_state = self::PARSER_STATE_OUTSIDE;
180  }
181  if(preg_match('/---/', $line)) {
182  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITHOUT_FUNCTION,
183  " in file: ".$this->file_path." line ".$current_entry);
184  }
185  }
186 
187  }
188  if($parser_state === self::PARSER_STATE_SEEKING_RETURN ){
189  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
190  " in file: ".$this->file_path." line ".$current_entry);
191  }else if($parser_state === self::PARSER_STATE_ENTRY){
192  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
193  " in file: ".$this->file_path);
194  }else if($parser_state === self::PARSER_STATE_SEEKING_FUNCTION_NAME){;
195  throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITHOUT_FUNCTION,
196  " in file: ".$this->file_path);
197  }
198  return $yaml_entries;
199  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseArrayFromFile()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::parseArrayFromFile (   $filePath)
Parameters
string$filePath
Returns
array
Exceptions
Exception

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 59 of file EntriesYamlParser.php.

References ILIAS\UI\Implementation\Crawler\EntriesYamlParser\getFileContentAsString(), and ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseArrayFromString().

59  {
60  $this->file_path = $filePath;
61  $content = $this->getFileContentAsString($filePath);
62  return $this->parseArrayFromString($content);
63  }
+ Here is the call graph for this function:

◆ parseArrayFromString()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::parseArrayFromString (   $content)

◆ parseEntriesFromFile()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::parseEntriesFromFile (   $filePath)
Parameters
string$filePath
Returns
Entry
Exceptions
Exception

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 70 of file EntriesYamlParser.php.

References ILIAS\UI\Implementation\Crawler\EntriesYamlParser\getFileContentAsString(), and ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseEntriesFromString().

70  {
71  $this->file_path = $filePath;
72  $content = $this->getFileContentAsString($filePath);
73  return $this->parseEntriesFromString($content);
74  }
+ Here is the call graph for this function:

◆ parseEntriesFromString()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::parseEntriesFromString (   $content)
Parameters
string$content
Returns
Entry

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 100 of file EntriesYamlParser.php.

References ILIAS\UI\Implementation\Crawler\EntriesYamlParser\getEntriesFromArray(), and ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseArrayFromString().

Referenced by ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseEntriesFromFile().

100  {
101  $entries_array = $this->parseArrayFromString($content);
102  return $this->getEntriesFromArray($entries_array);
103  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseYamlStringArrayFromFile()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::parseYamlStringArrayFromFile (   $filePath)
Parameters
string$filePath
Returns
array|string
Exceptions
Exception

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 48 of file EntriesYamlParser.php.

References ILIAS\UI\Implementation\Crawler\EntriesYamlParser\getFileContentAsString(), and ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseYamlStringArrayFromString().

48  {
49  $this->file_path = $filePath;
50  $content = $this->getFileContentAsString($filePath);
51  return $this->parseYamlStringArrayFromString($content);
52  }
+ Here is the call graph for this function:

◆ parseYamlStringArrayFromString()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::parseYamlStringArrayFromString (   $content)
Parameters
string$content
Returns
array
Exceptions
Exception

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 81 of file EntriesYamlParser.php.

References ILIAS\UI\Implementation\Crawler\EntriesYamlParser\getYamlEntriesFromString().

Referenced by ILIAS\UI\Implementation\Crawler\EntriesYamlParser\parseYamlStringArrayFromFile().

81  {
82  return $this->getYamlEntriesFromString($content);
83  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ purifyYamlLine()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::purifyYamlLine (   $line)
protected
Parameters
string$line
Returns
string

Definition at line 205 of file EntriesYamlParser.php.

Referenced by ILIAS\UI\Implementation\Crawler\EntriesYamlParser\getYamlEntriesFromString().

205  {
206  return str_replace("* ", "", ltrim($line)).PHP_EOL;
207  }
+ Here is the caller graph for this function:

◆ toLowerCamelCase()

static ILIAS\UI\Implementation\Crawler\EntriesYamlParser::toLowerCamelCase (   $string,
  $seperator 
)
static
Parameters
string$string
string$seperator
Returns
mixed

Definition at line 295 of file EntriesYamlParser.php.

295  {
296  return str_replace($seperator, '', lcfirst(ucwords($string)));
297  }

◆ toUpperCamelCase()

static ILIAS\UI\Implementation\Crawler\EntriesYamlParser::toUpperCamelCase (   $string,
  $seperator 
)
static
Parameters
string$string
string$seperator
Returns
mixed

Definition at line 286 of file EntriesYamlParser.php.

286  {
287  return str_replace($seperator, '', ucwords($string));
288  }

Field Documentation

◆ $ef

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::$ef = null
protected

Definition at line 27 of file EntriesYamlParser.php.

◆ $file_path

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::$file_path = "none"
protected

◆ $items

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::$items = array()
protected

Definition at line 22 of file EntriesYamlParser.php.

◆ PARSER_STATE_ENTRY

const ILIAS\UI\Implementation\Crawler\EntriesYamlParser::PARSER_STATE_ENTRY = 2

Definition at line 15 of file EntriesYamlParser.php.

◆ PARSER_STATE_OUTSIDE

const ILIAS\UI\Implementation\Crawler\EntriesYamlParser::PARSER_STATE_OUTSIDE = 1

Definition at line 14 of file EntriesYamlParser.php.

◆ PARSER_STATE_SEEKING_FUNCTION_NAME

const ILIAS\UI\Implementation\Crawler\EntriesYamlParser::PARSER_STATE_SEEKING_FUNCTION_NAME = 4

Definition at line 17 of file EntriesYamlParser.php.

◆ PARSER_STATE_SEEKING_RETURN

const ILIAS\UI\Implementation\Crawler\EntriesYamlParser::PARSER_STATE_SEEKING_RETURN = 3

Definition at line 16 of file EntriesYamlParser.php.


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