51 $this->file_path = $filePath;
63 $this->file_path = $filePath;
75 $this->file_path = $filePath;
119 if (!file_exists($filePath)) {
120 throw $this->ef->exception(
Exception\CrawlerException::INVALID_FILE_PATH, $filePath);
122 $content = file_get_contents($filePath);
124 throw $this->ef->exception(
Exception\CrawlerException::FILE_OPENING_FAILED, $filePath);
136 $parser_state = self::PARSER_STATE_OUTSIDE;
138 $yaml_entries = array();
140 foreach (preg_split(
"/((\r?\n)|(\r\n?))/", $content) as $line) {
141 if ($parser_state === self::PARSER_STATE_OUTSIDE) {
142 if (preg_match(
'/---/', $line)) {
144 $parser_state = self::PARSER_STATE_ENTRY;
146 if (preg_match(
'/\@return/', $line)) {
147 throw $this->ef->exception(
148 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
149 " in file: " . $this->file_path .
", " . $line
152 if (preg_match(
'/public function (.*)\(/', $line)) {
153 throw $this->ef->exception(
154 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
155 " in file: " . $this->file_path .
", " . $line
158 } elseif ($parser_state === self::PARSER_STATE_ENTRY) {
159 if (!preg_match(
'/(\*$)|(---)/', $line)) {
162 if (preg_match(
'/---/', $line)) {
163 $parser_state = self::PARSER_STATE_SEEKING_RETURN;
165 if (preg_match(
'/\@return/', $line)) {
166 throw $this->ef->exception(
167 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
168 " in file: " . $this->file_path .
", " . $line
171 if (preg_match(
'/public function (.*)\(/', $line)) {
172 throw $this->ef->exception(
173 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
174 " in file: " . $this->file_path .
", " . $line
177 } elseif ($parser_state === self::PARSER_STATE_SEEKING_RETURN) {
178 if (preg_match(
'/\@return/', $line)) {
179 $current_entry .=
"namespace: " . ltrim($this->
purifyYamlLine($line),
'@return');
180 $parser_state = self::PARSER_STATE_SEEKING_FUNCTION_NAME;
182 if (preg_match(
'/---/', $line)) {
183 throw $this->ef->exception(
184 Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
185 " in file: " . $this->file_path .
" line " . $current_entry
188 if (preg_match(
'/public function (.*)\(/', $line)) {
189 throw $this->ef->exception(
190 Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
191 " in file: " . $this->file_path .
" line " . $current_entry
195 if (preg_match(
'/public function (.*)\(/', $line, $matches)) {
196 preg_match(
'/public function (.*)\(/', $line, $matches);
197 $current_entry .=
"function_name: " . $matches[1];
198 $yaml_entries[] = $current_entry;
199 $parser_state = self::PARSER_STATE_OUTSIDE;
201 if (preg_match(
'/---/', $line)) {
202 throw $this->ef->exception(
203 Exception\CrawlerException::ENTRY_WITHOUT_FUNCTION,
204 " in file: " . $this->file_path .
" line " . $current_entry
209 if ($parser_state === self::PARSER_STATE_SEEKING_RETURN) {
210 throw $this->ef->exception(
211 Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
212 " in file: " . $this->file_path .
" line " . $current_entry
214 } elseif ($parser_state === self::PARSER_STATE_ENTRY) {
215 throw $this->ef->exception(
216 Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION,
217 " in file: " . $this->file_path
219 } elseif ($parser_state === self::PARSER_STATE_SEEKING_FUNCTION_NAME) {
220 throw $this->ef->exception(
221 Exception\CrawlerException::ENTRY_WITHOUT_FUNCTION,
222 " in file: " . $this->file_path
225 return $yaml_entries;
234 return str_replace(
"* ",
"", ltrim($line)) . PHP_EOL;
245 $parser =
new Yaml\Parser();
247 foreach ($yaml_entries as $yaml_entry) {
249 $entries[] = $parser->parse($yaml_entry);
251 throw $this->ef->exception(
Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED,
" file: " . $this->file_path .
"; " . $e);
256 array_walk_recursive($entries,
function (&$item) {
257 $item = rtrim($item, PHP_EOL);
269 $entries =
new Entry\ComponentEntries();
271 foreach ($entries_array as $entry_data) {
285 $entry_data[
'title'] = self::fromCamelCaseToWords($entry_data[
'function_name']);
287 if (!array_key_exists(
"title", $entry_data) || !$entry_data[
'title'] || $entry_data[
'title'] ==
"") {
288 throw $this->ef->exception(
Exception\CrawlerException::ENTRY_TITLE_MISSING,
" File: " . $this->file_path);
290 if (!array_key_exists(
"namespace", $entry_data) || !$entry_data[
'namespace'] || $entry_data[
'namespace'] ==
"") {
291 throw $this->ef->exception(
Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
" File: " . $this->file_path);
294 $entry_data[
'id'] = str_replace(
297 str_replace(
"\\ILIAS\\UI\\",
"", str_replace(
"\\ILIAS\\UI\\Component\\",
"", $entry_data[
'namespace']))
299 . self::toUpperCamelCase($entry_data[
'title'],
' ');
300 $entry_data[
'abstract'] = preg_match(
"/Factory/", $entry_data[
'namespace']);
301 $entry_data[
'path'] = str_replace(
"/ILIAS",
"src", str_replace(
"\\",
"/", $entry_data[
'namespace']));
304 $entry =
new Entry\ComponentEntry($entry_data);
306 throw $this->ef->exception(
307 Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED,
308 " could not convert data to entry, message: '" . $e->getMessage() .
"' file: " .
$this->file_path 322 return str_replace($seperator,
'', ucwords($string));
332 return str_replace($seperator,
'', lcfirst(ucwords($string)));
341 return implode(
' ', preg_split(
'/(?<=[a-z])(?=[A-Z])/x', ucwords($camelCaseString)));
parseArrayFromString($content)
static toLowerCamelCase($string, $seperator)
const PARSER_STATE_SEEKING_RETURN
parseEntriesFromString($content)
getYamlEntriesFromString($content)
getPHPArrayFromYamlArray($yaml_entries)
static fromCamelCaseToWords($camelCaseString)
parseYamlStringArrayFromString($content)
getEntryFromData(array $entry_data)
const PARSER_STATE_OUTSIDE
getEntriesFromArray(array $entries_array)
getFileContentAsString($filePath)
parseYamlStringArrayFromFile($filePath)
Parses information from UI components.
static toUpperCamelCase($string, $seperator)
parseEntriesFromFile($filePath)
const PARSER_STATE_SEEKING_FUNCTION_NAME
__construct()
FactoryCrawler constructor.
parseArrayFromFile($filePath)