PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.21
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.21
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / vendor / wpfluent / framework / src / WPFluent / Container / Util.php

Util.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.5.21, 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 FluentBooking\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 FluentBooking\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 FluentBooking\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 FluentBooking\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