getParameters(); $docs = new LuMethodDocParser($reflect->getDocComment()); $docs->parse(); $args = []; foreach ($params as $param) { try { $value = null; if (array_key_exists($param->getName(), $parameters)) { $value = static::getParam($param, $parameters[$param->getName()]); } else if ($param->isOptional()) { $value = $param->getDefaultValue(); } else { throw new LuDboDeserializeException("Missing parameter '" . $param->getName() . "'", 400); } if (array_key_exists($param->getName(), $docs->getParams())) { $doc = $docs->getParams()[$param->getName()]; if (is_null($value) && $doc->isNotNull()) { throw new LuDboConstraintException("Parameter '" . $param->getName() . "' can not be null", 400); } if (!is_null($value)) { $value->checkConstraints($doc->getConstraints()); } } $args[$param->getName()] = $value; } catch (LuDboConstraintException $e) { $paramName = $param->getName(); throw new LuBusinessException("Invalid value for '${paramName}': " . $e->getMessage(), 400, $e); } catch (LuDboDeserializeException $e) { $paramName = $param->getName(); throw new LuBusinessException("Failed to deserialize '${paramName}': " . $e->getMessage(), 400, $e); } } $result = call_user_func_array(array($objInstance, $methodName), $args); return $result; } public static function getClassName(\ReflectionParameter $param) { preg_match('/\[\s\<\w+?>\s([\w]+)/s', $param->__toString(), $matches); return isset($matches[1]) ? $matches[1] : null; } public static function getParam(\ReflectionParameter $param, $value) { $typedValue = null; $className = static::getClassName($param); if (is_null($className)) { $typedValue = $value; } else { $class = $param->getClass(); $className = is_null($class) ? "string" : $class->getName(); try { $json = json_decode($value, true); $typedValue = LuDbo::deserializeValue($json, $className); } catch (\Exception $e) { if ($e instanceof LuDboDeserializeException || $e instanceof LuDboConstraintException) { throw $e; } throw new LuBusinessException("Unable to parse JSON value for '" . $param->getName() . "'", 400, $e); } } return $typedValue; } }