jupitern / slim3-skeleton

Slim3 skeleton (http + cli) with some add-ons out of the box
44 stars 12 forks source link

app->resolveRoute incomplete #1

Closed marcelloh closed 7 years ago

marcelloh commented 7 years ago

I was wondering how you solved "Dynamic routing" and saw incomplete code. My advice is to have codeception tests, or phpunit tests to check ever part of the program

I also think there is things double:

$class = new \ReflectionClass($namespace.'\\'.$className);

if (!$class->isInstantiable() || !$class->hasMethod($methodName)) {
    $handler = $this->getContainer()['notFoundHandler'];
    return $handler($this->getContainer()['request'], $this->getContainer()['response']);
}

with the line that follow:

$controllerObj = $this->resolve($namespace."\\{$className}");
jupitern commented 7 years ago

What do you mean by incomplete code? I can refactor to the code bellow:

$response = $this->resolve('response');

$class = new \ReflectionClass($namespace.'\\'.$className);

if (!$class->isInstantiable() || !$class->hasMethod($methodName)) {
    $handler = $this->getContainer()['notFoundHandler'];
    return $handler($this->getContainer()['request'], $this->getContainer()['response']);
}

$method = $class->getMethod($methodName);
$constructorArgs = $this->resolveDependencies($class->getConstructor()->getParameters());
$methodArgs = $this->resolveDependencies($method->getParameters(), $requestParams);

$ret = $method->invokeArgs($class->newInstanceArgs($constructorArgs), $methodArgs);
marcelloh commented 7 years ago

incomplete code: completely my fault: somehow (when I copy-pasted some code, one of the end-tags was missing, resulting in some strange format in my phpstorm.

The resolve function does also do a part that you do in the resolveRoute function, that's what I noticed.