Skip to content

Commit

Permalink
update README.md and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cevin committed Mar 28, 2024
1 parent d589142 commit 06cd489
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,36 @@ class SomeController extends Controller
$b = func_get_args()[1];
$c = func_get_args()[2];
}

// For route: /{a}/{b}/{c}
// ❌ Parameter name does not match the variable name defined in the route.
public function method($aa, $bb, $cc)
{
// ....
}

// For route: /{a}/{b}/{c}
// ❗️ The number of parameters does not match the number of variables defined in the route.
public function method($a, $b)
{
$c = func_get_args()[2];
}

// For route: /{a}/{b}/{c}
// ✅
public function method($a, $b, $c)
{
// .....
}

// For route: /{a}/{b}/{c}
// ✅
public function method($c, $a, $b)
{
return $c.'-'.$a.'-'.$b;
// /a/b/c
// output: c-a-b
}
}
```

Expand Down
4 changes: 2 additions & 2 deletions src/Route/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function resolveMethodDependencies(array $parameters, ReflectionFunctionA

if ($instance !== $skippableValue) {
$arrangedParameters[$parameter->getName()] = $instance;
} else if($parameter->isDefaultValueAvailable()) {
$arrangedParameters[$parameter->getName()] = $parameter->getDefaultValue();
} else {
$arrangedParameters[$parameter->getName()] = array_key_exists($parameter->getName(), $parameters) ? $parameters[$parameter->getName()] : ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null);
}
}

Expand Down

0 comments on commit 06cd489

Please sign in to comment.