ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCtrlStructureReader Class Reference

Class ilCtrlStructureReader. More...

+ Collaboration diagram for ilCtrlStructureReader:

Public Member Functions

 __construct ($a_ini_file=null)
 
 setIniFile ($a_ini_file)
 
 getStructure ()
 parse code files and store call structure in db More...
 
 readStructure ( $a_force=false, $a_dir="", $a_comp_prefix="", $a_plugin_path="")
 
 withDB (\ilDBInterface $db)
 

Data Fields

 $executed
 
 $db = null
 
const INTERESTING_FILES_REGEXP = "~^(class\..*\.php)$~i"
 
const GUI_CLASS_FILE_REGEXP = "~^.*[/\\\\]class\.(.*GUI)\.php$~i"
 
const IL_CTRL_DECLARATION_REGEXP = '~^.*@{WHICH}\s+([\w\\\\]+)\s*:\s*([\w\\\\]+(\s*,\s*[\w\\\\]+)*)\s*$~mi'
 

Protected Member Functions

 flushCaches ()
 
 readDirTo (string $a_cdir, \ilCtrlStructure $cs)
 
 getFilesIn (string $dir)
 
 shouldDescendToDirectory (string $dir)
 
 normalizePath (string $path)
 
 isInterestingFile (string $file)
 
 panicOnDuplicateClass (string $full_path, string $other_path, string $parent)
 
 storeToDB (\ilCtrlStructure $ctrl_structure, string $start_dir)
 
 setClassFileIdsInDB ()
 
 parseFileTo (\ilCtrlStructure $cs, string $full_path, string $content)
 
 getGUIClassNameFromClassPath (string $path)
 
 containsClassDefinitionFor (string $class, string $content)
 
 getIlCtrlCalls (string $content)
 
 getIlCtrlIsCalledBy (string $content)
 
 getIlCtrlDeclarations (string $content, string $which)
 
 getDB ()
 
 getILIASAbsolutePath ()
 

Protected Attributes

 $read_plugins = false
 

Detailed Description

Class ilCtrlStructureReader.

Reads call structure of classes into db

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilCtrlStructureReader::__construct (   $a_ini_file = null)

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

20  {
21  $this->class_script = array();
22  $this->class_childs = array();
23  $this->executed = false;
24  $this->ini = $a_ini_file;
25  }

Member Function Documentation

◆ containsClassDefinitionFor()

ilCtrlStructureReader::containsClassDefinitionFor ( string  $class,
string  $content 
)
protected

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

Referenced by parseFileTo().

356  : bool
357  {
358  $regexp = "~.*class\s+$class~mi";
359  return preg_match($regexp, $content) != 0;
360  }
+ Here is the caller graph for this function:

◆ flushCaches()

ilCtrlStructureReader::flushCaches ( )
protected

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

References ilCachedCtrl\flush().

Referenced by readStructure().

96  : void
97  {
99  ilGlobalCache::flushAll();
100  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDB()

ilCtrlStructureReader::getDB ( )
protected

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

References $db, and $ilDB.

Referenced by getStructure(), panicOnDuplicateClass(), readStructure(), setClassFileIdsInDB(), and storeToDB().

426  {
427  if (!is_null($this->db)) {
428  return $this->db;
429  }
430  //return ilDB in any case - backward compat.
431  global $ilDB;
432  return $ilDB;
433  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $ilDB
+ Here is the caller graph for this function:

◆ getFilesIn()

ilCtrlStructureReader::getFilesIn ( string  $dir)
protected

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

References Vendor\Package\$e, Vendor\Package\$f, normalizePath(), and shouldDescendToDirectory().

Referenced by readDirTo().

139  : \Generator
140  {
141  foreach (scandir($dir) as $e) {
142  if ($e == "." || $e == "..") {
143  continue;
144  }
145  $f = $this->normalizePath("$dir/$e");
146  if (@is_dir($f)) {
147  if (!$this->shouldDescendToDirectory($dir)) {
148  continue;
149  }
150  foreach ($this->getFilesIn($f) as $s) {
151  yield $s;
152  }
153  }
154  if (@is_file($f)) {
155  yield [$e, $f];
156  }
157  }
158  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGUIClassNameFromClassPath()

ilCtrlStructureReader::getGUIClassNameFromClassPath ( string  $path)
protected

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

References $res.

Referenced by parseFileTo().

347  : ?string
348  {
349  $res = [];
350  if (preg_match(self::GUI_CLASS_FILE_REGEXP, $path, $res)) {
351  return strtolower($res[1]);
352  }
353  return null;
354  }
foreach($_POST as $key=> $value) $res
+ Here is the caller graph for this function:

◆ getIlCtrlCalls()

ilCtrlStructureReader::getIlCtrlCalls ( string  $content)
protected
Returns
null|(string,string[])

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

References getIlCtrlDeclarations().

Referenced by parseFileTo().

372  : ?array
373  {
374  return $this->getIlCtrlDeclarations($content, "ilctrl_calls");
375  }
getIlCtrlDeclarations(string $content, string $which)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIlCtrlDeclarations()

ilCtrlStructureReader::getIlCtrlDeclarations ( string  $content,
string  $which 
)
protected
Returns
null|(string,string[])

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

References $res.

Referenced by getIlCtrlCalls(), and getIlCtrlIsCalledBy().

388  : ?array
389  {
390  $regexp = str_replace("{WHICH}", $which, self::IL_CTRL_DECLARATION_REGEXP);
391  $res = [];
392  if (!preg_match_all($regexp, $content, $res)) {
393  return null;
394  }
395 
396  $class_names = array_unique($res[1]);
397  if (count($class_names) != 1) {
398  throw new \LogicException(
399  "Found different class names in ilctrl_calls: " . join(",", $class_names)
400  );
401  }
402 
403  $declaration = [];
404  foreach ($res[2] as $ls) {
405  foreach (explode(",", $ls) as $l) {
406  $declaration[] = strtolower(trim($l));
407  }
408  }
409 
410  return [strtolower(trim($class_names[0])), $declaration];
411  }
foreach($_POST as $key=> $value) $res
+ Here is the caller graph for this function:

◆ getIlCtrlIsCalledBy()

ilCtrlStructureReader::getIlCtrlIsCalledBy ( string  $content)
protected
Returns
null|(string,string[])

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

References getIlCtrlDeclarations().

Referenced by parseFileTo().

380  : ?array
381  {
382  return $this->getIlCtrlDeclarations($content, "ilctrl_iscalledby");
383  }
getIlCtrlDeclarations(string $content, string $which)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getILIASAbsolutePath()

ilCtrlStructureReader::getILIASAbsolutePath ( )
protected

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

References normalizePath().

Referenced by readStructure(), and shouldDescendToDirectory().

435  : string
436  {
437  if (defined("ILIAS_ABSOLUTE_PATH")) {
438  return $this->normalizePath(ILIAS_ABSOLUTE_PATH);
439  } else {
440  return dirname(__FILE__, 5);
441  }
442  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStructure()

ilCtrlStructureReader::getStructure ( )

parse code files and store call structure in db

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

References $ilDB, and getDB().

36  {
37  $ilDB = $this->getDB();
38 
39  $this->ini->setVariable("db", "structure_reload", "1");
40  $this->ini->write();
41  if ($this->ini->readVariable("db", "structure_reload") != "1") {
42  echo "Error Cannot write client.ini.file.";
43  }
44  //$this->get_structure = true;
45  }
global $ilDB
+ Here is the call graph for this function:

◆ isInterestingFile()

ilCtrlStructureReader::isInterestingFile ( string  $file)
protected

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

Referenced by readDirTo().

180  : bool
181  {
182  return preg_match(self::INTERESTING_FILES_REGEXP, $file);
183  }
+ Here is the caller graph for this function:

◆ normalizePath()

ilCtrlStructureReader::normalizePath ( string  $path)
protected

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

Referenced by getFilesIn(), getILIASAbsolutePath(), and shouldDescendToDirectory().

173  : string
174  {
175  return realpath(str_replace(['//'], ['/'], $path));
176  }
+ Here is the caller graph for this function:

◆ panicOnDuplicateClass()

ilCtrlStructureReader::panicOnDuplicateClass ( string  $full_path,
string  $other_path,
string  $parent 
)
protected

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

References $ilDB, and getDB().

Referenced by readDirTo().

190  : void
191  {
192  $ilDB = $this->getDB();
193 
194  // delete all class to file assignments
195  $ilDB->manipulate("DELETE FROM ctrl_classfile WHERE comp_prefix = " .
196  $ilDB->quote($this->comp_prefix, "text"));
197  if ($this->comp_prefix == "") {
198  $ilDB->manipulate($q = "DELETE FROM ctrl_classfile WHERE " .
199  $ilDB->equals("comp_prefix", "", "text", true));
200  }
201 
202  // delete all call entries
203  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix = " .
204  $ilDB->quote($this->comp_prefix, "text"));
205  if ($this->comp_prefix == "") {
206  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix IS NULL");
207  }
208 
209  $msg = implode("\n", [
210  "Error: Duplicate call structure definition found (Class %s) in files:",
211  "- %s",
212  "- %s",
213  "",
214  "Please remove the file, that does not belong to the official ILIAS distribution.",
215  "After that invoke 'Tools' -> 'Reload Control Structure' in the ILIAS Setup."
216  ]);
217 
218  throw new \Exception(
219  sprintf(
220  $msg,
221  $parent,
222  $other_path,
223  $full_path
224  )
225  );
226  }
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseFileTo()

ilCtrlStructureReader::parseFileTo ( \ilCtrlStructure  $cs,
string  $full_path,
string  $content 
)
protected
Exceptions

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

References containsClassDefinitionFor(), getGUIClassNameFromClassPath(), getIlCtrlCalls(), getIlCtrlIsCalledBy(), ilCtrlStructure\withClassChild(), and ilCtrlStructure\withClassScript().

Referenced by readDirTo().

312  {
313  list($parent, $children) = $this->getIlCtrlCalls($content);
314  if ($parent) {
315  $cs = $cs->withClassScript($parent, $full_path);
316  }
317  if ($children) {
318  foreach ($children as $child) {
319  $cs = $cs->withClassChild($parent, $child);
320  }
321  }
322 
323  list($child, $parents) = $this->getIlCtrlIsCalledBy($content);
324  if ($child) {
325  $cs = $cs->withClassScript($child, $full_path);
326  }
327  if ($parents) {
328  foreach ($parents as $parent) {
329  $cs = $cs->withClassChild($parent, $child);
330  }
331  }
332 
333  $cl = $this->getGUIClassNameFromClassPath($full_path);
334  if ($cl && $this->containsClassDefinitionFor($cl, $content)) {
335  $cs = $cs->withClassScript($cl, $full_path);
336  }
337 
338  return $cs;
339  }
The CtrlStructure knows how GUIs call each other and where the code of the guis is located...
containsClassDefinitionFor(string $class, string $content)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readDirTo()

ilCtrlStructureReader::readDirTo ( string  $a_cdir,
\ilCtrlStructure  $cs 
)
protected

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

References Vendor\Package\$e, ilCtrlStructure\getClassScriptOf(), getFilesIn(), isInterestingFile(), panicOnDuplicateClass(), and parseFileTo().

Referenced by readStructure().

103  {
104  // check wether $a_cdir is a directory
105  if (!@is_dir($a_cdir)) {
106  throw new \LogicException("'$a_cdir' is not a directory.");
107  }
108 
109  foreach ($this->getFilesIn($a_cdir) as list($file, $full_path)) {
110  if (!$this->isInterestingFile($file)) {
111  continue;
112  }
113 
114  $content = file_get_contents($full_path);
115  try {
116  $cs = $this->parseFileTo($cs, $full_path, $content);
117  } catch (\LogicException $e) {
118  throw new \LogicException("In file \"$full_path\": " . $e->getMessage(), $e->getCode(), $e);
119  } catch (\RuntimeException $e) {
120  if (!isset($e->class) || !isset($e->file_path)) {
121  throw $e;
122  }
123  $this->panicOnDuplicateClass(
124  $e->file_path,
125  $cs->getClassScriptOf($e->class),
126  $e->class
127  );
128  }
129  }
130 
131  return $cs;
132  }
The CtrlStructure knows how GUIs call each other and where the code of the guis is located...
panicOnDuplicateClass(string $full_path, string $other_path, string $parent)
parseFileTo(\ilCtrlStructure $cs, string $full_path, string $content)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readStructure()

ilCtrlStructureReader::readStructure (   $a_force = false,
  $a_dir = "",
  $a_comp_prefix = "",
  $a_plugin_path = "" 
)

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

References $ilDB, flushCaches(), getDB(), getILIASAbsolutePath(), readDirTo(), setClassFileIdsInDB(), and storeToDB().

57  : void {
58  $ilDB = $this->getDB();
59 
60  if (!$a_force && $this->ini->readVariable("db", "structure_reload") != "1") {
61  return;
62  }
63 
64  // only run one time per db_update request
65  if ($this->executed) {
66  return;
67  }
68 
69  $this->flushCaches();
70 
71  // prefix for component
72  $this->comp_prefix = $a_comp_prefix;
73 
74  // plugin path
75  $this->plugin_path = $a_plugin_path;
76 
77  if ($this->plugin_path != "" && $this->comp_prefix != "") {
78  $this->read_plugins = true;
79  }
80 
81  if ($a_dir == "") {
82  $a_dir = $this->getILIASAbsolutePath();
83  }
84 
85  $ctrl_structure = $this->readDirTo($a_dir, new \ilCtrlStructure());
86  $this->storeToDB($ctrl_structure, $a_dir);
87  $this->setClassFileIdsInDB();
88 
89  $this->executed = true;
90  if (!$a_force) {
91  $this->ini->setVariable("db", "structure_reload", "0");
92  $this->ini->write();
93  }
94  }
The CtrlStructure knows how GUIs call each other and where the code of the guis is located...
readDirTo(string $a_cdir, \ilCtrlStructure $cs)
storeToDB(\ilCtrlStructure $ctrl_structure, string $start_dir)
global $ilDB
+ Here is the call graph for this function:

◆ setClassFileIdsInDB()

ilCtrlStructureReader::setClassFileIdsInDB ( )
protected

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

References $ilDB, and getDB().

Referenced by readStructure().

281  : void
282  {
283  $ilDB = $this->getDB();
284 
285  $ilDB->manipulate(
286  "UPDATE ctrl_classfile SET " .
287  " cid = " . $ilDB->quote("", "text")
288  );
289  $set = $ilDB->query("SELECT * FROM ctrl_classfile ");
290  $cnt = 1;
291  while ($rec = $ilDB->fetchAssoc($set)) {
292  $cid = base_convert((string) $cnt, 10, 36);
293  $ilDB->manipulate(
294  "UPDATE ctrl_classfile SET " .
295  " cid = " . $ilDB->quote($cid, "text") .
296  " WHERE class = " . $ilDB->quote($rec["class"], "text")
297  );
298  $cnt++;
299  }
300  }
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setIniFile()

ilCtrlStructureReader::setIniFile (   $a_ini_file)

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

28  {
29  $this->ini = $a_ini_file;
30  }

◆ shouldDescendToDirectory()

ilCtrlStructureReader::shouldDescendToDirectory ( string  $dir)
protected

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

References getILIASAbsolutePath(), and normalizePath().

Referenced by getFilesIn().

160  : bool
161  {
162  $il_absolute_path = $this->getILIASAbsolutePath();
163  $data_dir = $this->normalizePath($il_absolute_path . "/data");
164  $customizing_dir = $this->normalizePath($il_absolute_path . "/Customizing");
165 
166  $dir = $this->normalizePath($dir);
167  if ($this->read_plugins) {
168  return $dir != $data_dir;
169  }
170  return $dir != $customizing_dir && $dir != $data_dir;
171  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ storeToDB()

ilCtrlStructureReader::storeToDB ( \ilCtrlStructure  $ctrl_structure,
string  $start_dir 
)
protected

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

References $ilDB, ilCtrlStructure\getClassChildren(), ilCtrlStructure\getClassScripts(), and getDB().

Referenced by readStructure().

228  : void
229  {
230  $ilDB = $this->getDB();
231 
232  // delete all class to file assignments
233  $ilDB->manipulate("DELETE FROM ctrl_classfile WHERE comp_prefix = " .
234  $ilDB->quote($this->comp_prefix, "text"));
235  if ($this->comp_prefix == "") {
236  $ilDB->manipulate($q = "DELETE FROM ctrl_classfile WHERE " .
237  $ilDB->equals("comp_prefix", "", "text", true));
238  }
239 
240  // delete all call entries
241  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix = " .
242  $ilDB->quote($this->comp_prefix, "text"));
243  if ($this->comp_prefix == "") {
244  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE " .
245  $ilDB->equals("comp_prefix", "", "text", true));
246  }
247 
248  foreach ($ctrl_structure->getClassScripts() as $class => $script) {
249  $file = substr(realpath($script), strlen(realpath($start_dir)) + 1);
250  // store class to file assignment
251  $ilDB->manipulate(sprintf(
252  "INSERT IGNORE INTO ctrl_classfile (class, filename, comp_prefix, plugin_path) " .
253  " VALUES (%s,%s,%s,%s)",
254  $ilDB->quote($class, "text"),
255  $ilDB->quote($file, "text"),
256  $ilDB->quote($this->comp_prefix, "text"),
257  $ilDB->quote($this->plugin_path, "text")
258  ));
259  }
260  //$this->class_childs[$parent][] = $child;
261  foreach ($ctrl_structure->getClassChildren() as $parent => $children) {
262  if (!strlen($parent)) {
263  continue;
264  }
265  foreach ($children as $child) {
266  if (!strlen(trim($child))) {
267  continue;
268  }
269  // store call entry
270  $ilDB->manipulate(sprintf(
271  "INSERT IGNORE INTO ctrl_calls (parent, child, comp_prefix) " .
272  "VALUES (%s,%s,%s)",
273  $ilDB->quote($parent, "text"),
274  $ilDB->quote($child, "text"),
275  $ilDB->quote($this->comp_prefix, "text")
276  ));
277  }
278  }
279  }
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withDB()

ilCtrlStructureReader::withDB ( \ilDBInterface  $db)

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

References $db.

419  {
420  $clone = clone $this;
421  $clone->db = $db;
422  return $clone;
423  }

Field Documentation

◆ $db

ilCtrlStructureReader::$db = null

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

Referenced by getDB(), and withDB().

◆ $executed

ilCtrlStructureReader::$executed

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

◆ $read_plugins

ilCtrlStructureReader::$read_plugins = false
protected

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

◆ GUI_CLASS_FILE_REGEXP

const ilCtrlStructureReader::GUI_CLASS_FILE_REGEXP = "~^.*[/\\\\]class\.(.*GUI)\.php$~i"

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

◆ IL_CTRL_DECLARATION_REGEXP

const ilCtrlStructureReader::IL_CTRL_DECLARATION_REGEXP = '~^.*@{WHICH}\s+([\w\\\\]+)\s*:\s*([\w\\\\]+(\s*,\s*[\w\\\\]+)*)\s*$~mi'

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

◆ INTERESTING_FILES_REGEXP

const ilCtrlStructureReader::INTERESTING_FILES_REGEXP = "~^(class\..*\.php)$~i"

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


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