Skip to content

Commit

Permalink
DE-75217: Add get name method for route (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtahavranek authored Dec 6, 2023
1 parent 6fbc10c commit 7838dd0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"require": {
"php": ">=7.2",
"php": ">=7.4",
"psr/http-message": "^1.0"
},
"suggest": {
Expand All @@ -30,6 +30,9 @@
},
"config": {
"sort-packages": true,
"process-timeout": 600
"process-timeout": 600,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
6 changes: 6 additions & 0 deletions src/Bridge/Slim/SlimRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ public function getCallable(): callable

return $this->route->getCallable();
}


public function getName(): ?string
{
return $this->route->getName();
}
}
6 changes: 2 additions & 4 deletions src/Bridge/Slim/SlimRouterNetteDiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ private static function createSlimRouter(Container $container, array $routes): R
throw new LogicException(sprintf('Route with pattern: "%s" must have name.', $pattern));
}

$callbackProvider = function () use ($container, $data) {
return self::getService($container, $data['service']);
};
$callbackProvider = fn() => self::getService($container, $data['service']);

$route = $router->map(
explode(self::METHOD_DELIMITER, $method),
$pattern,
new RouteCallbackAccessor($callbackProvider)
new RouteCallbackAccessor($callbackProvider),
);
$route->setName($data['name']);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Slim/SlimRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testPathFor(): void
['GET'],
'/foo/{foo}/bar/{bar}',
function (): void {
}
},
);
$route->setName('fooRoute');
$router = new SlimRouter($slimRouter);
Expand Down
3 changes: 3 additions & 0 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public function getArgument(string $name, $default = null);


public function getCallable(): callable;


public function getName(): ?string;
}

0 comments on commit 7838dd0

Please sign in to comment.