PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.0
Defender Security – Malware Scanner, Login Security & Firewall v5.7.0
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 / functions.php

functions.php in Defender Security – Malware Scanner, Login Security & Firewall 5.7.0, at lib/packages/DI/functions.php

155 lines 4.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
5 namespace WPMU_DEV\Defender\Vendor\DI;
6
7 use WPMU_DEV\Defender\Vendor\DI\Definition\ArrayDefinitionExtension;
8 use WPMU_DEV\Defender\Vendor\DI\Definition\EnvironmentVariableDefinition;
9 use WPMU_DEV\Defender\Vendor\DI\Definition\Helper\AutowireDefinitionHelper;
10 use WPMU_DEV\Defender\Vendor\DI\Definition\Helper\CreateDefinitionHelper;
11 use WPMU_DEV\Defender\Vendor\DI\Definition\Helper\FactoryDefinitionHelper;
12 use WPMU_DEV\Defender\Vendor\DI\Definition\Reference;
13 use WPMU_DEV\Defender\Vendor\DI\Definition\StringDefinition;
14 use WPMU_DEV\Defender\Vendor\DI\Definition\ValueDefinition;
15
16 if (! function_exists('WPMU_DEV\Defender\Vendor\DI\value')) {
17 /**
18 * Helper for defining a value.
19 */
20 function value(mixed $value) : ValueDefinition
21 {
22 return new ValueDefinition($value);
23 }
24 }
25
26 if (! function_exists('WPMU_DEV\Defender\Vendor\DI\create')) {
27 /**
28 * Helper for defining an object.
29 *
30 * @param string|null $className Class name of the object.
31 * If null, the name of the entry (in the container) will be used as class name.
32 */
33 function create(?string $className = null) : CreateDefinitionHelper
34 {
35 return new CreateDefinitionHelper($className);
36 }
37 }
38
39 if (! function_exists('WPMU_DEV\Defender\Vendor\DI\autowire')) {
40 /**
41 * Helper for autowiring an object.
42 *
43 * @param string|null $className Class name of the object.
44 * If null, the name of the entry (in the container) will be used as class name.
45 */
46 function autowire(?string $className = null) : AutowireDefinitionHelper
47 {
48 return new AutowireDefinitionHelper($className);
49 }
50 }
51
52 if (! function_exists('WPMU_DEV\Defender\Vendor\DI\factory')) {
53 /**
54 * Helper for defining a container entry using a factory function/callable.
55 *
56 * @param callable|array|string $factory The factory is a callable that takes the container as parameter
57 * and returns the value to register in the container.
58 */
59 function factory(callable|array|string $factory) : FactoryDefinitionHelper
60 {
61 return new FactoryDefinitionHelper($factory);
62 }
63 }
64
65 if (! function_exists('WPMU_DEV\Defender\Vendor\DI\decorate')) {
66 /**
67 * Decorate the previous definition using a callable.
68 *
69 * Example:
70 *
71 * 'foo' => decorate(function ($foo, $container) {
72 * return new CachedFoo($foo, $container->get('cache'));
73 * })
74 *
75 * @param callable $callable The callable takes the decorated object as first parameter and
76 * the container as second.
77 */
78 function decorate(callable|array|string $callable) : FactoryDefinitionHelper
79 {
80 return new FactoryDefinitionHelper($callable, true);
81 }
82 }
83
84 if (! function_exists('WPMU_DEV\Defender\Vendor\DI\get')) {
85 /**
86 * Helper for referencing another container entry in an object definition.
87 */
88 function get(string $entryName) : Reference
89 {
90 return new Reference($entryName);
91 }
92 }
93
94 if (! function_exists('WPMU_DEV\Defender\Vendor\DI\env')) {
95 /**
96 * Helper for referencing environment variables.
97 *
98 * @param string $variableName The name of the environment variable.
99 * @param mixed $defaultValue The default value to be used if the environment variable is not defined.
100 */
101 function env(string $variableName, mixed $defaultValue = null) : EnvironmentVariableDefinition
102 {
103 // Only mark as optional if the default value was *explicitly* provided.
104 $isOptional = 2 === func_num_args();
105
106 return new EnvironmentVariableDefinition($variableName, $isOptional, $defaultValue);
107 }
108 }
109
110 if (! function_exists('WPMU_DEV\Defender\Vendor\DI\add')) {
111 /**
112 * Helper for extending another definition.
113 *
114 * Example:
115 *
116 * 'log.backends' => WPMU_DEV\Defender\Vendor\DI\add(WPMU_DEV\Defender\Vendor\DI\get('My\Custom\LogBackend'))
117 *
118 * or:
119 *
120 * 'log.backends' => WPMU_DEV\Defender\Vendor\DI\add([
121 * WPMU_DEV\Defender\Vendor\DI\get('My\Custom\LogBackend')
122 * ])
123 *
124 * @param mixed|array $values A value or an array of values to add to the array.
125 *
126 * @since 5.0
127 */
128 function add($values) : ArrayDefinitionExtension
129 {
130 if (! is_array($values)) {
131 $values = [$values];
132 }
133
134 return new ArrayDefinitionExtension($values);
135 }
136 }
137
138 if (! function_exists('WPMU_DEV\Defender\Vendor\DI\string')) {
139 /**
140 * Helper for concatenating strings.
141 *
142 * Example:
143 *
144 * 'log.filename' => WPMU_DEV\Defender\Vendor\DI\string('{app.path}/app.log')
145 *
146 * @param string $expression A string expression. Use the `{}` placeholders to reference other container entries.
147 *
148 * @since 5.0
149 */
150 function string(string $expression) : StringDefinition
151 {
152 return new StringDefinition($expression);
153 }
154 }
155