PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.7.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.7.0
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Http / SubstituteParameters.php

SubstituteParameters.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.7.0, at vendor/wpfluent/framework/src/WPFluent/Http/SubstituteParameters.php

77 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Framework\Http;
4
5 use Closure;
6 use ReflectionMethod;
7 use ReflectionFunction;
8 use InvalidArgumentException;
9 use FluentCommunity\Framework\Container\Util;
10 use FluentCommunity\Framework\Support\Reflector;
11 use FluentCommunity\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