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
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ composer require innmind/http-session
```php
use Innmind\HttpSession\Manager\Native;
use Innmind\Http\{
Message\Response\Response,
Message\ServerRequest,
Message\StatusCode,
Response,
Response\StatusCode,
ServerRequest,
Headers,
Header\SetCookie,
Header\CookieParameter\HttpOnly,
Header\CookieParameter\Domain,
Header\Parameter\Parameter,
Header\SetCookie\Directive,
Header\SetCookie\Domain,
};

$manager = Native::of();
Expand All @@ -39,18 +38,20 @@ $session = $manager->start($request)->match(
// inject some data in the session
$manager->save($session);

$response = new Response(
$code = StatusCode::ok,
$response = Response::of(
StatusCode::ok,
$request->protocolVersion(),
Headers::of(
SetCookie::of(
new Parameter($session->name()->toString(), $session->id()->toString()),
new HttpOnly,
new Domain($request->url()->authority()->host()),
$session->name()->toString(),
$session->id()->toString(),
Directive::httpOnly,
Domain::of($request->url()->authority()->host()),
),
),
);
// send the response
```

**Note**: you should take a look at [`innmint/http-server`](https://github.com/Innmind/HttpServer) in order to know how to have access to an instance of `ServerRequest` and send the `Response`.
> [!NOTE]
> You should take a look at [`innmind/http-server`](https://github.com/Innmind/HttpServer) in order to know how to have access to an instance of `ServerRequest` and send the `Response`.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
},
"require": {
"php": "~8.2",
"innmind/immutable": "~4.9|~5.0",
"innmind/http": "~7.0",
"innmind/validation": "~1.0"
"innmind/foundation": "~1.3"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 3 additions & 6 deletions src/Manager/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
use Innmind\Http\{
ServerRequest,
Header\Cookie,
Header\CookieValue,
};
use Innmind\Validation\Is;
use Innmind\Url\Path;
use Innmind\Immutable\{
Map,
Sequence,
Maybe,
SideEffect,
};
Expand Down Expand Up @@ -137,10 +135,9 @@ private function configureSessionId(ServerRequest $request): void
}

$sessionName = \session_name();
/** @var Sequence<CookieValue> */
$values = Sequence::of(...$cookie->values()->toList());
$_ = $values
->flatMap(static fn($value) => $value->parameters()->values())
$_ = $cookie
->parameters()
->values()
->find(static fn($parameter) => $parameter->name() === $sessionName)
->match(
static fn($parameter) => \session_id($parameter->value()),
Expand Down
Loading