ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
FactoriesCrawler.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
24 
25 /***
26  * @author Timon Amstutz <timon.amstutz@ilub.unibe.ch>
27  * @version $Id$
28  */
29 class FactoriesCrawler implements Crawler
30 {
31  protected ?EntriesYamlParser $parser = null;
32  protected ?Exception\Factory $ef = null;
33 
34  public function __construct()
35  {
36  $this->parser = new EntriesYamlParser();
37  $this->ef = new Exception\Factory();
38  }
39 
43  public function crawlFactory(
44  string $factoryPath,
45  Entry\ComponentEntry $parent = null,
46  int $depth = 0
47  ): Entry\ComponentEntries {
48  $depth++;
49  if ($depth > 30) {
50  throw $this->ef->exception(Exception\CrawlerException::CRAWL_MAX_NESTING_REACHED, " Current Path: " . $factoryPath . " Parent: " . $parent->getId());
51  }
52  $entries = $this->parser->parseEntriesFromFile($factoryPath);
53 
54  $children = new Entry\ComponentEntries();
55 
56  foreach ($entries as $entry) {
57  if ($entry->isAbstract()) {
58  $children->addEntries($this->crawlFactory($entry->getPath() . ".php", $entry, $depth));
59  }
60  if ($parent) {
61  $entry->setParent($parent->getId());
62  $parent->addChild($entry->getId());
63  }
64  }
65  $entries->addEntries($children);
66  return $entries;
67  }
68 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
crawlFactory(string $factoryPath, Entry\ComponentEntry $parent=null, int $depth=0)
Starts with the factory indicated by factory path and crawles form this point all subsequent factorie...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Crawler.php:21