Skip to content

Commit

Permalink
Merge pull request #23 from abbadon1334/refactor-route-handlers
Browse files Browse the repository at this point in the history
Refactor route handlers
  • Loading branch information
abbadon1334 committed Jul 31, 2019
2 parents 240386e + 1e28f1e commit 86594f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Route/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,16 @@ private static function getHandlerFromArray(array $array): iOnRoute
$first_element = $array[0];
$second_element = $array[1] ?? null;

if (null === $second_element) {
return new RoutedCallable(...$array);
}
switch (true) {

if (is_string($second_element)) {
return RoutedMethod::fromArray($array);
}
case is_callable($first_element):
return new RoutedCallable($first_element);

switch (true) {
case is_string($first_element) && is_string($second_element):
return RoutedMethod::fromArray($array);

case is_a($first_element, RoutedServeStatic::class, true):
return RoutedServeStatic::fromArray($array);
return RoutedServeStatic::fromArray($second_element);

case is_a($first_element, jsExpressionable::class, true):
return RoutedUI::fromArray($array);
Expand Down
1 change: 1 addition & 0 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function dataProviderTestDemos()
];

$cases = [
['GET', '/callable', 200, false],
['GET', '/callable', 200, false],
['GET', '/test', 200, false],
['GET', '/testStatic', 200, false],
Expand Down

0 comments on commit 86594f9

Please sign in to comment.