ILIAS  release_8 Revision v8.24
ilCtrlStructureReader Class Reference

Class ilCtrlStructureReader is responsible for reading ilCtrl's control structure. More...

+ Collaboration diagram for ilCtrlStructureReader:

Public Member Functions

 __construct (ilCtrlIteratorInterface $iterator, ilCtrlStructureCidGenerator $cid_generator)
 ilCtrlStructureReader Constructor More...
 
 isExecuted ()
 Returns whether this instance was already executed or not. More...
 
 readStructure ()
 Processes all classes within the ILIAS installation. More...
 

Data Fields

const REGEX_GUI_CLASS_NAME = '/^class\.([A-z0-9]*(GUI))\.php$/'
 

Private Member Functions

 getReferencedClassesByReflection (ReflectionClass $reflection, string $regex)
 Returns all classes referenced by an ilCtrl_Calls or ilCtrl_isCalledBy statement. More...
 
 getRelativePath (string $absolute_path)
 Returns a given path relative to the ILIAS absolute path. More...
 
 getChildren (ReflectionClass $reflection)
 Helper function that returns all children references. More...
 
 getParents (ReflectionClass $reflection)
 Helper function that returns all parent references. More...
 
 stripWhitespaces (string $string)
 Helper function that replaces all whitespace characters from the given string. More...
 
 isGuiClass (string $path)
 Returns whether the given file/path matches ILIAS conventions. More...
 
 isNamespaced (string $class_name)
 Returns if the given classname is namespaced. More...
 

Private Attributes

const REGEX_PHPDOC_CALLS = '/(((?i)@ilctrl_calls)\s*({CLASS_NAME}(:\s*|\s*:\s*))\K)([A-z0-9,\s])*/'
 
const REGEX_PHPDOC_CALLED_BYS = '/(((?i)@ilctrl_iscalledby)\s*({CLASS_NAME}(:\s*|\s*:\s*))\K)([A-z0-9,\s])*/'
 
ilCtrlStructureCidGenerator $cid_generator
 
ilCtrlIteratorInterface $iterator
 
bool $is_executed = false
 
string $ilias_path
 

Detailed Description

Class ilCtrlStructureReader is responsible for reading ilCtrl's control structure.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Thibeau Fuhrer thf@s.nosp@m.tude.nosp@m.r-rai.nosp@m.mann.nosp@m..ch

Definition at line 16 of file class.ilCtrlStructureReader.php.

Constructor & Destructor Documentation

◆ __construct()

ilCtrlStructureReader::__construct ( ilCtrlIteratorInterface  $iterator,
ilCtrlStructureCidGenerator  $cid_generator 
)

ilCtrlStructureReader Constructor

Parameters
ilCtrlIteratorInterface$iterator
ilCtrlStructureCidGenerator$cid_generator

Definition at line 71 of file class.ilCtrlStructureReader.php.

72 {
73 $this->ilias_path = rtrim(
74 (defined('ILIAS_ABSOLUTE_PATH')) ?
75 ILIAS_ABSOLUTE_PATH : dirname(__FILE__, 5),
76 '/'
77 );
78
79 $this->cid_generator = $cid_generator;
80 $this->iterator = $iterator;
81 }
ilCtrlIteratorInterface $iterator
ilCtrlStructureCidGenerator $cid_generator

References $cid_generator, and $iterator.

Member Function Documentation

◆ getChildren()

ilCtrlStructureReader::getChildren ( ReflectionClass  $reflection)
private

Helper function that returns all children references.

Parameters
ReflectionClass$reflection
Returns
array

Definition at line 210 of file class.ilCtrlStructureReader.php.

210 : array
211 {
212 return $this->getReferencedClassesByReflection($reflection, self::REGEX_PHPDOC_CALLS);
213 }
getReferencedClassesByReflection(ReflectionClass $reflection, string $regex)
Returns all classes referenced by an ilCtrl_Calls or ilCtrl_isCalledBy statement.

References getReferencedClassesByReflection().

Referenced by readStructure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParents()

ilCtrlStructureReader::getParents ( ReflectionClass  $reflection)
private

Helper function that returns all parent references.

Parameters
ReflectionClass$reflection
Returns
array

Definition at line 221 of file class.ilCtrlStructureReader.php.

221 : array
222 {
223 return $this->getReferencedClassesByReflection($reflection, self::REGEX_PHPDOC_CALLED_BYS);
224 }

References getReferencedClassesByReflection().

Referenced by readStructure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getReferencedClassesByReflection()

ilCtrlStructureReader::getReferencedClassesByReflection ( ReflectionClass  $reflection,
string  $regex 
)
private

Returns all classes referenced by an ilCtrl_Calls or ilCtrl_isCalledBy statement.

Parameters
ReflectionClass$reflection
string$regex
Returns
array

Definition at line 155 of file class.ilCtrlStructureReader.php.

155 : array
156 {
157 // abort if the class has no PHPDoc comment.
158 if (!$reflection->getDocComment()) {
159 return [];
160 }
161
162 // replace the classname placeholder with the
163 // actual one and execute the regex search.
164 $name = str_replace('\\', '\\\\', $reflection->getName());
165 $regex = str_replace('{CLASS_NAME}', $name, $regex);
166 preg_match_all($regex, $reflection->getDocComment(), $matches);
167
168 // the first array entry of $matches contains
169 // the list's of statements found.
170 if (empty($matches[0])) {
171 return [];
172 }
173
174 $referenced_classes = [];
175 foreach ($matches[0] as $class_list) {
176 // explode lists and strip all whitespaces.
177 foreach (explode(',', $class_list) as $class) {
178 $class_name = $this->stripWhitespaces($class);
179 if (!empty($class_name)) {
180 $referenced_classes[] = strtolower($class_name);
181 }
182 }
183 }
184
185 return $referenced_classes;
186 }
stripWhitespaces(string $string)
Helper function that replaces all whitespace characters from the given string.
if($format !==null) $name
Definition: metadata.php:247

References $name, and stripWhitespaces().

Referenced by getChildren(), and getParents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRelativePath()

ilCtrlStructureReader::getRelativePath ( string  $absolute_path)
private

Returns a given path relative to the ILIAS absolute path.

Parameters
string$absolute_path
Returns
string

Definition at line 194 of file class.ilCtrlStructureReader.php.

194 : string
195 {
196 // some paths might contain syntax like '../../../' etc.
197 // and realpath() resolves that in order to cut off the
198 // ilias installation path properly.
199 $absolute_path = realpath($absolute_path);
200
201 return '.' . str_replace($this->ilias_path, '', $absolute_path);
202 }

Referenced by readStructure().

+ Here is the caller graph for this function:

◆ isExecuted()

ilCtrlStructureReader::isExecuted ( )

Returns whether this instance was already executed or not.

Returns
bool

Definition at line 88 of file class.ilCtrlStructureReader.php.

88 : bool
89 {
90 return $this->is_executed;
91 }

References $is_executed.

◆ isGuiClass()

ilCtrlStructureReader::isGuiClass ( string  $path)
private

Returns whether the given file/path matches ILIAS conventions.

Parameters
string$path
Returns
bool

Definition at line 244 of file class.ilCtrlStructureReader.php.

244 : bool
245 {
246 return (bool) preg_match(self::REGEX_GUI_CLASS_NAME, basename($path));
247 }
$path
Definition: ltiservices.php:32

References $path.

Referenced by readStructure().

+ Here is the caller graph for this function:

◆ isNamespaced()

ilCtrlStructureReader::isNamespaced ( string  $class_name)
private

Returns if the given classname is namespaced.

Parameters
string$class_name
Returns
bool

Definition at line 255 of file class.ilCtrlStructureReader.php.

255 : bool
256 {
257 return (false !== strpos($class_name, '\\'));
258 }

Referenced by readStructure().

+ Here is the caller graph for this function:

◆ readStructure()

ilCtrlStructureReader::readStructure ( )

Processes all classes within the ILIAS installation.

Returns
array

Definition at line 98 of file class.ilCtrlStructureReader.php.

98 : array
99 {
100 $base_classes = $structure = [];
101 foreach ($this->iterator as $class_name => $path) {
102 // skip iteration if class doesn't meet ILIAS GUI class criteria.
103 if (!$this->isGuiClass($path)) {
104 continue;
105 }
106
107 $lower_class_name = strtolower($class_name);
108 try {
109 // the classes need to be required manually, because
110 // the autoload classmap might not include the plugin
111 // classes when an update is triggered (small structure
112 // reload).
113 require_once $path;
114
115 $reflection = ($this->isNamespaced($class_name)) ?
116 new ReflectionClass("\\$class_name") :
117 new ReflectionClass($class_name)
118 ;
119
120 $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_CID] = $this->cid_generator->getCid();
121 $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_NAME] = $class_name;
122 $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_PATH] = $this->getRelativePath($path);
123 $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_CHILDREN] = $this->getChildren($reflection);
124 $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_PARENTS] = $this->getParents($reflection);
125
126 // temporarily store base classes in order to filer the
127 // structure afterwards.
128 if (in_array(ilCtrlBaseClassInterface::class, $reflection->getInterfaceNames(), true)) {
129 $base_classes[] = $lower_class_name;
130 }
131 } catch (ReflectionException $e) {
132 continue;
133 }
134 }
135
136 $mapped_structure = (new ilCtrlStructureHelper($base_classes, $structure))
137 ->mapStructureReferences()
138 ->filterUnnecessaryEntries()
139 ->getStructure()
140 ;
141
142 $this->is_executed = true;
143
144 return $mapped_structure;
145 }
Class ilCtrlStructureHelper.
isNamespaced(string $class_name)
Returns if the given classname is namespaced.
getChildren(ReflectionClass $reflection)
Helper function that returns all children references.
getRelativePath(string $absolute_path)
Returns a given path relative to the ILIAS absolute path.
isGuiClass(string $path)
Returns whether the given file/path matches ILIAS conventions.
getParents(ReflectionClass $reflection)
Helper function that returns all parent references.
const KEY_CLASS_CID
array key constants that are used for certain information.

References Vendor\Package\$e, $path, getChildren(), getParents(), getRelativePath(), isGuiClass(), isNamespaced(), ilCtrlStructureInterface\KEY_CLASS_CHILDREN, ilCtrlStructureInterface\KEY_CLASS_CID, ilCtrlStructureInterface\KEY_CLASS_NAME, ilCtrlStructureInterface\KEY_CLASS_PARENTS, and ilCtrlStructureInterface\KEY_CLASS_PATH.

+ Here is the call graph for this function:

◆ stripWhitespaces()

ilCtrlStructureReader::stripWhitespaces ( string  $string)
private

Helper function that replaces all whitespace characters from the given string.

Parameters
string$string
Returns
string

Definition at line 233 of file class.ilCtrlStructureReader.php.

233 : string
234 {
235 return (string) preg_replace('/\s+/', '', $string);
236 }

Referenced by getReferencedClassesByReflection().

+ Here is the caller graph for this function:

Field Documentation

◆ $cid_generator

ilCtrlStructureCidGenerator ilCtrlStructureReader::$cid_generator
private

Definition at line 42 of file class.ilCtrlStructureReader.php.

Referenced by __construct().

◆ $ilias_path

string ilCtrlStructureReader::$ilias_path
private

Definition at line 63 of file class.ilCtrlStructureReader.php.

◆ $is_executed

bool ilCtrlStructureReader::$is_executed = false
private

Definition at line 56 of file class.ilCtrlStructureReader.php.

Referenced by isExecuted().

◆ $iterator

ilCtrlIteratorInterface ilCtrlStructureReader::$iterator
private

Definition at line 49 of file class.ilCtrlStructureReader.php.

Referenced by __construct().

◆ REGEX_GUI_CLASS_NAME

const ilCtrlStructureReader::REGEX_GUI_CLASS_NAME = '/^class\.([A-z0-9]*(GUI))\.php$/'

Definition at line 22 of file class.ilCtrlStructureReader.php.

◆ REGEX_PHPDOC_CALLED_BYS

const ilCtrlStructureReader::REGEX_PHPDOC_CALLED_BYS = '/(((?i)@ilctrl_iscalledby)\s*({CLASS_NAME}(:\s*|\s*:\s*))\K)([A-z0-9,\s])*/'
private

Definition at line 35 of file class.ilCtrlStructureReader.php.

◆ REGEX_PHPDOC_CALLS

const ilCtrlStructureReader::REGEX_PHPDOC_CALLS = '/(((?i)@ilctrl_calls)\s*({CLASS_NAME}(:\s*|\s*:\s*))\K)([A-z0-9,\s])*/'
private

Definition at line 29 of file class.ilCtrlStructureReader.php.


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