Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,33 @@

## [Unreleased]

### Added

- `Innmind\Framework\Http\Route`
- `Innmind\Framework\Http\Route\Reference`
- `Innmind\Framework\Application::mapRoute()`
- `Innmind\Framework\Application::routes(class-string<Innmind\Framework\Http\Route\Reference>)`
- `Innmind\Framework\Application::recoverRouteError()`

### Changed

- Requires `innmind/foundation:~1.9`
- Requires `innmind/di:~3.0`
- `Innmind\Framework\Application::route()` callable must now return a `Innmind\Router\Component`
- `Innmind\Framework\Application::route()` callable first parameter now is a `Innmint\Router\Pipe`
- `Innmind\Framework\Application::route()` first parameter must now be expressed via a component inside the callable
- `Innminf\Framework\Application::notFoundRequestHandler()` callable must now return an `Innmind\Immutable\Attempt<Response>`
- `Innminf\Framework\Application::notFoundRequestHandler()` has been renamed `::routeNotFound()`

### Removed

- The ability to use `string`s to reference services
- `Innmind\Framework\Http\Service`
- `Innmind\Framework\Http\To`
- `Innmind\Framework\Http\Routes`
- `Innmind\Framework\Application::appendRoutes()`
- `Innmind\Framework\Application::mapRequestHandler()`
- `Innmind\Framework\Http\RequestHandler`

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"php": "~8.2",
"innmind/foundation": "~1.9",
"innmind/di": "~3.0",
"innmind/router": "^5.0.1"
"innmind/router": "~5.2"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 6 additions & 12 deletions fixtures/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@
use Innmind\Framework\{
Application,
Main\Async\Http,
Http\Routes,
};
use Innmind\Router\{
Method,
Endpoint,
Handle,
Respond,
};
use Innmind\Router\Respond;
use Innmind\Http\Response\StatusCode;
use Innmind\Immutable\Attempt;

new class extends Http
{
protected function configure(Application $app): Application
{
return $app->appendRoutes(static fn($routes) => $routes->add(
Method::get()
->pipe(Endpoint::of('/hello'))
return $app->route(
static fn($pipe) => $pipe
->get()
->endpoint('/hello')
->pipe(Respond::with(StatusCode::ok)),
));
);
}
};
56 changes: 38 additions & 18 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

namespace Innmind\Framework;

use Innmind\Framework\Http\{
Routes,
RequestHandler,
};
use Innmind\OperatingSystem\OperatingSystem;
use Innmind\CLI\{
Environment as CliEnv,
Expand All @@ -16,7 +12,10 @@
Container,
Service,
};
use Innmind\Router\Component;
use Innmind\Router\{
Component,
Pipe,
};
use Innmind\Http\{
ServerRequest,
Response,
Expand Down Expand Up @@ -147,50 +146,71 @@ public function mapCommand(callable $map): self
/**
* @psalm-mutation-free
*
* @param literal-string $pattern
* @param callable(Container, OperatingSystem, Environment): Component<SideEffect, Response> $handle
* @param Http\Route\Reference|callable(Pipe, Container, OperatingSystem, Environment): Component<SideEffect, Response> $handle
*
* @return self<I, O>
*/
public function route(Http\Route\Reference|callable $handle): self
{
if ($handle instanceof Http\Route\Reference) {
$handle = $handle->route();
}

return new self($this->app->route($handle));
}

/**
* @psalm-mutation-free
*
* @param class-string<Http\Route\Reference> $routes
*
* @return self<I, O>
*/
public function route(string $pattern, callable $handle): self
public function routes(string $routes): self
{
return new self($this->app->route($pattern, $handle));
$self = $this;

foreach ($routes::cases() as $route) {
$self = $self->route($route);
}

return $self;
}

/**
* @psalm-mutation-free
*
* @param callable(Routes, Container, OperatingSystem, Environment): Routes $append
* @param callable(Component<SideEffect, Response>, Container): Component<SideEffect, Response> $map
*
* @return self<I, O>
*/
public function appendRoutes(callable $append): self
public function mapRoute(callable $map): self
{
return new self($this->app->appendRoutes($append));
return new self($this->app->mapRoute($map));
}

/**
* @psalm-mutation-free
*
* @param callable(RequestHandler, Container, OperatingSystem, Environment): RequestHandler $map
* @param callable(ServerRequest, Container, OperatingSystem, Environment): Attempt<Response> $handle
*
* @return self<I, O>
*/
public function mapRequestHandler(callable $map): self
public function routeNotFound(callable $handle): self
{
return new self($this->app->mapRequestHandler($map));
return new self($this->app->routeNotFound($handle));
}

/**
* @psalm-mutation-free
*
* @param callable(ServerRequest, Container, OperatingSystem, Environment): Response $handle
* @param callable(ServerRequest, \Throwable, Container): Attempt<Response> $recover
*
* @return self<I, O>
*/
public function notFoundRequestHandler(callable $handle): self
public function recoverRouteError(callable $recover): self
{
return new self($this->app->notFoundRequestHandler($handle));
return new self($this->app->recoverRouteError($recover));
}

/**
Expand Down
Loading