19 declare(strict_types=1);
58 $this->file_path = $filePath;
68 $this->file_path = $filePath;
78 $this->file_path = $filePath;
112 if (!file_exists($filePath)) {
113 throw $this->ef->exception(
Exception\CrawlerException::INVALID_FILE_PATH, $filePath);
115 $content = file_get_contents($filePath);
117 throw $this->ef->exception(
Exception\CrawlerException::FILE_OPENING_FAILED, $filePath);
127 $parser_state = self::PARSER_STATE_OUTSIDE;
129 $yaml_entries = array();
131 foreach (preg_split(
"/((\r?\n)|(\r\n?))/", $content) as $line) {
132 if ($parser_state === self::PARSER_STATE_OUTSIDE) {
133 if (preg_match(
'/---/', $line)) {
135 $parser_state = self::PARSER_STATE_ENTRY;
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
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
149 } elseif ($parser_state === self::PARSER_STATE_ENTRY) {
150 if (!preg_match(
'/(\*$)|(---)/', $line)) {
153 if (preg_match(
'/---/', $line)) {
154 $parser_state = self::PARSER_STATE_SEEKING_RETURN;
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
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
168 } elseif ($parser_state === self::PARSER_STATE_SEEKING_RETURN) {
169 if (preg_match(
'/\@return/', $line)) {
170 $current_entry .=
"namespace: " . ltrim($this->
purifyYamlLine($line),
'@return');
171 $parser_state = self::PARSER_STATE_SEEKING_FUNCTION_NAME;
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
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
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;
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
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
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
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
216 return $yaml_entries;
221 return str_replace(
"* ",
"", ltrim($line)) . PHP_EOL;
230 $parser =
new Yaml\Parser();
232 foreach ($yaml_entries as $yaml_entry) {
234 $entries[] = $parser->parse($yaml_entry);
236 throw $this->ef->exception(
Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED,
" file: " . $this->file_path .
"; " . $e);
241 array_walk_recursive($entries,
function (&$item) {
242 if (!is_null($item)) {
243 $item = rtrim($item, PHP_EOL);
254 $entries =
new Entry\ComponentEntries();
256 foreach ($entries_array as $entry_data) {
268 $entry_data[
'title'] = self::fromCamelCaseToWords($entry_data[
'function_name']);
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);
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);
276 $entry_data[
'namespace'] = str_replace(
'[]',
'', $entry_data[
'namespace']);
278 $entry_data[
'id'] = str_replace(
281 str_replace(
"\\ILIAS\\UI\\",
"", str_replace(
"\\ILIAS\\UI\\Component\\",
"", $entry_data[
'namespace']))
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']));
287 if (str_contains($entry_data[
'path'],
'tests/UI/')) {
288 $entry_data[
'path'] = str_replace(
"tests/UI/",
"components/ILIAS/UI/tests/", $entry_data[
'path']);
292 $entry =
new Entry\ComponentEntry($entry_data);
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 308 return str_replace($seperator,
'', ucwords($string));
316 return str_replace($seperator,
'', lcfirst(ucwords($string)));
321 return implode(
' ', preg_split(
'/(?<=[a-z])(?=[A-Z])/x', ucwords($camelCaseString)));
static toLowerCamelCase(string $string, string $seperator)
const PARSER_STATE_SEEKING_RETURN
parseEntriesFromFile(string $filePath)
parseArrayFromFile(string $filePath)
parseYamlStringArrayFromString(string $content)
getPHPArrayFromYamlArray(array $yaml_entries)
getEntryFromData(array $entry_data)
const PARSER_STATE_OUTSIDE
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
parseArrayFromString(string $content)
getEntriesFromArray(array $entries_array)
static toUpperCamelCase(string $string, string $seperator)
getYamlEntriesFromString(string $content)
getFileContentAsString(string $filePath)
parseEntriesFromString(string $content)
Returns a list UI Component Entries of the parsed YAML entries in a given string. ...
parseYamlStringArrayFromFile(string $filePath)
purifyYamlLine(string $line)
string $file_path
Used to add for Information in Exceptions.
Parses information from UI components.
static fromCamelCaseToWords(string $camelCaseString)
const PARSER_STATE_SEEKING_FUNCTION_NAME
__construct()
FactoryCrawler constructor.