PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / trunk
Fluent Support – Helpdesk & Customer Support Ticket System vtrunk
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / vendor / wpfluent / framework / src / WPFluent / Container / Util.php

Util.php in Fluent Support – Helpdesk & Customer Support Ticket System trunk, 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 FluentSupport\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 FluentSupport\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 FluentSupport\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 FluentSupport\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