Subversion Repository Public Repository

Nextrek

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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php namespace Illuminate\Routing;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Container\Container;

class ControllerDispatcher {

	/**
	 * The routing filterer implementation.
	 *
	 * @var \Illuminate\Routing\RouteFiltererInterface  $filterer
	 */
	protected $filterer;

	/**
	 * The IoC container instance.
	 *
	 * @var \Illuminate\Container\Container
	 */
	protected $container;

	/**
	 * Create a new controller dispatcher instance.
	 *
	 * @param  \Illuminate\Routing\RouteFiltererInterface  $filterer
	 * @param  \Illuminate\Container\Container  $container
	 * @return void
	 */
	public function __construct(RouteFiltererInterface $filterer,
								Container $container = null)
	{
		$this->filterer = $filterer;
		$this->container = $container;
	}

	/**
	 * Dispatch a request to a given controller and method.
	 *
	 * @param  \Illuminate\Routing\Route  $route
	 * @param  \Illuminate\Http\Request  $request
	 * @param  string  $controller
	 * @param  string  $method
	 * @return mixed
	 */
	public function dispatch(Route $route, Request $request, $controller, $method)
	{
		// First we will make an instance of this controller via the IoC container instance
		// so that we can call the methods on it. We will also apply any "after" filters
		// to the route so that they will be run by the routers after this processing.
		$instance = $this->makeController($controller);

		$this->assignAfter($instance, $route, $request, $method);

		$response = $this->before($instance, $route, $request, $method);

		// If no before filters returned a response we'll call the method on the controller
		// to get the response to be returned to the router. We will then return it back
		// out for processing by this router and the after filters can be called then.
		if (is_null($response))
		{
			$response = $this->call($instance, $route, $method);
		}

		return $response;
	}

	/**
	 * Make a controller instance via the IoC container.
	 *
	 * @param  string  $controller
	 * @return mixed
	 */
	protected function makeController($controller)
	{
		Controller::setFilterer($this->filterer);

		return $this->container->make($controller);
	}

	/**
	 * Call the given controller instance method.
	 *
	 * @param  \Illuminate\Routing\Controller  $instance
	 * @param  \Illuminate\Routing\Route  $route
	 * @param  string  $method
	 * @return mixed
	 */
	protected function call($instance, $route, $method)
	{
		$parameters = $route->parametersWithoutNulls();

		return $instance->callAction($method, $parameters);
	}

	/**
	 * Call the "before" filters for the controller.
	 *
	 * @param  \Illuminate\Routing\Controller  $instance
	 * @param  \Illuminate\Routing\Route  $route
	 * @param  \Illuminate\Http\Request  $request
	 * @param  string  $method
	 * @return mixed
	 */
	protected function before($instance, $route, $request, $method)
	{
		foreach ($instance->getBeforeFilters() as $filter)
		{
			if ($this->filterApplies($filter, $request, $method))
			{
				// Here we will just check if the filter applies. If it does we will call the filter
				// and return the responses if it isn't null. If it is null, we will keep hitting
				// them until we get a response or are finished iterating through this filters.
				$response = $this->callFilter($filter, $route, $request);

				if ( ! is_null($response)) return $response;
			}
		}
	}

	/**
	 * Apply the applicable after filters to the route.
	 *
	 * @param  \Illuminate\Routing\Controller  $instance
	 * @param  \Illuminate\Routing\Route  $route
	 * @param  \Illuminate\Http\Request  $request
	 * @param  string  $method
	 * @return mixed
	 */
	protected function assignAfter($instance, $route, $request, $method)
	{
		foreach ($instance->getAfterFilters() as $filter)
		{
			// If the filter applies, we will add it to the route, since it has already been
			// registered on the filterer by the controller, and will just let the normal
			// router take care of calling these filters so we do not duplicate logics.
			if ($this->filterApplies($filter, $request, $method))
			{
				$route->after($this->getAssignableAfter($filter));
			}
		}
	}

	/**
	 * Get the assignable after filter for the route.
	 *
	 * @param  \Closure|string  $filter
	 * @return string
	 */
	protected function getAssignableAfter($filter)
	{
		return $filter['original'] instanceof Closure ? $filter['filter'] : $filter['original'];
	}

	/**
	 * Determine if the given filter applies to the request.
	 *
	 * @param  array  $filter
	 * @param  \Illuminate\Http\Request  $request
	 * @param  string  $method
	 * @return bool
	 */
	protected function filterApplies($filter, $request, $method)
	{
		foreach (array('Only', 'Except', 'On') as $type)
		{
			if ($this->{"filterFails{$type}"}($filter, $request, $method))
			{
				return false;
			}
		}

		return true;
	}

	/**
	 * Determine if the filter fails the "only" constraint.
	 *
	 * @param  array  $filter
	 * @param  \Illuminate\Http\Request  $request
	 * @param  string  $method
	 * @return bool
	 */
	protected function filterFailsOnly($filter, $request, $method)
	{
		if ( ! isset($filter['options']['only'])) return false;

		return ! in_array($method, (array) $filter['options']['only']);
	}

	/**
	 * Determine if the filter fails the "except" constraint.
	 *
	 * @param  array  $filter
	 * @param  \Illuminate\Http\Request  $request
	 * @param  string  $method
	 * @return bool
	 */
	protected function filterFailsExcept($filter, $request, $method)
	{
		if ( ! isset($filter['options']['except'])) return false;

		return in_array($method, (array) $filter['options']['except']);
	}

	/**
	 * Determine if the filter fails the "on" constraint.
	 *
	 * @param  array  $filter
	 * @param  \Illuminate\Http\Request  $request
	 * @param  string  $method
	 * @return bool
	 */
	protected function filterFailsOn($filter, $request, $method)
	{
		$on = array_get($filter, 'options.on');

		if (is_null($on)) return false;

		// If the "on" is a string, we will explode it on the pipe so you can set any
		// amount of methods on the filter constraints and it will still work like
		// you specified an array. Then we will check if the method is in array.
		if (is_string($on)) $on = explode('|', $on);

		return ! in_array(strtolower($request->getMethod()), $on);
	}

	/**
	 * Call the given controller filter method.
	 *
	 * @param  array  $filter
	 * @param  \Illuminate\Routing\Route  $route
	 * @param  \Illuminate\Http\Request  $request
	 * @return mixed
	 */
	protected function callFilter($filter, $route, $request)
	{
		extract($filter);

		return $this->filterer->callRouteFilter($filter, $parameters, $route, $request);
	}

}

Commits for Nextrek/Aiba_backup/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000