ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ImplementationOfInterfaceFinder.php
Go to the documentation of this file.
1<?php
2
3namespace ILIAS\Setup;
4
11{
12
16 private $interface = "";
20 private $ignore
21 = [
22 '.*/libs/',
23 '.*/test/',
24 '.*/tests/',
25 '.*/setup/',
26 // Classes using removed Auth-class from PEAR
27 '.*ilSOAPAuth.*',
28 // Classes using unknown
29 '.*ilPDExternalFeedBlockGUI.*',
30 ];
31
32
33 public function __construct(string $interface)
34 {
35 $this->interface = $interface;
36 $this->getAllClassNames();
37 }
38
39
40 private function getAllClassNames() : \Iterator
41 {
42 // We use the composer classmap ATM
43 $composer_classmap = include "./libs/composer/vendor/composer/autoload_classmap.php";
44 $root = substr(__FILE__, 0, strpos(__FILE__, "/src"));
45
46 if (!is_array($composer_classmap)) {
47 throw new \LogicException("Composer ClassMap not loaded");
48 }
49
50 $regexp = implode(
51 "|",
52 array_map(
53 // fix path-separators to respect windows' backspaces.
54 function ($v) {
55 return "(" . str_replace('/', '(/|\\\\)', $v) . ")";
56 },
58 )
59 );
60
61 foreach ($composer_classmap as $class_name => $file_path) {
62 $path = str_replace($root, "", realpath($file_path));
63 if (!preg_match("#^" . $regexp . "$#", $path)) {
64 yield $class_name;
65 }
66 }
67 }
68
69
70 public function getMatchingClassNames() : \Iterator
71 {
72 foreach ($this->getAllClassNames() as $class_name) {
73 try {
74 $r = new \ReflectionClass($class_name);
75 if ($r->isInstantiable() && $r->implementsInterface($this->interface)) {
76 yield $class_name;
77 }
78 } catch (\Throwable $e) {
79 // noting to do here
80 }
81 }
82 }
83}
An exception for terminatinating execution or to throw for unit testing.