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) {
221 throw $this->ef->exception(
222 Exception\CrawlerException::ENTRY_WITHOUT_FUNCTION,
223 " in file: " . $this->file_path
226 return $yaml_entries;
235 return str_replace(
"* ",
"", ltrim($line)) .
PHP_EOL;
248 foreach ($yaml_entries as $yaml_entry) {
250 $entries[] =
$parser->parse($yaml_entry);
252 throw $this->ef->exception(
Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED,
" file: " . $this->file_path .
"; " . $e);
257 array_walk_recursive($entries,
function (&$item) {
272 foreach ($entries_array as $entry_data) {
286 $entry_data[
'title'] = self::fromCamelCaseToWords($entry_data[
'function_name']);
288 if (!array_key_exists(
"title", $entry_data) || !$entry_data[
'title'] || $entry_data[
'title'] ==
"") {
289 throw $this->ef->exception(
Exception\CrawlerException::ENTRY_TITLE_MISSING,
" File: " . $this->file_path);
291 if (!array_key_exists(
"namespace", $entry_data) || !$entry_data[
'namespace'] || $entry_data[
'namespace'] ==
"") {
292 throw $this->ef->exception(
Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT,
" File: " . $this->file_path);
295 $entry_data[
'id'] = str_replace(
298 str_replace(
"\\ILIAS\\UI\\",
"", str_replace(
"\\ILIAS\\UI\\Component\\",
"", $entry_data[
'namespace']))
300 . self::toUpperCamelCase($entry_data[
'title'],
' ');
301 $entry_data[
'abstract'] = preg_match(
"/Factory/", $entry_data[
'namespace']);
302 $entry_data[
'path'] = str_replace(
"/ILIAS",
"src", str_replace(
"\\",
"/", $entry_data[
'namespace']));
307 throw $this->ef->exception(
308 Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED,
309 " could not convert data to entry, message: '" . $e->getMessage() .
"' file: " .
$this->file_path 323 return str_replace($seperator,
'', ucwords($string));
333 return str_replace($seperator,
'', lcfirst(ucwords($string)));
342 return join(preg_split(
'/(?<=[a-z])(?=[A-Z])/x', ucwords($camelCaseString)),
" ");
parseArrayFromString($content)
static toLowerCamelCase($string, $seperator)
const PARSER_STATE_SEEKING_RETURN
parseEntriesFromString($content)
getYamlEntriesFromString($content)
Container storing a list of UI Component Entries, can act as Iterator, countable and is serializable...
getPHPArrayFromYamlArray($yaml_entries)
static fromCamelCaseToWords($camelCaseString)
parseYamlStringArrayFromString($content)
getEntryFromData(array $entry_data)
const PARSER_STATE_OUTSIDE
getEntriesFromArray(array $entries_array)
Stores Information of UI Components parsed from YAML, examples and less files.
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)