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\Support\Traits;
4
 
5
use BadMethodCallException;
6
use Error;
7
 
8
trait ForwardsCalls
9
{
10
    /**
11
     * Forward a method call to the given object.
12
     *
13
     * @param  mixed  $object
14
     * @param  string  $method
15
     * @param  array  $parameters
16
     * @return mixed
17
     *
18
     * @throws \BadMethodCallException
19
     */
20
    protected function forwardCallTo($object, $method, $parameters)
21
    {
22
        try {
23
            return $object->{$method}(...$parameters);
24
        } catch (Error|BadMethodCallException $e) {
25
            $pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';
26
 
27
            if (! preg_match($pattern, $e->getMessage(), $matches)) {
28
                throw $e;
29
            }
30
 
31
            if ($matches['class'] != get_class($object) ||
32
                $matches['method'] != $method) {
33
                throw $e;
34
            }
35
 
36
            static::throwBadMethodCallException($method);
37
        }
38
    }
39
 
40
    /**
41
     * Forward a method call to the given object, returning $this if the forwarded call returned itself.
42
     *
43
     * @param  mixed  $object
44
     * @param  string  $method
45
     * @param  array  $parameters
46
     * @return mixed
47
     *
48
     * @throws \BadMethodCallException
49
     */
50
    protected function forwardDecoratedCallTo($object, $method, $parameters)
51
    {
52
        $result = $this->forwardCallTo($object, $method, $parameters);
53
 
54
        if ($result === $object) {
55
            return $this;
56
        }
57
 
58
        return $result;
59
    }
60
 
61
    /**
62
     * Throw a bad method call exception for the given method.
63
     *
64
     * @param  string  $method
65
     * @return void
66
     *
67
     * @throws \BadMethodCallException
68
     */
69
    protected static function throwBadMethodCallException($method)
70
    {
71
        throw new BadMethodCallException(sprintf(
72
            'Call to undefined method %s::%s()', static::class, $method
73
        ));
74
    }
75
}