PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.10
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.10
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / vendor / wpfluent / framework / src / WPFluent / Container / Util.php

Util.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.10, at vendor/wpfluent/framework/src/WPFluent/Container/Util.php

74 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\Framework\Container;
4
5 use Closure;
6 use ReflectionNamedType;
7
8 /**
9 * @internal
10 */
11 class Util
12 {
13 /**
14 * If the given value is not an array and not null, wrap it in one.
15 *
16 * From Arr::wrap() in FluentForm\Framework\Support.
17 *
18 * @param mixed $value
19 * @return array
20 */
21 public static function arrayWrap($value)
22 {
23 if (is_null($value)) {
24 return [];
25 }
26
27 return is_array($value) ? $value : [$value];
28 }
29
30 /**
31 * Return the default value of the given value.
32 *
33 * From global value() helper in FluentForm\Framework\Support.
34 *
35 * @param mixed $value
36 * @return mixed
37 */
38 public static function unwrapIfClosure($value)
39 {
40 return $value instanceof Closure ? $value() : $value;
41 }
42
43 /**
44 * Get the class name of the given parameter's type, if possible.
45 *
46 * From Reflector::getParameterClassName() in FluentForm\Framework\Support.
47 *
48 * @param \ReflectionParameter $parameter
49 * @return string|null
50 */
51 public static function getParameterClassName($parameter)
52 {
53 $type = $parameter->getType();
54
55 if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
56 return null;
57 }
58
59 $name = $type->getName();
60
61 if (! is_null($class = $parameter->getDeclaringClass())) {
62 if ($name === 'self') {
63 return $class->getName();
64 }
65
66 if ($name === 'parent' && $parent = $class->getParentClass()) {
67 return $parent->getName();
68 }
69 }
70
71 return $name;
72 }
73 }
74