/** * @param $controllerAction ControllerActionInfo * @param $params array * @return ActionResult */ public static function Execute(ControllerActionInfo $controllerAction, $params) { return $controllerAction->Execute($params); }
private function GetParametersFor(ControllerActionInfo $controllerActionInfo, $urlParts) { $methodInfo = $controllerActionInfo->GetMethodInfo(); $params = $methodInfo->getParameters(); $arguments = []; foreach ($params as $param) { $name = $param->getName(); $optional = $param->isOptional(); $type = $param->getClass(); if ($type != null) { //build from POST data $typeName = $type->name; $vm = new $typeName(); $classInfo = new \ReflectionClass($typeName); $properties = $classInfo->getProperties(); foreach ($properties as $property) { $propertyName = ltrim($property->getName(), '_'); if (isset($_POST[$propertyName])) { $property->setValue($vm, $_POST[$propertyName]); } } $arguments[] = $vm; } elseif (isset($_POST[$name])) { $arguments[] = $_POST[$name]; } elseif (!empty($urlParts)) { $arguments[] = array_shift($urlParts); } elseif (!$optional) { throw new \Exception(sprintf("Can't provide argument for action method %s, for parameter %s", $methodInfo->getName(), $name)); } } return $arguments; }