PluginProbe
Elementor Website Builder – more than just a page builder / 3.27.4
Elementor Website Builder – more than just a page builder v3.27.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / vendor_prefixed / php-di / php-di / src / Annotation / Inject.php

Inject.php in Elementor Website Builder – more than just a page builder 3.27.4, at vendor_prefixed/php-di/php-di/src/Annotation/Inject.php

78 lines 1.9 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 namespace ElementorDeps\DI\Annotation;
5
6 use ElementorDeps\DI\Definition\Exception\InvalidAnnotation;
7 /**
8 * "Inject" annotation.
9 *
10 * Marks a property or method as an injection point
11 *
12 * @api
13 *
14 * @Annotation
15 * @Target({"METHOD","PROPERTY"})
16 *
17 * @author Matthieu Napoli <matthieu@mnapoli.fr>
18 */
19 final class Inject
20 {
21 /**
22 * Entry name.
23 * @var string
24 */
25 private $name;
26 /**
27 * Parameters, indexed by the parameter number (index) or name.
28 *
29 * Used if the annotation is set on a method
30 * @var array
31 */
32 private $parameters = [];
33 /**
34 * @throws InvalidAnnotation
35 */
36 public function __construct(array $values)
37 {
38 // Process the parameters as a list AND as a parameter array (we don't know on what the annotation is)
39 // @Inject(name="foo")
40 if (isset($values['name']) && \is_string($values['name'])) {
41 $this->name = $values['name'];
42 return;
43 }
44 // @Inject
45 if (!isset($values['value'])) {
46 return;
47 }
48 $values = $values['value'];
49 // @Inject("foo")
50 if (\is_string($values)) {
51 $this->name = $values;
52 }
53 // @Inject({...}) on a method
54 if (\is_array($values)) {
55 foreach ($values as $key => $value) {
56 if (!\is_string($value)) {
57 throw new InvalidAnnotation(\sprintf('@Inject({"param" = "value"}) expects "value" to be a string, %s given.', \json_encode($value)));
58 }
59 $this->parameters[$key] = $value;
60 }
61 }
62 }
63 /**
64 * @return string|null Name of the entry to inject
65 */
66 public function getName()
67 {
68 return $this->name;
69 }
70 /**
71 * @return array Parameters, indexed by the parameter number (index) or name
72 */
73 public function getParameters() : array
74 {
75 return $this->parameters;
76 }
77 }
78