ILIAS  release_7 Revision v7.30-3-g800a261c036
ILIAS\Setup\ImplementationOfAgentFinder Class Reference
+ Inheritance diagram for ILIAS\Setup\ImplementationOfAgentFinder:
+ Collaboration diagram for ILIAS\Setup\ImplementationOfAgentFinder:

Public Member Functions

 __construct (Refinery $refinery, Data\Factory $data_factory, \ilSetupLanguage $lng, ImplementationOfInterfaceFinder $interface_finder, \ilPluginRawReader $plugin_raw_reader, array $predefined_agents=[])
 
 getAgents ()
 Collect all agents from the system, core and plugin, bundled in a collection. More...
 
 getCoreAgents ()
 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 Attributes

 $refinery
 
 $data_factory
 
 $lng
 
 $plugin_raw_reader
 
 $interface_finder
 
 $predefined_agents
 

Detailed Description

Definition at line 12 of file ImplementationOfAgentFinder.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Setup\ImplementationOfAgentFinder::__construct ( Refinery  $refinery,
Data\Factory  $data_factory,
\ilSetupLanguage  $lng,
ImplementationOfInterfaceFinder  $interface_finder,
\ilPluginRawReader  $plugin_raw_reader,
array  $predefined_agents = [] 
)

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 166 of file ImplementationOfAgentFinder.php.

166  : Agent
167  {
168  if (!class_exists($class_name)) {
169  throw new \InvalidArgumentException("Class '" . $class_name . "' not found.");
170  }
171 
172  return new $class_name(
173  $this->refinery,
174  $this->data_factory,
175  $this->lng
176  );
177  }

◆ 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 182 of file ImplementationOfAgentFinder.php.

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

182  : string
183  {
184  // We assume that the name of an agent in the class ilXYZSetupAgent really
185  // is XYZ. If that does not fit we just use the class name.
186  $match = [];
187  if (preg_match("/il(\w+)SetupAgent/", $class_name, $match)) {
188  return strtolower($match[1]);
189  }
190  return $class_name;
191  }
+ 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 68 of file ImplementationOfAgentFinder.php.

References ILIAS\Setup\ImplementationOfAgentFinder\getCoreAgents(), and ILIAS\Setup\ImplementationOfAgentFinder\getPluginAgent().

68  : AgentCollection
69  {
70  $agents = $this->getCoreAgents();
71 
72  // Get a list of existing plugins in the system.
73  $plugins = $this->plugin_raw_reader->getPluginNames();
74 
75  foreach ($plugins as $plugin_name) {
76  $agents = $agents->withAdditionalAgent(
77  strtolower($plugin_name),
78  $this->getPluginAgent($plugin_name)
79  );
80  }
81 
82  return $agents;
83  }
getCoreAgents()
Collect core agents from the system bundled in a collection.
getPluginAgent(string $name)
Get a agent from a specific plugin.
+ Here is the call graph for this function:

◆ getCoreAgents()

ILIAS\Setup\ImplementationOfAgentFinder::getCoreAgents ( )

Collect core agents from the system bundled in a collection.

Implements ILIAS\Setup\AgentFinder.

Definition at line 89 of file ImplementationOfAgentFinder.php.

References ILIAS\Setup\ImplementationOfAgentFinder\getAgentNameByClassName().

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

89  : AgentCollection
90  {
91  // Initialize the agents.
92  $agents = new AgentCollection(
93  $this->refinery,
94  $this->predefined_agents
95  );
96 
97  // This is a list of all agent classes in the system (which we don't want to ignore).
98  $agent_classes = $this->interface_finder->getMatchingClassNames(
99  Agent::class,
100  ["[/]Customizing/.*"]
101  );
102  foreach ($agent_classes as $class_name) {
103  $agents = $agents->withAdditionalAgent(
104  $this->getAgentNameByClassName($class_name),
105  new $class_name(
106  $this->refinery,
107  $this->data_factory,
108  $this->lng
109  )
110  );
111  }
112 
113  return $agents;
114  }
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 124 of file ImplementationOfAgentFinder.php.

References $name.

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

124  : Agent
125  {
126  if (!$this->plugin_raw_reader->hasPlugin($name)) {
127  throw new \InvalidArgumentException(
128  "Cannot find plugin with name '$name'"
129  );
130  }
131 
132  // TODO: This seems to be something that rather belongs to Services/Component/
133  // but we put it here anyway for the moment. This seems to be something that
134  // could go away when we unify Services/Modules/Plugins to one common concept.
135  $path = "[/]Customizing/global/plugins/.*/.*/" . $name . "/.*";
136  $agent_classes = iterator_to_array($this->interface_finder->getMatchingClassNames(
137  Agent::class,
138  [],
139  $path
140  ));
141 
142  if (count($agent_classes) === 0) {
143  return new class($name) extends \ilPluginDefaultAgent {
144  };
145  }
146 
147  $agents = [];
148  foreach ($agent_classes as $class_name) {
149  $agents[] = new $class_name(
150  $this->refinery,
151  $this->data_factory,
152  $this->lng
153  );
154  }
155 
156  if (count($agents) === 1) {
157  return $agents[0];
158  }
159 
160  return new AgentCollection(
161  $this->refinery,
162  $agents
163  );
164  }
if($format !==null) $name
Definition: metadata.php:230
+ Here is the caller graph for this function:

Field Documentation

◆ $data_factory

ILIAS\Setup\ImplementationOfAgentFinder::$data_factory
protected

◆ $interface_finder

ILIAS\Setup\ImplementationOfAgentFinder::$interface_finder
protected

◆ $lng

ILIAS\Setup\ImplementationOfAgentFinder::$lng
protected

◆ $plugin_raw_reader

ILIAS\Setup\ImplementationOfAgentFinder::$plugin_raw_reader
protected

◆ $predefined_agents

array< string, Setup\Agent > ILIAS\Setup\ImplementationOfAgentFinder::$predefined_agents
protected

◆ $refinery

ILIAS\Setup\ImplementationOfAgentFinder::$refinery
protected

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