ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 (string $filePath)
 
 parseArrayFromFile (string $filePath)
 
 parseEntriesFromFile (string $filePath)
 
 parseYamlStringArrayFromString (string $content)
 
 parseArrayFromString (string $content)
 
 parseEntriesFromString (string $content)
 Returns a list UI Component Entries of the parsed YAML entries in a given string. More...
 
 parseYamlStringArrayFromFile (string $filePath)
 Returns an array of all YAML entries as string of the components in the factories in a given file. More...
 
 parseArrayFromFile (string $filePath)
 Returns an array of arrays of the parsed YAML entries in a given file. More...
 
 parseEntriesFromFile (string $filePath)
 Returns an Entry\ComponentEntries of the parsed YAML entries in a given file. More...
 
 parseYamlStringArrayFromString (string $content)
 Returns an array of all YAML entries as string of the components in the factories in a given string. More...
 
 parseArrayFromString (string $content)
 Returns an array of arrays of the parsed YAML entries in a given string. More...
 
 parseEntriesFromString (string $content)
 Returns a list UI Component Entries of the parsed YAML entries in a given string. More...
 

Static Public Member Functions

static toUpperCamelCase (string $string, string $seperator)
 
static toLowerCamelCase (string $string, string $seperator)
 
static fromCamelCaseToWords (string $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 (string $filePath)
 
 getYamlEntriesFromString (string $content)
 
 purifyYamlLine (string $line)
 
 getPHPArrayFromYamlArray (array $yaml_entries)
 
 getEntriesFromArray (array $entries_array)
 
 getEntryFromData (array $entry_data)
 

Protected Attributes

array $items = array()
 
Exception Factory $ef = null
 
string $file_path = "none"
 Used to add for Information in Exceptions. More...
 

Detailed Description

Definition at line 30 of file EntriesYamlParser.php.

Constructor & Destructor Documentation

◆ __construct()

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

FactoryCrawler constructor.

Definition at line 48 of file EntriesYamlParser.php.

49 {
50 $this->ef = new Exception\Factory();
51 }

Member Function Documentation

◆ fromCamelCaseToWords()

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

Definition at line 319 of file EntriesYamlParser.php.

319 : string
320 {
321 return implode(' ', preg_split('/(?<=[a-z])(?=[A-Z])/x', ucwords($camelCaseString)));
322 }

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

+ Here is the caller graph for this function:

◆ getEntriesFromArray()

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

Definition at line 252 of file EntriesYamlParser.php.

253 {
254 $entries = new Entry\ComponentEntries();
255
256 foreach ($entries_array as $entry_data) {
257 $entries->addEntry($this->getEntryFromData($entry_data));
258 }
259
260 return $entries;
261 }
Container storing a list of UI Component Entries, can act as Iterator, countable and is serializable.

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

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

+ 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
Exceptions
Exception

CrawlerException

Definition at line 266 of file EntriesYamlParser.php.

267 {
268 $entry_data['title'] = self::fromCamelCaseToWords($entry_data['function_name']);
269
270 if (!array_key_exists("title", $entry_data) || !$entry_data['title'] || $entry_data['title'] == "") {
271 throw $this->ef->exception(Exception\CrawlerException::ENTRY_TITLE_MISSING, " File: " . $this->file_path);
272 }
273 if (!array_key_exists("namespace", $entry_data) || !$entry_data['namespace'] || $entry_data['namespace'] == "") {
274 throw $this->ef->exception(Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT, " File: " . $this->file_path);
275 }
276 $entry_data['namespace'] = str_replace('[]', '', $entry_data['namespace']);
277
278 $entry_data['id'] = str_replace(
279 "\\",
280 "",
281 str_replace("\\ILIAS\\UI\\", "", str_replace("\\ILIAS\\UI\\Component\\", "", $entry_data['namespace']))
282 )
283 . self::toUpperCamelCase($entry_data['title'], ' ');
284 $entry_data['abstract'] = preg_match("/Factory/", $entry_data['namespace']);
285 $entry_data['path'] = str_replace("/ILIAS/UI", "components/ILIAS/UI/src", str_replace("\\", "/", $entry_data['namespace']));
286
287 if (str_contains($entry_data['path'], 'tests/UI/')) {
288 $entry_data['path'] = str_replace("tests/UI/", "components/ILIAS/UI/tests/", $entry_data['path']);
289 }
290
291 try {
292 $entry = new Entry\ComponentEntry($entry_data);
293 } catch (\Exception $e) {
294 throw $this->ef->exception(
295 Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED,
296 " could not convert data to entry, message: '" . $e->getMessage() . "' file: " . $this->file_path
297 );
298 }
299
300 return $entry;
301 }
static fromCamelCaseToWords(string $camelCaseString)
static toUpperCamelCase(string $string, string $seperator)
Stores Information of UI Components parsed from YAML, examples and less files.

References Vendor\Package\$e, ILIAS\UI\Implementation\Crawler\EntriesYamlParser\fromCamelCaseToWords(), and ILIAS\UI\Implementation\Crawler\EntriesYamlParser\toUpperCamelCase().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFileContentAsString()

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

CrawlerException

Definition at line 110 of file EntriesYamlParser.php.

110 : string
111 {
112 if (!file_exists($filePath)) {
113 throw $this->ef->exception(Exception\CrawlerException::INVALID_FILE_PATH, $filePath);
114 }
115 $content = file_get_contents($filePath);
116 if (!$content) {
117 throw $this->ef->exception(Exception\CrawlerException::FILE_OPENING_FAILED, $filePath);
118 }
119 return $content;
120 }

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

+ Here is the caller graph for this function:

◆ getPHPArrayFromYamlArray()

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

CrawlerException

Definition at line 227 of file EntriesYamlParser.php.

227 : array
228 {
229 $entries = array();
230 $parser = new Yaml\Parser();
231
232 foreach ($yaml_entries as $yaml_entry) {
233 try {
234 $entries[] = $parser->parse($yaml_entry);
235 } catch (\Exception $e) {
236 throw $this->ef->exception(Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED, " file: " . $this->file_path . "; " . $e);
237 }
238 }
239
240
241 array_walk_recursive($entries, function (&$item) {
242 if (!is_null($item)) {
243 $item = rtrim($item, PHP_EOL);
244 } else {
245 $item = '';
246 }
247 });
248
249 return $entries;
250 }

References Vendor\Package\$e.

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

+ Here is the caller graph for this function:

◆ getYamlEntriesFromString()

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

CrawlerException

Reimplemented in ILIAS\UI\Implementation\Crawler\ExamplesYamlParser.

Definition at line 125 of file EntriesYamlParser.php.

125 : array
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 if (preg_match('/\@return/', $line)) {
138 throw $this->ef->exception(
139 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
140 " in file: " . $this->file_path . ", " . $line
141 );
142 }
143 if (preg_match('/public function (.*)\‍(/', $line)) {
144 throw $this->ef->exception(
145 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
146 " in file: " . $this->file_path . ", " . $line
147 );
148 }
149 } elseif ($parser_state === self::PARSER_STATE_ENTRY) {
150 if (!preg_match('/(\*$)|(---)/', $line)) {
151 $current_entry .= $this->purifyYamlLine($line);
152 }
153 if (preg_match('/---/', $line)) {
154 $parser_state = self::PARSER_STATE_SEEKING_RETURN;
155 }
156 if (preg_match('/\@return/', $line)) {
157 throw $this->ef->exception(
158 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
159 " in file: " . $this->file_path . ", " . $line
160 );
161 }
162 if (preg_match('/public function (.*)\‍(/', $line)) {
163 throw $this->ef->exception(
164 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
165 " in file: " . $this->file_path . ", " . $line
166 );
167 }
168 } elseif ($parser_state === self::PARSER_STATE_SEEKING_RETURN) {
169 if (preg_match('/\@return/', $line)) {
170 $current_entry .= "namespace: " . ltrim($this->purifyYamlLine($line), '@return');
172 }
173 if (preg_match('/---/', $line)) {
174 throw $this->ef->exception(
175 Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
176 " in file: " . $this->file_path . " line " . $current_entry
177 );
178 }
179 if (preg_match('/public function (.*)\‍(/', $line)) {
180 throw $this->ef->exception(
181 Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
182 " in file: " . $this->file_path . " line " . $current_entry
183 );
184 }
185 } else {
186 if (preg_match('/public function (.*)\‍(/', $line, $matches)) {
187 preg_match('/public function (.*)\‍(/', $line, $matches);
188 $current_entry .= "function_name: " . $matches[1];
189 $yaml_entries[] = $current_entry;
190 $parser_state = self::PARSER_STATE_OUTSIDE;
191 }
192 if (preg_match('/---/', $line)) {
193 throw $this->ef->exception(
194 Exception\CrawlerException::ENTRY_WITHOUT_FUNCTION,
195 " in file: " . $this->file_path . " line " . $current_entry
196 );
197 }
198 }
199 }
200 if ($parser_state === self::PARSER_STATE_SEEKING_RETURN) {
201 throw $this->ef->exception(
202 Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
203 " in file: " . $this->file_path . " line " . $current_entry
204 );
205 } elseif ($parser_state === self::PARSER_STATE_ENTRY) {
206 throw $this->ef->exception(
207 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
208 " in file: " . $this->file_path
209 );
210 } elseif ($parser_state === self::PARSER_STATE_SEEKING_FUNCTION_NAME) {
211 throw $this->ef->exception(
212 Exception\CrawlerException::ENTRY_WITHOUT_FUNCTION,
213 " in file: " . $this->file_path
214 );
215 }
216 return $yaml_entries;
217 }

References ILIAS\UI\Implementation\Crawler\EntriesYamlParser\PARSER_STATE_ENTRY, ILIAS\UI\Implementation\Crawler\EntriesYamlParser\PARSER_STATE_OUTSIDE, ILIAS\UI\Implementation\Crawler\EntriesYamlParser\PARSER_STATE_SEEKING_FUNCTION_NAME, ILIAS\UI\Implementation\Crawler\EntriesYamlParser\PARSER_STATE_SEEKING_RETURN, and ILIAS\UI\Implementation\Crawler\EntriesYamlParser\purifyYamlLine().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseArrayFromFile()

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

CrawlerException

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 66 of file EntriesYamlParser.php.

66 : array
67 {
68 $this->file_path = $filePath;
69 $content = $this->getFileContentAsString($filePath);
70 return $this->parseArrayFromString($content);
71 }

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

+ Here is the call graph for this function:

◆ parseArrayFromString()

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

◆ parseEntriesFromFile()

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

CrawlerException

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 76 of file EntriesYamlParser.php.

77 {
78 $this->file_path = $filePath;
79 $content = $this->getFileContentAsString($filePath);
80 return $this->parseEntriesFromString($content);
81 }
parseEntriesFromString(string $content)
Returns a list UI Component Entries of the parsed YAML entries in a given string.

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

+ Here is the call graph for this function:

◆ parseEntriesFromString()

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

Returns a list UI Component Entries of the parsed YAML entries in a given string.

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 101 of file EntriesYamlParser.php.

102 {
103 $entries_array = $this->parseArrayFromString($content);
104 return $this->getEntriesFromArray($entries_array);
105 }

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseYamlStringArrayFromFile()

ILIAS\UI\Implementation\Crawler\EntriesYamlParser::parseYamlStringArrayFromFile ( string  $filePath)
Exceptions
Exception

CrawlerException

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 56 of file EntriesYamlParser.php.

56 : array
57 {
58 $this->file_path = $filePath;
59 $content = $this->getFileContentAsString($filePath);
60 return $this->parseYamlStringArrayFromString($content);
61 }

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

+ Here is the call graph for this function:

◆ parseYamlStringArrayFromString()

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

CrawlerException

Implements ILIAS\UI\Implementation\Crawler\YamlParser.

Definition at line 86 of file EntriesYamlParser.php.

86 : array
87 {
88 return $this->getYamlEntriesFromString($content);
89 }

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ purifyYamlLine()

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

Definition at line 219 of file EntriesYamlParser.php.

219 : string
220 {
221 return str_replace("* ", "", ltrim($line)) . PHP_EOL;
222 }

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

+ Here is the caller graph for this function:

◆ toLowerCamelCase()

static ILIAS\UI\Implementation\Crawler\EntriesYamlParser::toLowerCamelCase ( string  $string,
string  $seperator 
)
static
Returns
string|string[]

Definition at line 314 of file EntriesYamlParser.php.

315 {
316 return str_replace($seperator, '', lcfirst(ucwords($string)));
317 }

◆ toUpperCamelCase()

static ILIAS\UI\Implementation\Crawler\EntriesYamlParser::toUpperCamelCase ( string  $string,
string  $seperator 
)
static
Returns
string|string[]

Definition at line 306 of file EntriesYamlParser.php.

307 {
308 return str_replace($seperator, '', ucwords($string));
309 }

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

+ Here is the caller graph for this function:

Field Documentation

◆ $ef

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

Definition at line 38 of file EntriesYamlParser.php.

◆ $file_path

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

Used to add for Information in Exceptions.

Definition at line 43 of file EntriesYamlParser.php.

◆ $items

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

Definition at line 37 of file EntriesYamlParser.php.

◆ PARSER_STATE_ENTRY

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

◆ PARSER_STATE_OUTSIDE

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

◆ PARSER_STATE_SEEKING_FUNCTION_NAME

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

◆ PARSER_STATE_SEEKING_RETURN

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

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