ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 30 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 85 of file class.ilCtrlStructureReader.php.

References $cid_generator, and $iterator.

86  {
87  $this->ilias_path = rtrim(
88  (defined('ILIAS_ABSOLUTE_PATH')) ?
89  ILIAS_ABSOLUTE_PATH : dirname(__FILE__, 6),
90  '/'
91  );
92 
93  $this->cid_generator = $cid_generator;
94  $this->iterator = $iterator;
95  }
ilCtrlIteratorInterface $iterator
ilCtrlStructureCidGenerator $cid_generator

Member Function Documentation

◆ getChildren()

ilCtrlStructureReader::getChildren ( ReflectionClass  $reflection)
private

Helper function that returns all children references.

Parameters
ReflectionClass$reflection
Returns
array

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

References getReferencedClassesByReflection().

Referenced by readStructure().

224  : array
225  {
226  return $this->getReferencedClassesByReflection($reflection, self::REGEX_PHPDOC_CALLS);
227  }
getReferencedClassesByReflection(ReflectionClass $reflection, string $regex)
Returns all classes referenced by an ilCtrl_Calls or ilCtrl_isCalledBy statement. ...
+ 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 235 of file class.ilCtrlStructureReader.php.

References getReferencedClassesByReflection().

Referenced by readStructure().

235  : array
236  {
237  return $this->getReferencedClassesByReflection($reflection, self::REGEX_PHPDOC_CALLED_BYS);
238  }
getReferencedClassesByReflection(ReflectionClass $reflection, string $regex)
Returns all classes referenced by an ilCtrl_Calls or ilCtrl_isCalledBy statement. ...
+ 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 169 of file class.ilCtrlStructureReader.php.

References stripWhitespaces().

Referenced by getChildren(), and getParents().

169  : array
170  {
171  // abort if the class has no PHPDoc comment.
172  if (!$reflection->getDocComment()) {
173  return [];
174  }
175 
176  // replace the classname placeholder with the
177  // actual one and execute the regex search.
178  $name = str_replace('\\', '\\\\', $reflection->getName());
179  $regex = str_replace('{CLASS_NAME}', $name, $regex);
180  preg_match_all($regex, $reflection->getDocComment(), $matches);
181 
182  // the first array entry of $matches contains
183  // the list's of statements found.
184  if (empty($matches[0])) {
185  return [];
186  }
187 
188  $referenced_classes = [];
189  foreach ($matches[0] as $class_list) {
190  // explode lists and strip all whitespaces.
191  foreach (explode(',', $class_list) as $class) {
192  $class_name = $this->stripWhitespaces($class);
193  if (!empty($class_name)) {
194  $referenced_classes[] = strtolower($class_name);
195  }
196  }
197  }
198 
199  return $referenced_classes;
200  }
stripWhitespaces(string $string)
Helper function that replaces all whitespace characters from the given string.
+ 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 208 of file class.ilCtrlStructureReader.php.

Referenced by readStructure().

208  : string
209  {
210  // some paths might contain syntax like '../../../' etc.
211  // and realpath() resolves that in order to cut off the
212  // ilias installation path properly.
213  $absolute_path = realpath($absolute_path);
214 
215  return '.' . str_replace($this->ilias_path, '', $absolute_path);
216  }
+ 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 102 of file class.ilCtrlStructureReader.php.

References $is_executed.

102  : bool
103  {
104  return $this->is_executed;
105  }

◆ isGuiClass()

ilCtrlStructureReader::isGuiClass ( string  $path)
private

Returns whether the given file/path matches ILIAS conventions.

Parameters
string$path
Returns
bool

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

Referenced by readStructure().

258  : bool
259  {
260  return (bool) preg_match(self::REGEX_GUI_CLASS_NAME, basename($path));
261  }
$path
Definition: ltiservices.php:29
+ 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 269 of file class.ilCtrlStructureReader.php.

Referenced by readStructure().

269  : bool
270  {
271  return (false !== strpos($class_name, '\\'));
272  }
+ Here is the caller graph for this function:

◆ readStructure()

ilCtrlStructureReader::readStructure ( )

Processes all classes within the ILIAS installation.

Returns
array

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

References Vendor\Package\$e, $path, $structure, 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.

112  : array
113  {
114  $base_classes = $structure = [];
115  foreach ($this->iterator as $class_name => $path) {
116  // skip iteration if class doesn't meet ILIAS GUI class criteria.
117  if (!$this->isGuiClass($path)) {
118  continue;
119  }
120 
121  $lower_class_name = strtolower($class_name);
122  try {
123  // the classes need to be required manually, because
124  // the autoload classmap might not include the plugin
125  // classes when an update is triggered (small structure
126  // reload).
127  require_once $path;
128 
129  $reflection = ($this->isNamespaced($class_name)) ?
130  new ReflectionClass("\\$class_name") :
131  new ReflectionClass($class_name)
132  ;
133 
134  $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_CID] = $this->cid_generator->getCid();
135  $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_NAME] = $class_name;
136  $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_PATH] = $this->getRelativePath($path);
137  $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_CHILDREN] = $this->getChildren($reflection);
138  $structure[$lower_class_name][ilCtrlStructureInterface::KEY_CLASS_PARENTS] = $this->getParents($reflection);
139 
140  // temporarily store base classes in order to filer the
141  // structure afterwards.
142  if (in_array(ilCtrlBaseClassInterface::class, $reflection->getInterfaceNames(), true)) {
143  $base_classes[] = $lower_class_name;
144  }
145  } catch (ReflectionException $e) {
146  continue;
147  }
148  }
149 
150  $mapped_structure = (new ilCtrlStructureHelper($base_classes, $structure))
151  ->mapStructureReferences()
152  ->filterUnnecessaryEntries()
153  ->getStructure()
154  ;
155 
156  $this->is_executed = true;
157 
158  return $mapped_structure;
159  }
Class ilCtrlStructureHelper.
isNamespaced(string $class_name)
Returns if the given classname is namespaced.
getChildren(ReflectionClass $reflection)
Helper function that returns all children references.
$path
Definition: ltiservices.php:29
const KEY_CLASS_CID
array key constants that are used for certain information.
getRelativePath(string $absolute_path)
Returns a given path relative to the ILIAS absolute path.
$structure
TOTAL STRUCTURE.
getParents(ReflectionClass $reflection)
Helper function that returns all parent references.
isGuiClass(string $path)
Returns whether the given file/path matches ILIAS conventions.
+ 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 247 of file class.ilCtrlStructureReader.php.

Referenced by getReferencedClassesByReflection().

247  : string
248  {
249  return (string) preg_replace('/\s+/', '', $string);
250  }
+ Here is the caller graph for this function:

Field Documentation

◆ $cid_generator

ilCtrlStructureCidGenerator ilCtrlStructureReader::$cid_generator
private

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

Referenced by __construct().

◆ $ilias_path

string ilCtrlStructureReader::$ilias_path
private

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

◆ $is_executed

bool ilCtrlStructureReader::$is_executed = false
private

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

Referenced by isExecuted().

◆ $iterator

ilCtrlIteratorInterface ilCtrlStructureReader::$iterator
private

Definition at line 63 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 36 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 49 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 43 of file class.ilCtrlStructureReader.php.


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