Skip to content

Commit

Permalink
fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Nov 25, 2023
1 parent 1896bf1 commit f851362
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 47 deletions.
14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -41,10 +41,10 @@ use Innmind\Router\{
Route,
Route\Variables,
};
use Innmind\Http\Message\{
use Innmind\Http\{
ServerRequest,
Response\Response,
StatusCode,
Response,
Response\StatusCode,
};
use Innmind\Filesystem\File\Content;

Expand All @@ -54,19 +54,19 @@ new class extends Http {
return $app->appendRoutes(
static fn(Routes $routes) => $routes
->add(Route::literal('GET /')->handle(
static fn(ServerRequest $request) => new Response(
static fn(ServerRequest $request) => Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent('Hello world!'),
Content::ofString('Hello world!'),
),
))
->add(Route::literal('GET /{name}')->handle(
static fn(ServerRequest $request, Variables $variables) => new Response(
static fn(ServerRequest $request, Variables $variables) => Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent("Hello {$variables->get('name')}!"),
Content::ofString("Hello {$variables->get('name')}!"),
),
)),
);
Expand Down
52 changes: 26 additions & 26 deletions docs/http.md
Expand Up @@ -59,10 +59,10 @@ use Innmind\Router\{
Route,
Route\Variables,
};
use Innmind\Http\Message\{
use Innmind\Http\{
ServerRequest,
Response\Response,
StatusCode,
Response,
Response\StatusCode,
};
use Innmind\Filesystem\File\Content;

Expand All @@ -72,19 +72,19 @@ new class extends Http {
return $app->appendRoutes(
static fn(Routes $routes) => $routes
->add(Route::literal('GET /')->handle(
static fn(ServerRequest $request) => new Response(
static fn(ServerRequest $request) => Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent('Hello world!'),
Content::ofString('Hello world!'),
),
))
->add(Route::literal('GET /{name}')->handle(
static fn(ServerRequest $request, Variables $variables) => new Response(
static fn(ServerRequest $request, Variables $variables) => Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent("Hello {$variables->get('name')}!"),
Content::ofString("Hello {$variables->get('name')}!"),
),
)),
);
Expand All @@ -104,28 +104,28 @@ use Innmind\Framework\{
Application,
};
use Innmind\Router\Route\Variables;
use Innmind\Http\Message\{
use Innmind\Http\{
ServerRequest,
Response\Response,
StatusCode,
Response,
Response\StatusCode,
};
use Innmind\Filesystem\File\Content;

new class extends Http {
protected function configure(Application $app): Application
{
return $app
->route('GET /', static fn(ServerRequest $request) => new Response(
->route('GET /', static fn(ServerRequest $request) => Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent('Hello world!'),
Content::ofString('Hello world!'),
))
->route('GET /{name}', static fn(ServerRequest $request, Variables $variables) => new Response(
->route('GET /{name}', static fn(ServerRequest $request, Variables $variables) => Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent("Hello {$variables->get('name')}!"),
Content::ofString("Hello {$variables->get('name')}!"),
));
}
};
Expand All @@ -150,8 +150,8 @@ use Innmind\Router\{
};
use Innmind\Http\Message\{
ServerRequest,
Response\Response,
StatusCode,
Response,
Response\StatusCode,
};
use Innmind\Filesystem\File\Content;

Expand All @@ -164,11 +164,11 @@ new class extends Http {
static fn() => new class {
public function __invoke(ServerRequest $request): Response
{
return new Response(
return Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent('Hello world!'),
Content::ofString('Hello world!'),
);
}
}
Expand All @@ -178,11 +178,11 @@ new class extends Http {
static fn() => new class {
public function __invoke(ServerRequest $request, Variables $variables): Response
{
return new Response(
return Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent("Hello {$variables->get('name')}!"),
Content::ofString("Hello {$variables->get('name')}!"),
);
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ use Innmind\Framework\{
use Innmind\Http\Message\{
ServerRequest,
Response,
StatusCode,
Response\StatusCode,
};

new class extends Http {
Expand All @@ -233,7 +233,7 @@ new class extends Http {
{
// use something stronger in a real app
if (!$request->headers()->contains('authorization')) {
return new Response\Response(
return Response::of(
StatusCode::unauthorized,
$request->protocolVersion(),
);
Expand Down Expand Up @@ -267,20 +267,20 @@ use Innmind\Framework\{
};
use Innmind\Http\Message\{
ServerRequest,
Response\Response,
StatusCode,
Response,
Response\StatusCode,
};
use Innmind\Filesystem\File\Content;

new class extends Http {
protected function configure(Application $app): Application
{
return $app->notFoundRequestHandler(
static fn(ServerRequest $request) => new Response(
static fn(ServerRequest $request) => Response::of(
StatusCode::notFound,
$request->protocolVersion(),
null,
Content\Line::ofContent('Page Not Found!'), // or return something more elaborated such as html
Content::ofString('Page Not Found!'), // or return something more elaborated such as html
),
);
}
Expand Down
23 changes: 9 additions & 14 deletions docs/testing.md
Expand Up @@ -13,9 +13,9 @@ use Innmind\Framework\{
};
use Innmind\OperatingSystem\Factory;
use Innmind\Http\{
Message\ServerRequest\ServerRequest,
Message\Response,
Message\Method,
ServerRequest,
Response,
Method,
ProtocolVersion,
};
use Innmind\Url\Url;
Expand All @@ -30,7 +30,7 @@ final class AppTest extends TestCase
'AMQP_URL' => 'amqp://guest:guest@localhost:5672/',
]))->map(new Kernel);

$response = $app->run(new ServerRequest(
$response = $app->run(ServerRequest::of(
Url::of('/'),
Method::get,
ProtocolVersion::v20,
Expand All @@ -50,12 +50,7 @@ use Innmind\Framework\{
Environment,
};
use Innmind\OperatingSystem\Factory;
use Innmind\Http\{
Message\ServerRequest\ServerRequest,
Message\Method,
ProtocolVersion,
};
use Innmind\Url\Url;
use Innmind\CLI\Environment\InMemory;
use PHPUnit\Framework\TestCase;

final class AppTest extends TestCase
Expand Down Expand Up @@ -102,9 +97,9 @@ use Innmind\Framework\{
};
use Innmind\OperatingSystem\Factory;
use Innmind\Http\{
Message\ServerRequest,
Message\Response,
Message\Method,
ServerRequest,
Response,
Method,
ProtocolVersion,
};
use Innmind\Url\Url;
Expand Down Expand Up @@ -145,7 +140,7 @@ final class AppTest extends TestCase
},
);

$response = $app->run(new ServerRequest\ServerRequest(
$response = $app->run(ServerRequest::of(
Url::of('/some-route/some-id'),
Method::delete,
ProtocolVersion::v20,
Expand Down

0 comments on commit f851362

Please sign in to comment.