ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\Setup\ImplementationOfAgentFinder Class Reference

Using the AgentFinder as EntryPoint is an exception/abomination for 10 only. More...

+ 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...
 
 getName ()
 Using the AgentFinder as EntryPoint is an exception/abomination for 10 only. More...
 
 enter ()
 Using the AgentFinder as EntryPoint is an exception/abomination for 10 only. More...
 

Protected Member Functions

 getPluginNames ()
 

Protected Attributes

array AgentCollection $component_agents
 

Detailed Description

Using the AgentFinder as EntryPoint is an exception/abomination for 10 only.

Do not copy or use as example! The Finder is needed in ilObjSystemFolderGUI to get the installation's status. There is a better bridge in 11.

Definition at line 32 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 36 of file ImplementationOfAgentFinder.php.

References ILIAS\Setup\ImplementationOfAgentFinder\$component_agents.

42  {
43  $this->component_agents = $component_agents;
44  }

Member Function Documentation

◆ enter()

ILIAS\Setup\ImplementationOfAgentFinder::enter ( )

Using the AgentFinder as EntryPoint is an exception/abomination for 10 only.

Do not copy or use as example!

Deprecated:
will be removed in 11

Implements ILIAS\Component\EntryPoint.

Definition at line 200 of file ImplementationOfAgentFinder.php.

References $DIC.

200  : int
201  {
202  global $DIC;
203  $DIC['setup.agentfinder'] = fn() => $this;
204  return 0;
205  }
global $DIC
Definition: shib_login.php:25

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

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

135  : Agent
136  {
137  if (!class_exists($class_name)) {
138  throw new \InvalidArgumentException("Class '" . $class_name . "' not found.");
139  }
140 
141  return new $class_name(
142  $this->refinery,
143  $this->data_factory,
144  $this->lng
145  );
146  }
+ 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 151 of file ImplementationOfAgentFinder.php.

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

151  : string
152  {
153  // We assume that the name of an agent in the class ilXYZSetupAgent really
154  // is XYZ. If that does not fit we just use the class name.
155  $match = [];
156  if (preg_match("/il(\w+)SetupAgent/", $class_name, $match)) {
157  return strtolower($match[1]);
158  }
159  return $class_name;
160  }
+ 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 51 of file ImplementationOfAgentFinder.php.

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

51  : AgentCollection
52  {
53  $agents = $this->getComponentAgents();
54 
55  // Get a list of existing plugins in the system.
56  $plugins = $this->getPluginNames();
57 
58  foreach ($plugins as $plugin_name) {
59  $agents = $agents->withAdditionalAgent(
60  $plugin_name,
61  $this->getPluginAgent($plugin_name)
62  );
63  }
64 
65  return $agents;
66  }
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 72 of file ImplementationOfAgentFinder.php.

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

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

72  : AgentCollection
73  {
74  if ($this->component_agents instanceof AgentCollection) {
76  }
77 
78  $agents = new AgentCollection($this->refinery, []);
79 
80  foreach ($this->component_agents as $agent) {
81  $agents = $agents->withAdditionalAgent(
82  $this->getAgentNameByClassName(get_class($agent)),
83  $agent
84  );
85  }
86 
87  $this->component_agents = $agents;
89  }
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:

◆ getName()

ILIAS\Setup\ImplementationOfAgentFinder::getName ( )

Using the AgentFinder as EntryPoint is an exception/abomination for 10 only.

Do not copy or use as example!

Deprecated:
will be removed in 11

Implements ILIAS\Component\EntryPoint.

Definition at line 190 of file ImplementationOfAgentFinder.php.

190  : string
191  {
192  return 'Agent Finder Adapter';
193  }

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

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

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

99  : Agent
100  {
101  // TODO: This seems to be something that rather belongs to Services/Component/
102  // but we put it here anyway for the moment. This seems to be something that
103  // could go away when we unify Services/Modules/Plugins to one common concept.
104  $path = "[/]public/Customizing/global/plugins/.*/.*/" . $name . "/.*";
105  $agent_classes = iterator_to_array($this->interface_finder->getMatchingClassNames(
106  Agent::class,
107  [],
108  $path
109  ));
110 
111  if ($agent_classes === []) {
112  return new class ($name) extends \ilPluginDefaultAgent {
113  };
114  }
115 
116  $agents = [];
117  foreach ($agent_classes as $class_name) {
118  $agents[] = new $class_name(
119  $this->refinery,
120  $this->data_factory,
121  $this->lng
122  );
123  }
124 
125  if (count($agents) === 1) {
126  return $agents[0];
127  }
128 
129  return new AgentCollection(
130  $this->refinery,
131  $agents
132  );
133  }
$path
Definition: ltiservices.php:30
+ 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 165 of file ImplementationOfAgentFinder.php.

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

165  : \Generator
166  {
167  $directories =
168  new \RecursiveIteratorIterator(
169  new \RecursiveDirectoryIterator(__DIR__ . "/../../../../public/Customizing/global/plugins")
170  );
171  $names = [];
172  foreach ($directories as $dir) {
173  $groups = [];
174  if (preg_match("%^" . __DIR__ . "/[.][.]/[.][.]/[.][.]/[.][.]/public/Customizing/global/plugins/(Services|Modules)/((\\w+/){2})([^/\.]+)(/|$)%", (string) $dir, $groups)) {
175  $name = $groups[4];
176  if (isset($names[$name])) {
177  continue;
178  }
179  $names[$name] = true;
180  yield $name;
181  }
182  }
183  }
+ 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: