PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.1
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 / vendor / php-di / php-di / src / DI / Definition / Helper / FactoryDefinitionHelper.php

FactoryDefinitionHelper.php in Defender Security – Malware Scanner, Login Security & Firewall 3.0.1, at vendor/php-di/php-di/src/DI/Definition/Helper/FactoryDefinitionHelper.php

92 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace DI\Definition\Helper;
4
5 use DI\Definition\DecoratorDefinition;
6 use DI\Definition\FactoryDefinition;
7
8 /**
9 * Helps defining how to create an instance of a class using a factory (callable).
10 *
11 * @author Matthieu Napoli <[email protected]>
12 */
13 class FactoryDefinitionHelper implements DefinitionHelper
14 {
15 /**
16 * @var callable
17 */
18 private $factory;
19
20 /**
21 * @var string|null
22 */
23 private $scope;
24
25 /**
26 * @var bool
27 */
28 private $decorate;
29
30 /**
31 * @var array
32 */
33 private $parameters = [];
34
35 /**
36 * @param callable $factory
37 * @param bool $decorate Is the factory decorating a previous definition?
38 */
39 public function __construct($factory, $decorate = false)
40 {
41 $this->factory = $factory;
42 $this->decorate = $decorate;
43 }
44
45 /**
46 * Defines the scope of the entry.
47 *
48 * @param string $scope
49 *
50 * @return FactoryDefinitionHelper
51 */
52 public function scope($scope)
53 {
54 $this->scope = $scope;
55
56 return $this;
57 }
58
59 /**
60 * @param string $entryName Container entry name
61 * @return FactoryDefinition
62 */
63 public function getDefinition($entryName)
64 {
65 if ($this->decorate) {
66 return new DecoratorDefinition($entryName, $this->factory, $this->scope, $this->parameters);
67 }
68
69 return new FactoryDefinition($entryName, $this->factory, $this->scope, $this->parameters);
70 }
71
72 /**
73 * Defines arguments to pass to the factory.
74 *
75 * Because factory methods do not yet support annotations or autowiring, this method
76 * should be used to define all parameters except the ContainerInterface and RequestedEntry.
77 *
78 * Multiple calls can be made to the method to override individual values.
79 *
80 * @param string $parameter Name or index of the parameter for which the value will be given.
81 * @param mixed $value Value to give to this parameter.
82 *
83 * @return FactoryDefinitionHelper
84 */
85 public function parameter($parameter, $value)
86 {
87 $this->parameters[$parameter] = $value;
88
89 return $this;
90 }
91 }
92