PluginProbe
Elementor Website Builder – more than just a page builder / 3.26.2
Elementor Website Builder – more than just a page builder v3.26.2
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 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 All 457 releases
elementor / vendor_prefixed / php-di / php-di / src / functions.php

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

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