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\Http\Resources;
4
 
5
use Exception;
6
use Illuminate\Support\Traits\ForwardsCalls;
7
use Illuminate\Support\Traits\Macroable;
8
 
9
trait DelegatesToResource
10
{
11
    use ForwardsCalls, Macroable {
12
        __call as macroCall;
13
    }
14
 
15
    /**
16
     * Get the value of the resource's route key.
17
     *
18
     * @return mixed
19
     */
20
    public function getRouteKey()
21
    {
22
        return $this->resource->getRouteKey();
23
    }
24
 
25
    /**
26
     * Get the route key for the resource.
27
     *
28
     * @return string
29
     */
30
    public function getRouteKeyName()
31
    {
32
        return $this->resource->getRouteKeyName();
33
    }
34
 
35
    /**
36
     * Retrieve the model for a bound value.
37
     *
38
     * @param  mixed  $value
39
     * @param  string|null  $field
40
     * @return void
41
     *
42
     * @throws \Exception
43
     */
44
    public function resolveRouteBinding($value, $field = null)
45
    {
46
        throw new Exception('Resources may not be implicitly resolved from route bindings.');
47
    }
48
 
49
    /**
50
     * Retrieve the model for a bound value.
51
     *
52
     * @param  string  $childType
53
     * @param  mixed  $value
54
     * @param  string|null  $field
55
     * @return void
56
     *
57
     * @throws \Exception
58
     */
59
    public function resolveChildRouteBinding($childType, $value, $field = null)
60
    {
61
        throw new Exception('Resources may not be implicitly resolved from route bindings.');
62
    }
63
 
64
    /**
65
     * Determine if the given attribute exists.
66
     *
67
     * @param  mixed  $offset
68
     * @return bool
69
     */
70
    public function offsetExists($offset): bool
71
    {
72
        return isset($this->resource[$offset]);
73
    }
74
 
75
    /**
76
     * Get the value for a given offset.
77
     *
78
     * @param  mixed  $offset
79
     * @return mixed
80
     */
81
    public function offsetGet($offset): mixed
82
    {
83
        return $this->resource[$offset];
84
    }
85
 
86
    /**
87
     * Set the value for a given offset.
88
     *
89
     * @param  mixed  $offset
90
     * @param  mixed  $value
91
     * @return void
92
     */
93
    public function offsetSet($offset, $value): void
94
    {
95
        $this->resource[$offset] = $value;
96
    }
97
 
98
    /**
99
     * Unset the value for a given offset.
100
     *
101
     * @param  mixed  $offset
102
     * @return void
103
     */
104
    public function offsetUnset($offset): void
105
    {
106
        unset($this->resource[$offset]);
107
    }
108
 
109
    /**
110
     * Determine if an attribute exists on the resource.
111
     *
112
     * @param  string  $key
113
     * @return bool
114
     */
115
    public function __isset($key)
116
    {
117
        return isset($this->resource->{$key});
118
    }
119
 
120
    /**
121
     * Unset an attribute on the resource.
122
     *
123
     * @param  string  $key
124
     * @return void
125
     */
126
    public function __unset($key)
127
    {
128
        unset($this->resource->{$key});
129
    }
130
 
131
    /**
132
     * Dynamically get properties from the underlying resource.
133
     *
134
     * @param  string  $key
135
     * @return mixed
136
     */
137
    public function __get($key)
138
    {
139
        return $this->resource->{$key};
140
    }
141
 
142
    /**
143
     * Dynamically pass method calls to the underlying resource.
144
     *
145
     * @param  string  $method
146
     * @param  array  $parameters
147
     * @return mixed
148
     */
149
    public function __call($method, $parameters)
150
    {
151
        if (static::hasMacro($method)) {
152
            return $this->macroCall($method, $parameters);
153
        }
154
 
155
        return $this->forwardCallTo($this->resource, $method, $parameters);
156
    }
157
}