ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AbstractOfFinder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Setup;
22
28abstract class AbstractOfFinder
29{
30 protected string $root;
31
35 protected array $ignore = [
36 '.*/components/ILIAS/Setup/',
37 '.*/components/ILIAS/GlobalScreen/tests/',
38 '.*/vendor/',
39 '.*/components/ILIAS/App/tests/',
40 '.*/components/ILIAS/BackgroundTasks/tests/',
41 '.*/components/ILIAS/Cache/tests/',
42 '.*/components/ILIAS/Data/tests/',
43 '.*/components/ILIAS/FileUpload/tests/',
44 '.*/components/ILIAS/Filesystem/tests/',
45 '.*/components/ILIAS/GlobalCache/tests/',
46 '.*/components/ILIAS/HTTP/tests/',
47 '.*/components/ILIAS/KioskMode/tests/',
48 '.*/components/ILIAS/Language/tests/',
49 '.*/components/ILIAS/Refinery/tests/',
50 '.*/components/ILIAS/ResourceStorage/tests/',
51 '.*/components/ILIAS/Types/tests/',
52 '.*/components/ILIAS/UI/tests/',
53 '.*/components/ILIAS/VirusScanner/tests/',
54 '.*/components/ILIAS/setup_/',
55 // Classes using removed Auth-class from PEAR
56 '.*ilSOAPAuth.*',
57 // Classes using unknown
58 '.*ilPDExternalFeedBlockGUI.*',
59 ];
60
64 protected ?array $classmap = null;
65
66 public function __construct()
67 {
68 $this->root = substr(__FILE__, 0, strpos(__FILE__, DIRECTORY_SEPARATOR . "components"));
69 $external_classmap = include(__DIR__ . "/../../../../vendor/composer/vendor/composer/autoload_classmap.php");
70 $this->classmap = $external_classmap ?: null;
71 }
72
86 protected function genericGetMatchingClassNames(
87 callable $is_matching,
88 array $additional_ignore = [],
89 ?string $matching_path = null
90 ): \Iterator {
91 foreach ($this->getAllClassNames($additional_ignore, $matching_path) as $class_name) {
92 try {
93 $reflection_class = new \ReflectionClass($class_name);
94 if ($is_matching($reflection_class)) {
95 yield $class_name;
96 }
97 } catch (\Throwable $e) {
98 // ignore
99 }
100 }
101 }
102
106 protected function getAllClassNames(array $additional_ignore, ?string $matching_path = null): \Iterator
107 {
108 $ignore = array_merge($this->ignore, $additional_ignore);
109
110 if (!is_array($this->classmap)) {
111 throw new \LogicException("Composer ClassMap not loaded");
112 }
113
114 $regexp = implode(
115 "|",
116 array_map(
117 // fix path-separators to respect windows' backspaces.
118 fn($v): string => "(" . str_replace('/', '(/|\\\\)', $v) . ")",
119 $ignore
120 )
121 );
122 if ($matching_path) {
123 $matching_path = str_replace('/', '(/|\\\\)', $matching_path);
124 }
125
126
127 foreach ($this->classmap as $class_name => $file_path) {
128 $real_path = realpath($file_path);
129 if ($real_path === false) {
130 throw new \RuntimeException(
131 "Could not find file for class $class_name (path: $file_path). " .
132 "Please check the composer classmap, maybe it is outdated. " .
133 "You can regenerate it by executing 'composer du' or 'composer install' " .
134 "(which also ensures dependencies are correctly installed) in the ILIAS root directory."
135 );
136 }
137
138 $path = str_replace($this->root, "", $real_path);
139 if ($matching_path && !preg_match("#^" . $matching_path . "$#", $path)) {
140 continue;
141 }
142 if (!preg_match("#^" . $regexp . "$#", $path)) {
143 yield $class_name;
144 }
145 }
146 }
147}
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...
$path
Definition: ltiservices.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...