ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
AbstractOfFinder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Setup;
22 
28 abstract class AbstractOfFinder
29 {
30  protected string $root;
31 
35  protected array $ignore = [
36  '.*/src/Setup/',
37  '.*/src/GlobalScreen/',
38  '.*/Customizing/.*/src/',
39  '.*/libs/',
40  '.*/test/',
41  '.*/tests/',
42  '.*/setup/',
43  // Classes using removed Auth-class from PEAR
44  '.*ilSOAPAuth.*',
45  // Classes using unknown
46  '.*ilPDExternalFeedBlockGUI.*',
47  ];
48 
52  protected ?array $classmap = null;
53 
54  public function __construct()
55  {
56  $this->root = substr(__FILE__, 0, strpos(__FILE__, DIRECTORY_SEPARATOR . "src"));
57  $external_classmap = include "./libs/composer/vendor/composer/autoload_classmap.php";
58  $this->classmap = $external_classmap ?: null;
59  }
60 
74  protected function genericGetMatchingClassNames(
75  callable $is_matching,
76  array $additional_ignore = [],
77  string $matching_path = null
78  ): \Iterator {
79  foreach ($this->getAllClassNames($additional_ignore, $matching_path) as $class_name) {
80  try {
81  $reflection_class = new \ReflectionClass($class_name);
82  if ($is_matching($reflection_class)) {
83  yield $class_name;
84  }
85  } catch (\Throwable $e) {
86  // ignore
87  }
88  }
89  }
90 
94  protected function getAllClassNames(array $additional_ignore, string $matching_path = null): \Iterator
95  {
96  $ignore = array_merge($this->ignore, $additional_ignore);
97 
98  if (!is_array($this->classmap)) {
99  throw new \LogicException("Composer ClassMap not loaded");
100  }
101 
102  $regexp = implode(
103  "|",
104  array_map(
105  // fix path-separators to respect windows' backspaces.
106  fn($v): string => "(" . str_replace('/', '(/|\\\\)', $v) . ")",
107  $ignore
108  )
109  );
110  if ($matching_path) {
111  $matching_path = str_replace('/', '(/|\\\\)', $matching_path);
112  }
113 
114 
115  foreach ($this->classmap as $class_name => $file_path) {
116  $real_path = realpath($file_path);
117  if ($real_path === false) {
118  throw new \RuntimeException(
119  "Could not find file for class $class_name (path: $file_path). " .
120  "Please check the composer classmap, maybe it is outdated. " .
121  "You can regenerate it by executing 'composer du' or 'composer install' " .
122  "(which also ensures dependencies are correctly installed) in the ILIAS root directory."
123  );
124  }
125 
126  $path = str_replace($this->root, "", $real_path);
127  if ($matching_path && !preg_match("#^" . $matching_path . "$#", $path)) {
128  continue;
129  }
130  if (!preg_match("#^" . $regexp . "$#", $path)) {
131  yield $class_name;
132  }
133  }
134  }
135 }
$path
Definition: ltiservices.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAllClassNames(array $additional_ignore, string $matching_path=null)
genericGetMatchingClassNames(callable $is_matching, array $additional_ignore=[], string $matching_path=null)
The matcher finds the class names implementing the given interface, while ignoring paths in self::$ig...