PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.2.0
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.2.0
4.9.2 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 All 200 releases
betterdocs / includes / Dependencies / DI / Definition / Helper / AutowireDefinitionHelper.php

AutowireDefinitionHelper.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.2.0, at includes/Dependencies/DI/Definition/Helper/AutowireDefinitionHelper.php

73 lines 2.4 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\Helper;
6
7 use WPDeveloper\BetterDocs\Dependencies\DI\Definition\AutowireDefinition;
8
9 /**
10 * Helps defining how to create an instance of a class using autowiring.
11 *
12 * @author Matthieu Napoli <matthieu@mnapoli.fr>
13 */
14 class AutowireDefinitionHelper extends CreateDefinitionHelper
15 {
16 const DEFINITION_CLASS = AutowireDefinition::class;
17
18 /**
19 * Defines a value for a specific argument of the constructor.
20 *
21 * This method is usually used together with annotations or autowiring, when a parameter
22 * is not (or cannot be) type-hinted. Using this method instead of constructor() allows to
23 * avoid defining all the parameters (letting them being resolved using annotations or autowiring)
24 * and only define one.
25 *
26 * @param string|int $parameter Parameter name of position for which the value will be given.
27 * @param mixed $value Value to give to this parameter.
28 *
29 * @return $this
30 */
31 public function constructorParameter($parameter, $value)
32 {
33 $this->constructor[$parameter] = $value;
34
35 return $this;
36 }
37
38 /**
39 * Defines a method to call and a value for a specific argument.
40 *
41 * This method is usually used together with annotations or autowiring, when a parameter
42 * is not (or cannot be) type-hinted. Using this method instead of method() allows to
43 * avoid defining all the parameters (letting them being resolved using annotations or
44 * autowiring) and only define one.
45 *
46 * If multiple calls to the method have been configured already (e.g. in a previous definition)
47 * then this method only overrides the parameter for the *first* call.
48 *
49 * @param string $method Name of the method to call.
50 * @param string|int $parameter Parameter name of position for which the value will be given.
51 * @param mixed $value Value to give to this parameter.
52 *
53 * @return $this
54 */
55 public function methodParameter(string $method, $parameter, $value)
56 {
57 // Special case for the constructor
58 if ($method === '__construct') {
59 $this->constructor[$parameter] = $value;
60
61 return $this;
62 }
63
64 if (! isset($this->methods[$method])) {
65 $this->methods[$method] = [0 => []];
66 }
67
68 $this->methods[$method][0][$parameter] = $value;
69
70 return $this;
71 }
72 }
73