ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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, 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 Member Functions

 getPluginNames ()
 

Protected Attributes

Refinery $refinery
 
Data Factory $data_factory
 
ilSetupLanguage $lng
 
ImplementationOfInterfaceFinder $interface_finder
 
array $predefined_agents
 

Detailed Description

Definition at line 26 of file ImplementationOfAgentFinder.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Setup\ImplementationOfAgentFinder::__construct ( Refinery  $refinery,
Data\Factory  $data_factory,
\ilSetupLanguage  $lng,
ImplementationOfInterfaceFinder  $interface_finder,
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 149 of file ImplementationOfAgentFinder.php.

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

149  : Agent
150  {
151  if (!class_exists($class_name)) {
152  throw new \InvalidArgumentException("Class '" . $class_name . "' not found.");
153  }
154 
155  return new $class_name(
156  $this->refinery,
157  $this->data_factory,
158  $this->lng
159  );
160  }
+ 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 165 of file ImplementationOfAgentFinder.php.

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

165  : string
166  {
167  // We assume that the name of an agent in the class ilXYZSetupAgent really
168  // is XYZ. If that does not fit we just use the class name.
169  $match = [];
170  if (preg_match("/il(\w+)SetupAgent/", $class_name, $match)) {
171  return strtolower($match[1]);
172  }
173  return $class_name;
174  }
+ 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 57 of file ImplementationOfAgentFinder.php.

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

57  : AgentCollection
58  {
59  $agents = $this->getCoreAgents();
60 
61  // Get a list of existing plugins in the system.
62  $plugins = $this->getPluginNames();
63 
64  foreach ($plugins as $plugin_name) {
65  $agents = $agents->withAdditionalAgent(
66  $plugin_name,
67  $this->getPluginAgent($plugin_name)
68  );
69  }
70 
71  return $agents;
72  }
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 78 of file ImplementationOfAgentFinder.php.

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

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

78  : AgentCollection
79  {
80  // Initialize the agents.
81  $agents = new AgentCollection(
82  $this->refinery,
83  $this->predefined_agents
84  );
85 
86  // This is a list of all agent classes in the system (which we don't want to ignore).
87  $agent_classes = $this->interface_finder->getMatchingClassNames(
88  Agent::class,
89  ["[/]Customizing/.*"]
90  );
91  foreach ($agent_classes as $class_name) {
92  $agents = $agents->withAdditionalAgent(
93  $this->getAgentNameByClassName($class_name),
94  new $class_name(
95  $this->refinery,
96  $this->data_factory,
97  $this->lng
98  )
99  );
100  }
101 
102  return $agents;
103  }
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 113 of file ImplementationOfAgentFinder.php.

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

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

113  : Agent
114  {
115  // TODO: This seems to be something that rather belongs to Services/Component/
116  // but we put it here anyway for the moment. This seems to be something that
117  // could go away when we unify Services/Modules/Plugins to one common concept.
118  $path = "[/]Customizing/global/plugins/.*/.*/" . $name . "/.*";
119  $agent_classes = iterator_to_array($this->interface_finder->getMatchingClassNames(
120  Agent::class,
121  [],
122  $path
123  ));
124 
125  if ($agent_classes === []) {
126  return new class ($name) extends \ilPluginDefaultAgent {
127  };
128  }
129 
130  $agents = [];
131  foreach ($agent_classes as $class_name) {
132  $agents[] = new $class_name(
133  $this->refinery,
134  $this->data_factory,
135  $this->lng
136  );
137  }
138 
139  if (count($agents) === 1) {
140  return $agents[0];
141  }
142 
143  return new AgentCollection(
144  $this->refinery,
145  $agents
146  );
147  }
$path
Definition: ltiservices.php:32
if($format !==null) $name
Definition: metadata.php:247
+ 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 179 of file ImplementationOfAgentFinder.php.

References $name.

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

179  : \Generator
180  {
181  $directories =
182  new \RecursiveIteratorIterator(
183  new \RecursiveDirectoryIterator(__DIR__ . "/../../Customizing/global/plugins/")
184  );
185  $names = [];
186  foreach ($directories as $dir) {
187  $groups = [];
188  if (preg_match("%^" . __DIR__ . "/[.][.]/[.][.]/Customizing/global/plugins/((Modules)|(Services))/((\\w+/){2})([^/\.]+)(/|$)%", (string) $dir, $groups)) {
189  $name = $groups[6];
190  if (isset($names[$name])) {
191  continue;
192  }
193  $names[$name] = true;
194  yield $name;
195  }
196  }
197  }
if($format !==null) $name
Definition: metadata.php:247
+ Here is the caller graph for this function:

Field Documentation

◆ $data_factory

Data Factory ILIAS\Setup\ImplementationOfAgentFinder::$data_factory
protected

◆ $interface_finder

ImplementationOfInterfaceFinder ILIAS\Setup\ImplementationOfAgentFinder::$interface_finder
protected

◆ $lng

ilSetupLanguage ILIAS\Setup\ImplementationOfAgentFinder::$lng
protected

◆ $predefined_agents

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

◆ $refinery

Refinery ILIAS\Setup\ImplementationOfAgentFinder::$refinery
protected

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