PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.2
Defender Security – Malware Scanner, Login Security & Firewall v5.7.2
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / lib / packages / DI / Attribute / Inject.php

Inject.php in Defender Security – Malware Scanner, Login Security & Firewall 5.7.2, at lib/packages/DI/Attribute/Inject.php

75 lines 1.7 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 WPMU_DEV\Defender\Vendor\DI\Attribute;
6
7 use Attribute;
8 use WPMU_DEV\Defender\Vendor\DI\Definition\Exception\InvalidAttribute;
9
10 /**
11 * #[Inject] attribute.
12 *
13 * Marks a property or method as an injection point
14 *
15 * @api
16 *
17 * @author Matthieu Napoli <[email protected]>
18 */
19 #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
20 class Inject
21 {
22 /**
23 * Entry name.
24 */
25 private ?string $name = null;
26
27 /**
28 * Parameters, indexed by the parameter number (index) or name.
29 *
30 * Used if the attribute is set on a method
31 */
32 private array $parameters = [];
33
34 /**
35 * @throws InvalidAttribute
36 */
37 public function __construct(string|array|null $name = null)
38 {
39 // #[Inject('foo')] or #[Inject(name: 'foo')]
40 if (is_string($name)) {
41 $this->name = $name;
42 }
43
44 // #[Inject([...])] on a method
45 if (is_array($name)) {
46 foreach ($name as $key => $value) {
47 if (! is_string($value)) {
48 throw new InvalidAttribute(sprintf(
49 "#[Inject(['param' => 'value'])] expects \"value\" to be a string, %s given.",
50 json_encode($value, \JSON_THROW_ON_ERROR)
51 ));
52 }
53
54 $this->parameters[$key] = $value;
55 }
56 }
57 }
58
59 /**
60 * @return string|null Name of the entry to inject
61 */
62 public function getName() : ?string
63 {
64 return $this->name;
65 }
66
67 /**
68 * @return array Parameters, indexed by the parameter number (index) or name
69 */
70 public function getParameters() : array
71 {
72 return $this->parameters;
73 }
74 }
75