PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.5.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.5.3
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Dependencies / DI / Definition / ObjectDefinition / MethodInjection.php

MethodInjection.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.5.3, at includes/Dependencies/DI/Definition/ObjectDefinition/MethodInjection.php

87 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace WPDeveloper\BetterDocs\Dependencies\DI\Definition\ObjectDefinition;
6
7 use WPDeveloper\BetterDocs\Dependencies\DI\Definition\Definition;
8
9 /**
10 * Describe an injection in an object method.
11 *
12 * @author Matthieu Napoli <matthieu@mnapoli.fr>
13 */
14 class MethodInjection implements Definition
15 {
16 /**
17 * @var string
18 */
19 private $methodName;
20
21 /**
22 * @var mixed[]
23 */
24 private $parameters = [];
25
26 public function __construct(string $methodName, array $parameters = [])
27 {
28 $this->methodName = (string) $methodName;
29 $this->parameters = $parameters;
30 }
31
32 public static function constructor(array $parameters = []) : self
33 {
34 return new self('__construct', $parameters);
35 }
36
37 public function getMethodName() : string
38 {
39 return $this->methodName;
40 }
41
42 /**
43 * @return mixed[]
44 */
45 public function getParameters() : array
46 {
47 return $this->parameters;
48 }
49
50 /**
51 * Replace the parameters of the definition by a new array of parameters.
52 */
53 public function replaceParameters(array $parameters)
54 {
55 $this->parameters = $parameters;
56 }
57
58 public function merge(self $definition)
59 {
60 // In case of conflicts, the current definition prevails.
61 $this->parameters = $this->parameters + $definition->parameters;
62 }
63
64 public function getName() : string
65 {
66 return '';
67 }
68
69 public function setName(string $name)
70 {
71 // The name does not matter for method injections
72 }
73
74 public function replaceNestedDefinitions(callable $replacer)
75 {
76 $this->parameters = array_map($replacer, $this->parameters);
77 }
78
79 /**
80 * {@inheritdoc}
81 */
82 public function __toString()
83 {
84 return sprintf('method(%s)', $this->methodName);
85 }
86 }
87