ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 89 of file class.ilComponentDefinitionReader.php.

89 : void
90 {
91 foreach ($this->processors as $processor) {
92 $processor->beginTag($name, $attributes);
93 }
94 }

Referenced by parseComponentXML().

+ Here is the caller graph for this function:

◆ endTag()

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

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

96 : void
97 {
98 foreach ($this->processors as $processor) {
99 $processor->endTag($name);
100 }
101 }

Referenced by parseComponentXML().

+ Here is the caller graph for this function:

◆ getComponentInfo()

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

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

125 : \Iterator
126 {
127 $dir = __DIR__ . "/../../../../" . $type;
128 foreach ($this->getComponentPaths($dir, $name) as $c) {
129 yield [
130 $type,
131 $c,
132 realpath($dir . "/" . $c . "/" . $name)
133 ];
134 }
135 }
$c
Definition: deliver.php:25

References $c, and getComponentPaths().

Referenced by getComponents().

+ 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 140 of file class.ilComponentDefinitionReader.php.

140 : \Iterator
141 {
142 $dir = opendir($root);
143 while ($sub = readdir($dir)) {
144 if ($sub === "." || $sub === "..") {
145 continue;
146 }
147 if (!is_dir($root . "/" . $sub)) {
148 continue;
149 }
150 if (!is_file($root . "/" . $sub . "/" . $name)) {
151 continue;
152 }
153 yield $sub;
154 }
155 }

Referenced by getComponentInfo().

+ Here is the caller graph for this function:

◆ getComponents()

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

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

106 : \Iterator
107 {
108 foreach (glob("components/*") as $component_namespace) {
109 $short_namespace = basename($component_namespace);
110 foreach ($this->getComponentInfo("components/" . $short_namespace, "module.xml") as $i) {
111 yield $i;
112 }
113 foreach ($this->getComponentInfo("components/" . $short_namespace, "service.xml") as $i) {
114 yield $i;
115 }
116 foreach ($this->getComponentInfo("components/" . $short_namespace, "component.xml") as $i) {
117 yield $i;
118 }
119 }
120 }

References getComponentInfo().

Referenced by readComponentDefinitions().

+ 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.

73 : void
74 {
75 $xml_parser = xml_parser_create("UTF-8");
76 xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
77 xml_set_element_handler($xml_parser, $this->beginTag(...), $this->endTag(...));
78 if (!xml_parse($xml_parser, $xml)) {
79 $code = xml_get_error_code($xml_parser);
80 $line = xml_get_current_line_number($xml_parser);
81 $col = xml_get_current_column_number($xml_parser);
82 $msg = xml_error_string($code);
83 throw new \InvalidArgumentException(
84 "Error $code component xml of $type/$component, on line $line in column $col: $msg"
85 );
86 }
87 }
beginTag($_, string $name, array $attributes)

References beginTag(), and endTag().

Referenced by readComponentDefinitions().

+ Here is the call graph for this function:
+ 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.

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 }
parseComponentXML(string $type, string $component, string $xml)
$path
Definition: ltiservices.php:30

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

+ Here is the call graph for this function:

◆ readFile()

ilComponentDefinitionReader::readFile ( string  $path)
protected

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

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 }

References $path.

Referenced by readComponentDefinitions().

+ 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: