Skip to content

Commit

Permalink
Merge pull request #100 from sunrise-php/release/v2.16.0
Browse files Browse the repository at this point in the history
v2.16.0
  • Loading branch information
fenric authored Apr 18, 2022
2 parents 13f5d0a + 88e7969 commit 38311fa
Show file tree
Hide file tree
Showing 34 changed files with 53 additions and 30 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## v2.13.0
# v2.16.0

* Supports for events using the `symfony/event-dispatcher`.
* New method: `Router::hasRoute(string):bool`.

## v2.15.0

* New middleware: `Sunrise\Http\Router\Middleware\JsonPayloadDecodingMiddleware`.

## v2.14.0

Expand All @@ -9,6 +13,6 @@
* New method: `Router::getRoutesByHostname(string):array`;
* New method: `RouterBuilder::setEventDispatcher(?EventDispatcherInterface):void`.

## v2.15.0
## v2.13.0

* New middleware: `Sunrise\Http\Router\Middleware\JsonPayloadDecodingMiddleware`.
* Supports for events using the `symfony/event-dispatcher`.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Sunrise // PHP
Copyright (c) 2018 Anatoly Nekhay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,16 @@ use Sunrise\Http\Router\Middleware\JsonPayloadDecodingMiddleware;
$router->addMiddleware(new JsonPayloadDecodingMiddleware());
```

### Get a route by name

```php
// checks if a route is exists
$router->hasRoute('foo');

// gets a route by name
$router->getRoute('foo');
```

### Get a current route

#### Through Router
Expand Down Expand Up @@ -642,9 +652,10 @@ $route->getHolder(); // return Reflector (class, method or function)

```php
$router = (new RouterBuilder)
->setContainer(null) // null or PSR-11 container instance...
->setCache(null) // null or PSR-16 cache instance... (only for descriptor loader)
->setCacheKey(null) // null or string... (only for descriptor loader)
->setEventDispatcher(...) // null or use to symfony/event-dispatcher...
->setContainer(...) // null or PSR-11 container instance...
->setCache(...) // null or PSR-16 cache instance... (only for descriptor loader)
->setCacheKey(...) // null or string... (only for descriptor loader)
->useConfigLoader([]) // array with files or directory with files...
->useDescriptorLoader([]) // array with classes or directory with classes...
->setHosts([]) //
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "sunrise/http-router",
"homepage": "https://github.com/sunrise-php/http-router",
"description": "Sunrise // HTTP router for PHP 7.1+ based on PSR-7 and PSR-15 with support for annotations/attributes and OpenAPI (Swagger) Specification",
"description": "HTTP router for PHP 7.1+ based on PSR-7 and PSR-15 with support for annotations/attributes and OpenAPI (Swagger) Specification",
"license": "MIT",
"keywords": [
"fenric",
"sunrise",
"http",
"router",
"annotations",
"request-handler",
"middlewares",
"annotations",
"attributes",
"openapi",
"swagger",
"psr-7",
"psr-15",
"php7",
"php8",
"attributes",
"php-attributes",
"swagger"
"php8"
],
"authors": [
{
Expand All @@ -28,12 +28,12 @@
],
"require": {
"php": "^7.1|^8.0",
"fig/http-message-util": "^1.1",
"psr/container": "^1.0",
"psr/http-message": "^1.0",
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"psr/simple-cache": "^1.0",
"fig/http-message-util": "^1.1"
"psr/simple-cache": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "7.5.20|9.5.0",
Expand All @@ -58,7 +58,7 @@
},
"autoload-dev": {
"psr-4": {
"Sunrise\\Http\\Router\\Tests\\Fixtures\\": "tests/fixtures/"
"Sunrise\\Http\\Router\\Tests\\": "tests/"
}
},
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ public function getAllowedMethods() : array
return array_keys($methods);
}

/**
* Checks if a route exists by the given name
*
* @return bool
*/
public function hasRoute(string $name) : bool
{
return isset($this->routes[$name]);
}

/**
* Gets a route for the given name
*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions tests/Loader/ConfigLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testLoadFile() : void
{
$loader = new ConfigLoader();

$loader->attach(__DIR__ . '/../fixtures/routes/foo.php');
$loader->attach(__DIR__ . '/../Fixtures/routes/foo.php');

$routes = $loader->load();

Expand All @@ -97,8 +97,8 @@ public function testLoadSeveralFiles() : void
$loader = new ConfigLoader();

$loader->attachArray([
__DIR__ . '/../fixtures/routes/foo.php',
__DIR__ . '/../fixtures/routes/bar.php',
__DIR__ . '/../Fixtures/routes/foo.php',
__DIR__ . '/../Fixtures/routes/bar.php',
]);

$routes = $loader->load();
Expand All @@ -116,7 +116,7 @@ public function testLoadDirectory() : void
{
$loader = new ConfigLoader();

$loader->attach(__DIR__ . '/../fixtures/routes');
$loader->attach(__DIR__ . '/../Fixtures/routes');

$routes = $loader->load();

Expand Down
2 changes: 1 addition & 1 deletion tests/Loader/DescriptorLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function testLoadSeveralAnnotatedClasses() : void
public function testLoadDirectoryWithAnnotatedClasses() : void
{
$loader = new DescriptorLoader();
$loader->attach(__DIR__ . '/../fixtures/Controllers/Annotated/Loadable');
$loader->attach(__DIR__ . '/../Fixtures/Controllers/Annotated/Loadable');

$routes = $loader->load();
$this->assertTrue($routes->has('first-loadable-annotated-controller'));
Expand Down
14 changes: 6 additions & 8 deletions tests/RouterBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function testBuild() : void
->setCache($cache)
->setCacheKey('foo')
->useConfigLoader([
__DIR__ . '/fixtures/routes/foo.php',
__DIR__ . '/fixtures/routes/bar.php',
__DIR__ . '/Fixtures/routes/foo.php',
__DIR__ . '/Fixtures/routes/bar.php',
])
->useMetadataLoader([
Fixtures\Controllers\Annotated\MinimallyAnnotatedController::class,
Expand All @@ -70,11 +70,9 @@ public function testBuild() : void
$this->assertSame($hosts, $router->getHosts());
$this->assertSame($middlewares, $router->getMiddlewares());
$this->assertSame($eventDispatcher, $router->getEventDispatcher());

$router->getRoutes('foo');
$router->getRoutes('bar');

$router->getRoutes('minimally-annotated-controller');
$router->getRoutes('maximally-annotated-controller');
$this->assertTrue($router->hasRoute('foo'));
$this->assertTrue($router->hasRoute('bar'));
$this->assertTrue($router->hasRoute('minimally-annotated-controller'));
$this->assertTrue($router->hasRoute('maximally-annotated-controller'));
}
}

0 comments on commit 38311fa

Please sign in to comment.