src/PeekAndPoke/Aviator/Mvc/EndpointInvoker.php
public function invoke(Container $container)
    {
        $controller = $container->get($this->route->getControllerId());

        // TODO: check for null ?

        // TODO: move this into the converter registry

        $reflect      = new \ReflectionClass($controller);
        $method       = $reflect->getMethod($this->route->getControllerMethod());
        $methodParams = $method->getParameters();

        $callParams = [];

        foreach ($methodParams as $methodParam) {

            $methodParamName = $methodParam->getName();
            // do we get something from the matched parameters?
            $input = $this->params[$methodParamName] ?? null;
            // use is as the default that will be passed to the method
            $callParams[$methodParamName] = $input;

            // do we need to convert the thing
            if ($methodParam->getClass()) {

                // find the converter that handle the param type
                $paramClass     = $methodParam->getClass();
                $converterToUse = null;

                // find the first converter that can do it
                foreach ($this->converterRegistry->getConverters() as $converter) {
                    if ($converter->canHandle($paramClass)) {
                        $converterToUse = $converter;
                        break;
                    }
                }

                if ($converterToUse) {
                    // convert the input
                    $converted = $converterToUse->fromRequest($paramClass, $input);

                    // if we got nothing, does the parameter allow a null ?
                    if ($converted === null && ! $methodParam->isOptional() && ! $methodParam->allowsNull()) {
                        throw (new HttpNotFound())->setInfo("Could not find {$paramClass->getName()}::$input");
                    }

                    $callParams[$methodParamName] = $converted;
                } else {
                    throw (new HttpInternalServerError())->setInfo('No converter found for ' . $paramClass->getName());
                }
            }
        }

        return $method->invokeArgs($controller, $callParams);
    }
public function invoke(Container $container)
    {
        $controller = $container->get($this->route->getControllerId());

        // TODO: check for null ?

        // TODO: move this into the converter registry

        $reflect      = new \ReflectionClass($controller);
        $method       = $reflect->getMethod($this->route->getControllerMethod());
        $methodParams = $method->getParameters();

        $callParams = [];

        foreach ($methodParams as $methodParam) {

            $methodParamName = $methodParam->getName();
            // do we get something from the matched parameters?
            $input = $this->params[$methodParamName] ?? null;
            // use is as the default that will be passed to the method
            $callParams[$methodParamName] = $input;

            // do we need to convert the thing
            if ($methodParam->getClass()) {

                // find the converter that handle the param type
                $paramClass     = $methodParam->getClass();
                $converterToUse = null;

                // find the first converter that can do it
                foreach ($this->converterRegistry->getConverters() as $converter) {
                    if ($converter->canHandle($paramClass)) {
                        $converterToUse = $converter;
                        break;
                    }
                }

                if ($converterToUse) {
                    // convert the input
                    $converted = $converterToUse->fromRequest($paramClass, $input);

                    // if we got nothing, does the parameter allow a null ?
                    if ($converted === null && ! $methodParam->isOptional() && ! $methodParam->allowsNull()) {
                        throw (new HttpNotFound())->setInfo("Could not find {$paramClass->getName()}::$input");
                    }

                    $callParams[$methodParamName] = $converted;
                } else {
                    throw (new HttpInternalServerError())->setInfo('No converter found for ' . $paramClass->getName());
                }
            }
        }

        return $method->invokeArgs($controller, $callParams);
    }
@param Container $container

@return mixed