ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\Setup\ImplementationOfAgentFinder Class Reference
+ Inheritance diagram for ILIAS\Setup\ImplementationOfAgentFinder:
+ Collaboration diagram for ILIAS\Setup\ImplementationOfAgentFinder:

Public Member Functions

 __construct (protected Refinery $refinery, protected Data\Factory $data_factory, protected \ILIAS\Language\Language $lng, protected ImplementationOfInterfaceFinder $interface_finder, $component_agents)
 
 getAgents ()
 Collect all agents from the system, core and plugin, bundled in a collection. More...
 
 getComponentAgents ()
 Collect core agents from the system bundled in a collection. More...
 
 getPluginAgent (string $name)
 Get a agent from a specific plugin. More...
 
 getAgentByClassName (string $class_name)
 Get an agent by class name. More...
 
 getAgentNameByClassName (string $class_name)
 Derive a name for the agent based on a class name. More...
 

Protected Member Functions

 getPluginNames ()
 

Protected Attributes

array AgentCollection $component_agents
 

Detailed Description

Definition at line 26 of file ImplementationOfAgentFinder.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Setup\ImplementationOfAgentFinder::__construct ( protected Refinery  $refinery,
protected Data\Factory  $data_factory,
protected \ILIAS\Language\Language  $lng,
protected ImplementationOfInterfaceFinder  $interface_finder,
  $component_agents 
)

Definition at line 30 of file ImplementationOfAgentFinder.php.

References ILIAS\Setup\ImplementationOfAgentFinder\$component_agents.

36  {
37  $this->component_agents = $component_agents;
38  }

Member Function Documentation

◆ getAgentByClassName()

ILIAS\Setup\ImplementationOfAgentFinder::getAgentByClassName ( string  $class_name)

Get an agent by class name.

Throws an exception if the class doesn't exists.

Parameters
string$class_name
Returns
AgentCollection
Exceptions

Implements ILIAS\Setup\AgentFinder.

Definition at line 129 of file ImplementationOfAgentFinder.php.

References ILIAS\Repository\lng(), and ILIAS\Repository\refinery().

129  : Agent
130  {
131  if (!class_exists($class_name)) {
132  throw new \InvalidArgumentException("Class '" . $class_name . "' not found.");
133  }
134 
135  return new $class_name(
136  $this->refinery,
137  $this->data_factory,
138  $this->lng
139  );
140  }
+ Here is the call graph for this function:

◆ getAgentNameByClassName()

ILIAS\Setup\ImplementationOfAgentFinder::getAgentNameByClassName ( string  $class_name)

Derive a name for the agent based on a class name.

Implements ILIAS\Setup\AgentFinder.

Definition at line 145 of file ImplementationOfAgentFinder.php.

Referenced by ILIAS\Setup\ImplementationOfAgentFinder\getComponentAgents().

145  : string
146  {
147  // We assume that the name of an agent in the class ilXYZSetupAgent really
148  // is XYZ. If that does not fit we just use the class name.
149  $match = [];
150  if (preg_match("/il(\w+)SetupAgent/", $class_name, $match)) {
151  return strtolower($match[1]);
152  }
153  return $class_name;
154  }
+ Here is the caller graph for this function:

◆ getAgents()

ILIAS\Setup\ImplementationOfAgentFinder::getAgents ( )

Collect all agents from the system, core and plugin, bundled in a collection.

Parameters
string[]$ignore folders to be ignored.

Implements ILIAS\Setup\AgentFinder.

Definition at line 45 of file ImplementationOfAgentFinder.php.

References ILIAS\Setup\ImplementationOfAgentFinder\getComponentAgents(), ILIAS\Setup\ImplementationOfAgentFinder\getPluginAgent(), and ILIAS\Setup\ImplementationOfAgentFinder\getPluginNames().

45  : AgentCollection
46  {
47  $agents = $this->getComponentAgents();
48 
49  // Get a list of existing plugins in the system.
50  $plugins = $this->getPluginNames();
51 
52  foreach ($plugins as $plugin_name) {
53  $agents = $agents->withAdditionalAgent(
54  $plugin_name,
55  $this->getPluginAgent($plugin_name)
56  );
57  }
58 
59  return $agents;
60  }
getPluginAgent(string $name)
Get a agent from a specific plugin.
getComponentAgents()
Collect core agents from the system bundled in a collection.
+ Here is the call graph for this function:

◆ getComponentAgents()

ILIAS\Setup\ImplementationOfAgentFinder::getComponentAgents ( )

Collect core agents from the system bundled in a collection.

Implements ILIAS\Setup\AgentFinder.

Definition at line 66 of file ImplementationOfAgentFinder.php.

References ILIAS\Setup\ImplementationOfAgentFinder\$component_agents, ILIAS\Setup\ImplementationOfAgentFinder\getAgentNameByClassName(), and ILIAS\Repository\refinery().

Referenced by ILIAS\Setup\ImplementationOfAgentFinder\getAgents().

66  : AgentCollection
67  {
68  if ($this->component_agents instanceof AgentCollection) {
70  }
71 
72  $agents = new AgentCollection($this->refinery, []);
73 
74  foreach ($this->component_agents as $agent) {
75  $agents = $agents->withAdditionalAgent(
76  $this->getAgentNameByClassName(get_class($agent)),
77  $agent
78  );
79  }
80 
81  $this->component_agents = $agents;
83  }
getAgentNameByClassName(string $class_name)
Derive a name for the agent based on a class name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPluginAgent()

ILIAS\Setup\ImplementationOfAgentFinder::getPluginAgent ( string  $name)

Get a agent from a specific plugin.

If there is no plugin agent, this would the default agent. If the plugin contains multiple agents, these will be collected.

Parameters
string$nameof the plugin to get the agent from

Implements ILIAS\Setup\AgentFinder.

Definition at line 93 of file ImplementationOfAgentFinder.php.

References $path, ILIAS\Repository\lng(), and ILIAS\Repository\refinery().

Referenced by ILIAS\Setup\ImplementationOfAgentFinder\getAgents().

93  : Agent
94  {
95  // TODO: This seems to be something that rather belongs to Services/Component/
96  // but we put it here anyway for the moment. This seems to be something that
97  // could go away when we unify Services/Modules/Plugins to one common concept.
98  $path = "[/]public/Customizing/global/plugins/.*/.*/" . $name . "/.*";
99  $agent_classes = iterator_to_array($this->interface_finder->getMatchingClassNames(
100  Agent::class,
101  [],
102  $path
103  ));
104 
105  if ($agent_classes === []) {
106  return new class ($name) extends \ilPluginDefaultAgent {
107  };
108  }
109 
110  $agents = [];
111  foreach ($agent_classes as $class_name) {
112  $agents[] = new $class_name(
113  $this->refinery,
114  $this->data_factory,
115  $this->lng
116  );
117  }
118 
119  if (count($agents) === 1) {
120  return $agents[0];
121  }
122 
123  return new AgentCollection(
124  $this->refinery,
125  $agents
126  );
127  }
$path
Definition: ltiservices.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPluginNames()

ILIAS\Setup\ImplementationOfAgentFinder::getPluginNames ( )
protected
Returns
<string>

Definition at line 159 of file ImplementationOfAgentFinder.php.

Referenced by ILIAS\Setup\ImplementationOfAgentFinder\getAgents().

159  : \Generator
160  {
161  $directories =
162  new \RecursiveIteratorIterator(
163  new \RecursiveDirectoryIterator(__DIR__ . "/../../../../public/Customizing/global/plugins")
164  );
165  $names = [];
166  foreach ($directories as $dir) {
167  $groups = [];
168  if (preg_match("%^" . __DIR__ . "/[.][.]/[.][.]/[.][.]/[.][.]/public/Customizing/global/plugins/(Services|Modules)/((\\w+/){2})([^/\.]+)(/|$)%", (string) $dir, $groups)) {
169  $name = $groups[4];
170  if (isset($names[$name])) {
171  continue;
172  }
173  $names[$name] = true;
174  yield $name;
175  }
176  }
177  }
+ Here is the caller graph for this function:

Field Documentation

◆ $component_agents

array AgentCollection ILIAS\Setup\ImplementationOfAgentFinder::$component_agents
protected

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