ILIAS  release_7 Revision v7.30-3-g800a261c036
ImplementationOfInterfaceFinder.php
Go to the documentation of this file.
1<?php
2
3namespace ILIAS\Setup;
4
11{
15 protected $root;
16
20 protected $ignore = [
21 '.*/src/',
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
35 protected $classmap = null;
36
37 public function __construct()
38 {
39 $this->root = substr(__FILE__, 0, strpos(__FILE__, "/src"));
40 $this->classmap = include "./libs/composer/vendor/composer/autoload_classmap.php";
41 }
42
53 public function getMatchingClassNames(
54 string $interface,
55 array $additional_ignore = [],
56 string $matching_path = null
57 ) : \Iterator {
58 foreach ($this->getAllClassNames($additional_ignore, $matching_path) as $class_name) {
59 try {
60 $r = new \ReflectionClass($class_name);
61 if ($r->isInstantiable() && $r->implementsInterface($interface)) {
62 yield $class_name;
63 }
64 } catch (\Throwable $e) {
65 // noting to do here
66 }
67 }
68 }
69
73 protected function getAllClassNames(array $additional_ignore, string $matching_path = null) : \Iterator
74 {
75 $ignore = array_merge($this->ignore, $additional_ignore);
76
77 if (!is_array($this->classmap)) {
78 throw new \LogicException("Composer ClassMap not loaded");
79 }
80
81 $regexp = implode(
82 "|",
83 array_map(
84 // fix path-separators to respect windows' backspaces.
85 function ($v) {
86 return "(" . str_replace('/', '(/|\\\\)', $v) . ")";
87 },
89 )
90 );
91 if ($matching_path) {
92 $matching_path = str_replace('/', '(/|\\\\)', $matching_path);
93 }
94
95
96 foreach ($this->classmap as $class_name => $file_path) {
97 $path = str_replace($this->root, "", realpath($file_path));
98 if ($matching_path && !preg_match("#^" . $matching_path . "$#", $path)) {
99 continue;
100 }
101 if (!preg_match("#^" . $regexp . "$#", $path)) {
102 yield $class_name;
103 }
104 }
105 }
106}
while(false !==( $line=fgets( $in))) if(! $columns) $ignore
Definition: Utf8Test.php:63
An exception for terminatinating execution or to throw for unit testing.
getMatchingClassNames(string $interface, array $additional_ignore=[], string $matching_path=null)
The matcher finds the class names implementing the given interface, while ignoring paths in self::$ig...
getAllClassNames(array $additional_ignore, string $matching_path=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...