PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / trunk
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder vtrunk
6.2.15 6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 All 197 releases
fluentform / vendor / wpfluent / framework / src / WPFluent / Http / SubstituteParameters.php

SubstituteParameters.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder trunk, 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 FluentForm\Framework\Http;
4
5 use Closure;
6 use ReflectionMethod;
7 use ReflectionFunction;
8 use InvalidArgumentException;
9 use FluentForm\Framework\Container\Util;
10 use FluentForm\Framework\Support\Reflector;
11 use FluentForm\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