ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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 // Test classes depend on dev-dependencies (e.g. PHPUnit) which are missing in --no-dev installs
40 '.*/tests/',
41 '.*/components/ILIAS/Setup/classes/',
42 // Classes using unknown
43 '.*ilPDExternalFeedBlockGUI.*',
44 ];
45
49 protected ?array $classmap = null;
50
51 public function __construct()
52 {
53 $this->root = substr(__FILE__, 0, strpos(__FILE__, DIRECTORY_SEPARATOR . "components"));
54 $external_classmap = include(__DIR__ . "/../../../../vendor/composer/vendor/composer/autoload_classmap.php");
55 $this->classmap = $external_classmap ?: null;
56 }
57
71 protected function genericGetMatchingClassNames(
72 callable $is_matching,
73 array $additional_ignore = [],
74 ?string $matching_path = null
75 ): \Iterator {
76 foreach ($this->getAllClassNames($additional_ignore, $matching_path) as $class_name) {
77 try {
78 $reflection_class = new \ReflectionClass($class_name);
79 if ($is_matching($reflection_class)) {
80 yield $class_name;
81 }
82 } catch (\Throwable $e) {
83 // ignore
84 }
85 }
86 }
87
91 protected function getAllClassNames(array $additional_ignore, ?string $matching_path = null): \Iterator
92 {
93 $ignore = array_merge($this->ignore, $additional_ignore);
94
95 if (!is_array($this->classmap)) {
96 throw new \LogicException("Composer ClassMap not loaded");
97 }
98
99 $regexp = implode(
100 "|",
101 array_map(
102 // fix path-separators to respect windows' backspaces.
103 fn($v): string => "(" . str_replace('/', '(/|\\\\)', $v) . ")",
104 $ignore
105 )
106 );
107 if ($matching_path) {
108 $matching_path = str_replace('/', '(/|\\\\)', $matching_path);
109 }
110
111
112 foreach ($this->classmap as $class_name => $file_path) {
113 $real_path = realpath($file_path);
114 if ($real_path === false) {
115 throw new \RuntimeException(
116 "Could not find file for class $class_name (path: $file_path). " .
117 "Please check the composer classmap, maybe it is outdated. " .
118 "You can regenerate it by executing 'composer du' or 'composer install' " .
119 "(which also ensures dependencies are correctly installed) in the ILIAS root directory."
120 );
121 }
122
123 $path = str_replace($this->root, "", $real_path);
124 if ($matching_path && !preg_match("#^" . $matching_path . "$#", $path)) {
125 continue;
126 }
127 if (!preg_match("#^" . $regexp . "$#", $path)) {
128 yield $class_name;
129 }
130 }
131 }
132}
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...
foreach( $report as $row)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...