ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ILIAS\Setup\ImplementationOfInterfaceFinder Class Reference
+ Inheritance diagram for ILIAS\Setup\ImplementationOfInterfaceFinder:
+ Collaboration diagram for ILIAS\Setup\ImplementationOfInterfaceFinder:

Public Member Functions

 __construct ()
 
 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::$ignore and and the additional patterns provided. More...
 

Protected Member Functions

 getAllClassNames (array $additional_ignore, string $matching_path=null)
 

Protected Attributes

string $root
 
array $ignore
 
array $classmap = null
 

Detailed Description

Definition at line 28 of file ImplementationOfInterfaceFinder.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Setup\ImplementationOfInterfaceFinder::__construct ( )

Definition at line 52 of file ImplementationOfInterfaceFinder.php.

53  {
54  $this->root = substr(__FILE__, 0, strpos(__FILE__, DIRECTORY_SEPARATOR . "src"));
55  $external_classmap = include "./libs/composer/vendor/composer/autoload_classmap.php";
56  $this->classmap = $external_classmap ?: null;
57  }

Member Function Documentation

◆ getAllClassNames()

ILIAS\Setup\ImplementationOfInterfaceFinder::getAllClassNames ( array  $additional_ignore,
string  $matching_path = null 
)
protected
Parameters
string[]$additional_ignore

Definition at line 90 of file ImplementationOfInterfaceFinder.php.

References $path.

Referenced by ILIAS\Setup\ImplementationOfInterfaceFinder\getMatchingClassNames().

90  : \Iterator
91  {
92  $ignore = array_merge($this->ignore, $additional_ignore);
93 
94  if (!is_array($this->classmap)) {
95  throw new \LogicException("Composer ClassMap not loaded");
96  }
97 
98  $regexp = implode(
99  "|",
100  array_map(
101  // fix path-separators to respect windows' backspaces.
102  fn ($v): string => "(" . str_replace('/', '(/|\\\\)', $v) . ")",
103  $ignore
104  )
105  );
106  if ($matching_path) {
107  $matching_path = str_replace('/', '(/|\\\\)', $matching_path);
108  }
109 
110 
111  foreach ($this->classmap as $class_name => $file_path) {
112  $real_path = realpath($file_path);
113  if ($real_path === false) {
114  throw new \RuntimeException(
115  "Could not find file for class $class_name (path: $file_path). " .
116  "Please check the composer classmap, maybe it is outdated. " .
117  "You can regenerate it by executing 'composer du' or 'composer install' " .
118  "(which also ensures dependencies are correctly installed) in the ILIAS root directory."
119  );
120  }
121 
122  $path = str_replace($this->root, "", $real_path);
123  if ($matching_path && !preg_match("#^" . $matching_path . "$#", $path)) {
124  continue;
125  }
126  if (!preg_match("#^" . $regexp . "$#", $path)) {
127  yield $class_name;
128  }
129  }
130  }
$path
Definition: ltiservices.php:32
+ Here is the caller graph for this function:

◆ getMatchingClassNames()

ILIAS\Setup\ImplementationOfInterfaceFinder::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::$ignore and and the additional patterns provided.

Patterns are regexps (without delimiters) to define complete paths on the filesystem to be ignored or selected.

Parameters
string$interface
string[]$additional_ignore
string | null$matching_path

Definition at line 70 of file ImplementationOfInterfaceFinder.php.

References Vendor\Package\$e, and ILIAS\Setup\ImplementationOfInterfaceFinder\getAllClassNames().

74  : \Iterator {
75  foreach ($this->getAllClassNames($additional_ignore, $matching_path) as $class_name) {
76  try {
77  $r = new \ReflectionClass($class_name);
78  if ($r->isInstantiable() && $r->implementsInterface($interface)) {
79  yield $class_name;
80  }
81  } catch (\Throwable $e) {
82  // noting to do here
83  }
84  }
85  }
getAllClassNames(array $additional_ignore, string $matching_path=null)
+ Here is the call graph for this function:

Field Documentation

◆ $classmap

array ILIAS\Setup\ImplementationOfInterfaceFinder::$classmap = null
protected

Definition at line 50 of file ImplementationOfInterfaceFinder.php.

◆ $ignore

array ILIAS\Setup\ImplementationOfInterfaceFinder::$ignore
protected
Initial value:
= [
'.*/src/',
'.*/libs/',
'.*/test/',
'.*/tests/',
'.*/setup/',
'.*ilSOAPAuth.*',
'.*ilPDExternalFeedBlockGUI.*',
]

Definition at line 35 of file ImplementationOfInterfaceFinder.php.

◆ $root

string ILIAS\Setup\ImplementationOfInterfaceFinder::$root
protected

Definition at line 30 of file ImplementationOfInterfaceFinder.php.


The documentation for this class was generated from the following file: