Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\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 Illuminate\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 Illuminate\Support.
34
     *
35
     * @param  mixed  $value
36
     * @param  mixed  ...$args
37
     * @return mixed
38
     */
39
    public static function unwrapIfClosure($value, ...$args)
40
    {
41
        return $value instanceof Closure ? $value(...$args) : $value;
42
    }
43
 
44
    /**
45
     * Get the class name of the given parameter's type, if possible.
46
     *
47
     * From Reflector::getParameterClassName() in Illuminate\Support.
48
     *
49
     * @param  \ReflectionParameter  $parameter
50
     * @return string|null
51
     */
52
    public static function getParameterClassName($parameter)
53
    {
54
        $type = $parameter->getType();
55
 
56
        if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
57
            return null;
58
        }
59
 
60
        $name = $type->getName();
61
 
62
        if (! is_null($class = $parameter->getDeclaringClass())) {
63
            if ($name === 'self') {
64
                return $class->getName();
65
            }
66
 
67
            if ($name === 'parent' && $parent = $class->getParentClass()) {
68
                return $parent->getName();
69
            }
70
        }
71
 
72
        return $name;
73
    }
74
}