PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.1.0
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.1.0
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / vendor / wpfluent / framework / src / WPFluent / Http / SubstituteParameters.php

SubstituteParameters.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 2.1.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 FluentBoards\Framework\Http;
4
5 use Closure;
6 use ReflectionMethod;
7 use ReflectionFunction;
8 use InvalidArgumentException;
9 use FluentBoards\Framework\Container\Util;
10 use FluentBoards\Framework\Support\Reflector;
11 use FluentBoards\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