PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.3.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.3.0
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / vendor / wpfluent / framework / src / WPFluent / Http / SubstituteParameters.php

SubstituteParameters.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.3.0, at vendor/wpfluent/framework/src/WPFluent/Http/SubstituteParameters.php

77 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\Framework\Http;
4
5 use Closure;
6 use ReflectionMethod;
7 use ReflectionFunction;
8 use InvalidArgumentException;
9 use FluentBooking\Framework\Container\Util;
10 use FluentBooking\Framework\Support\Reflector;
11 use FluentBooking\Framework\Support\UrlRoutable;
12
13 trait SubstituteParameters
14 {
15 protected function substituteParameters($routeParameters)
16 {
17 $resolved = [];
18
19 $signatureParameters = $this->getParametersFromRouteAction();
20
21 if ($signatureParameters) {
22
23 foreach ($signatureParameters as $signatureParam) {
24
25 $name = $signatureParam->getName();
26
27 if ($this->boundModel($name, $signatureParam, $routeParameters)) {
28
29 $class = Util::getParameterClassName($signatureParam);
30
31 $instance = $this->app->make($class);
32
33 $resolved[$name] = $instance->resolveRouteBinding(
34 $routeParameters[$name]
35 );
36
37 unset($routeParameters[$name]);
38 }
39 }
40 }
41
42 $remainingParams = [];
43
44 $signatureParameters = array_filter($signatureParameters, function($param) {
45 return !class_exists(Reflector::getParameterClassName($param) ?: '');
46 });
47
48 foreach ($routeParameters as $param) {
49 if ($dep = array_shift($signatureParameters)) {
50 $remainingParams[$dep->getName()] = $param;
51 }
52 }
53
54 return $resolved + $remainingParams;
55 }
56
57 protected function boundModel($name, $parameter, $routeParameters)
58 {
59 if (array_key_exists($name, $routeParameters)) {
60 return Reflector::isParameterSubclassOf(
61 $parameter, UrlRoutable::class
62 );
63 }
64 }
65
66 protected function getParametersFromRouteAction()
67 {
68 if ($this->action instanceof Closure) {
69 return (new ReflectionFunction($this->action))->getParameters();
70 }
71
72 list($class, $method) = explode('@', $this->action);
73
74 return (new ReflectionMethod($class, $method))->getParameters();
75 }
76 }
77