ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilComponentDefinitionReader Class Reference
+ Collaboration diagram for ilComponentDefinitionReader:

Public Member Functions

 __construct (ilComponentDefinitionProcessor ... $processor)
 
 purge ()
 This methods is supposed to purge existing data in the registered processor. More...
 
 readComponentDefinitions ()
 This reads the component.xml of all components in the core and processes them with the provided processor. More...
 
 beginTag ($_, string $name, array $attributes)
 
 endTag ($_, string $name)
 

Protected Member Functions

 readFile (string $path)
 
 parseComponentXML (string $type, string $component, string $xml)
 
 getComponents ()
 
 getComponentInfo (string $type, string $name)
 
 getComponentPaths (string $root, string $name)
 

Protected Attributes

array $processors
 

Detailed Description

Definition at line 21 of file class.ilComponentDefinitionReader.php.

Constructor & Destructor Documentation

◆ __construct()

ilComponentDefinitionReader::__construct ( ilComponentDefinitionProcessor ...  $processor)

Definition at line 28 of file class.ilComponentDefinitionReader.php.

30  {
31  $this->processors = $processor;
32  }

Member Function Documentation

◆ beginTag()

ilComponentDefinitionReader::beginTag (   $_,
string  $name,
array  $attributes 
)

Definition at line 97 of file class.ilComponentDefinitionReader.php.

97  : void
98  {
99  foreach ($this->processors as $processor) {
100  $processor->beginTag($name, $attributes);
101  }
102  }
$attributes
Definition: metadata.php:248
if($format !==null) $name
Definition: metadata.php:247

◆ endTag()

ilComponentDefinitionReader::endTag (   $_,
string  $name 
)

Definition at line 104 of file class.ilComponentDefinitionReader.php.

104  : void
105  {
106  foreach ($this->processors as $processor) {
107  $processor->endTag($name);
108  }
109  }
if($format !==null) $name
Definition: metadata.php:247

◆ getComponentInfo()

ilComponentDefinitionReader::getComponentInfo ( string  $type,
string  $name 
)
protected
Returns
Iterator<array>

Definition at line 127 of file class.ilComponentDefinitionReader.php.

References $c, $type, and getComponentPaths().

Referenced by getComponents().

127  : \Iterator
128  {
129  $dir = __DIR__ . "/../../../" . $type;
130  foreach ($this->getComponentPaths($dir, $name) as $c) {
131  yield [
132  $type,
133  $c,
134  realpath($dir . "/" . $c . "/" . $name)
135  ];
136  }
137  }
$c
Definition: cli.php:38
$type
if($format !==null) $name
Definition: metadata.php:247
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getComponentPaths()

ilComponentDefinitionReader::getComponentPaths ( string  $root,
string  $name 
)
protected
Returns
Iterator<string>

Definition at line 142 of file class.ilComponentDefinitionReader.php.

Referenced by getComponentInfo().

142  : \Iterator
143  {
144  $dir = opendir($root);
145  while ($sub = readdir($dir)) {
146  if ($sub === "." || $sub === "..") {
147  continue;
148  }
149  if (!is_dir($root . "/" . $sub)) {
150  continue;
151  }
152  if (!is_file($root . "/" . $sub . "/" . $name)) {
153  continue;
154  }
155  yield $sub;
156  }
157  }
if($format !==null) $name
Definition: metadata.php:247
+ Here is the caller graph for this function:

◆ getComponents()

ilComponentDefinitionReader::getComponents ( )
protected
Returns
Iterator<string>

Definition at line 114 of file class.ilComponentDefinitionReader.php.

References $i, and getComponentInfo().

Referenced by readComponentDefinitions().

114  : \Iterator
115  {
116  foreach ($this->getComponentInfo("Modules", "module.xml") as $i) {
117  yield $i;
118  }
119  foreach ($this->getComponentInfo("Services", "service.xml") as $i) {
120  yield $i;
121  }
122  }
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseComponentXML()

ilComponentDefinitionReader::parseComponentXML ( string  $type,
string  $component,
string  $xml 
)
protected

Definition at line 73 of file class.ilComponentDefinitionReader.php.

Referenced by readComponentDefinitions().

73  : void
74  {
75  $xml_parser = null;
76  try {
77  $xml_parser = xml_parser_create("UTF-8");
78  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
79  xml_set_object($xml_parser, $this);
80  xml_set_element_handler($xml_parser, 'beginTag', 'endTag');
81  if (!xml_parse($xml_parser, $xml)) {
82  $code = xml_get_error_code($xml_parser);
83  $line = xml_get_current_line_number($xml_parser);
84  $col = xml_get_current_column_number($xml_parser);
85  $msg = xml_error_string($code);
86  throw new \InvalidArgumentException(
87  "Error $code component xml of $type/$component, on line $line in column $col: $msg"
88  );
89  }
90  } finally {
91  if ($xml_parser) {
92  xml_parser_free($xml_parser);
93  }
94  }
95  }
$xml
Definition: metadata.php:351
+ Here is the caller graph for this function:

◆ purge()

ilComponentDefinitionReader::purge ( )

This methods is supposed to purge existing data in the registered processor.

Definition at line 38 of file class.ilComponentDefinitionReader.php.

38  : void
39  {
40  foreach ($this->processors as $p) {
41  $p->purge();
42  }
43  }

◆ readComponentDefinitions()

ilComponentDefinitionReader::readComponentDefinitions ( )

This reads the component.xml of all components in the core and processes them with the provided processor.

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

References $path, $type, getComponents(), parseComponentXML(), and readFile().

49  : void
50  {
51  foreach ($this->getComponents() as [$type, $component, $path]) {
52  $file = $this->readFile($path);
53  foreach ($this->processors as $processor) {
54  $processor->beginComponent($component, $type);
55  }
56  $this->parseComponentXML($type, $component, $file);
57  foreach ($this->processors as $processor) {
58  $processor->endComponent($component, $type);
59  }
60  }
61  }
$type
parseComponentXML(string $type, string $component, string $xml)
$path
Definition: ltiservices.php:32
+ Here is the call graph for this function:

◆ readFile()

ilComponentDefinitionReader::readFile ( string  $path)
protected

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

Referenced by readComponentDefinitions().

63  : string
64  {
65  if (!file_exists($path)) {
66  throw new \InvalidArgumentException(
67  "Cannot find file $path."
68  );
69  }
70  return file_get_contents($path);
71  }
$path
Definition: ltiservices.php:32
+ Here is the caller graph for this function:

Field Documentation

◆ $processors

array ilComponentDefinitionReader::$processors
protected

Definition at line 26 of file class.ilComponentDefinitionReader.php.


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