Repository navigation
Expand file tree
/
Copy pathBinding.php
More file actions
142 lines (127 loc) · 2.83 KB
/
Copy pathBinding.php
File metadata and controls
142 lines (127 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
namespace Dingo\Api\Transformer;
use Closure;
use RuntimeException;
use Illuminate\Container\Container;
class Binding
{
/**
* Illuminate container instance.
*
* @var \Illuminate\Container\Container
*/
protected $container;
/**
* Binding resolver.
*
* @var mixed
*/
protected $resolver;
/**
* Array of parameters.
*
* @var array
*/
protected $parameters = [];
/**
* Callback fired during transformation.
*
* @var \Closure
*/
protected $callback;
/**
* Array of meta data.
*
* @var array
*/
protected $meta = [];
/**
* Create a new binding instance.
*
* @param \Illuminate\Container\Container $container
* @param mixed $resolver
* @param array $parameters
* @param \Closure $callback
*
* @return void
*/
public function __construct(Container $container, $resolver, array $parameters = [], Closure $callback = null)
{
$this->container = $container;
$this->resolver = $resolver;
$this->parameters = $parameters;
$this->callback = $callback;
}
/**
* Resolve a transformer binding instance.
*
* @throws \RuntimeException
*
* @return object
*/
public function resolveTransformer()
{
if (is_string($this->resolver)) {
return $this->container->make($this->resolver);
} elseif (is_callable($this->resolver)) {
return call_user_func($this->resolver, $this->container);
} elseif (is_object($this->resolver)) {
return $this->resolver;
}
throw new RuntimeException('Unable to resolve transformer binding.');
}
/**
* Fire the binding callback.
*
* @param string|array $parameters
*
* @return void
*/
public function fireCallback($parameters = null)
{
if (is_callable($this->callback)) {
call_user_func_array($this->callback, func_get_args());
}
}
/**
* Get the binding parameters.
*
* @return array
*/
public function getParameters()
{
return $this->parameters;
}
/**
* Set the meta data for the binding.
*
* @param array $meta
*
* @return void
*/
public function setMeta(array $meta)
{
$this->meta = $meta;
}
/**
* Add a meta data key/value pair.
*
* @param string $key
* @param mixed $value
*
* @return void
*/
public function addMeta($key, $value)
{
$this->meta[$key] = $value;
}
/**
* Get the binding meta data.
*
* @return array
*/
public function getMeta()
{
return $this->meta;
}
}