3declare(strict_types=1);
23use Symfony\Component\Yaml;
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);
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)) {
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)) {
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');
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;
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);
235 }
catch (\Exception
$e) {
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);
256 foreach ($entries_array as $entry_data) {
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);
277 $entry_data[
'id'] = str_replace(
280 str_replace(
"\\ILIAS\\UI\\",
"", str_replace(
"\\ILIAS\\UI\\Component\\",
"", $entry_data[
'namespace']))
283 $entry_data[
'abstract'] = preg_match(
"/Factory/", $entry_data[
'namespace']);
284 $entry_data[
'path'] = str_replace(
"/ILIAS",
"src", str_replace(
"\\",
"/", $entry_data[
'namespace']));
288 }
catch (\Exception
$e) {
289 throw $this->ef->exception(
290 Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED,
291 " could not convert data to entry, message: '" .
$e->getMessage() .
"' file: " . $this->file_path
303 return str_replace($seperator,
'', ucwords($string));
311 return str_replace($seperator,
'', lcfirst(ucwords($string)));
316 return implode(
' ', preg_split(
'/(?<=[a-z])(?=[A-Z])/x', ucwords($camelCaseString)));
parseArrayFromFile(string $filePath)
getEntriesFromArray(array $entries_array)
const PARSER_STATE_OUTSIDE
getFileContentAsString(string $filePath)
getEntryFromData(array $entry_data)
static toLowerCamelCase(string $string, string $seperator)
__construct()
FactoryCrawler constructor.
parseEntriesFromFile(string $filePath)
purifyYamlLine(string $line)
static fromCamelCaseToWords(string $camelCaseString)
string $file_path
Used to add for Information in Exceptions.
static toUpperCamelCase(string $string, string $seperator)
parseYamlStringArrayFromFile(string $filePath)
const PARSER_STATE_SEEKING_FUNCTION_NAME
getYamlEntriesFromString(string $content)
getPHPArrayFromYamlArray(array $yaml_entries)
const PARSER_STATE_SEEKING_RETURN
parseYamlStringArrayFromString(string $content)
parseEntriesFromString(string $content)
Returns a list UI Component Entries of the parsed YAML entries in a given string.
parseArrayFromString(string $content)
Container storing a list of UI Component Entries, can act as Iterator, countable and is serializable.
Stores Information of UI Components parsed from YAML, examples and less files.
Parses information from UI components.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...