Skip to content

Commit 1c3e246

Browse files
committed
update docs on the new aura/session-interface
1 parent 0935c66 commit 1c3e246

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ session segments, next-request-only ("flash") values, and CSRF tools.
77

88
### Installation
99

10-
This library requires PHP 8.1 or later. It has been tested on PHP 8.1-8.5. We recommend using the latest available version of PHP as a matter of principle. It has no userland dependencies.
10+
This library requires PHP 8.1 or later. It has been tested on PHP 8.1-8.5. We recommend using the latest available version of PHP as a matter of principle. Its only dependency is [aura/session-interface](https://packagist.org/packages/aura/session-interface), which provides the shared session and segment contracts.
1111

1212
It is installable and autoloadable via Composer as [aura/session](https://packagist.org/packages/aura/session).
1313

docs/getting-started.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ The benefit of a session segment is that we can deconflict the keys in the
5656
the segment names. With segments, different packages can use the `$_SESSION`
5757
superglobal without stepping on each other's toes.
5858

59+
To remove a single value from a _Segment_, use the `remove()` method with the key. Calling `remove()` with no argument (or `null`) removes the entire segment from `$_SESSION`.
60+
61+
```php
62+
<?php
63+
$segment->remove('foo'); // unset just the 'foo' key
64+
$segment->remove(); // unset the whole segment
65+
?>
66+
```
67+
5968
To clear all the values on a _Segment_, use the `clear()` method.
6069

6170
### Flash Values
@@ -156,6 +165,45 @@ $session = $session_factory->newInstance($_COOKIE, $delete_cookie);
156165
?>
157166
```
158167

168+
## Shared Interfaces
169+
170+
Aura.Session implements the contracts published by the standalone
171+
[aura/session-interface](https://packagist.org/packages/aura/session-interface)
172+
package. Depending on these interfaces instead of the concrete classes lets our
173+
code stay decoupled from Aura.Session, and lets it interoperate with other
174+
packages built on the same contracts (such as Aura.Auth).
175+
176+
The contracts are deliberately segregated so consumers depend only on what they
177+
use:
178+
179+
- `Aura\Session_Interface\SessionInterface` — the _Session_ manager
180+
(`start()`, `resume()`, `regenerateId()`). Implemented by `Aura\Session\Session`.
181+
- `Aura\Session_Interface\SegmentInterface` — plain read/write on a segment
182+
(`get()`, `set()`).
183+
- `Aura\Session_Interface\ManageableSegmentInterface` — whole-segment
184+
management (`getSegment()`, `clear()`, `remove()`).
185+
- `Aura\Session_Interface\FlashSegmentInterface` — flash values (`setFlash()`,
186+
`getFlash()`, `getFlashNext()`, `setFlashNow()`, `clearFlash()`,
187+
`clearFlashNow()`, `keepFlash()`).
188+
189+
The Aura.Session `Aura\Session\SegmentInterface` composes all three segment
190+
contracts, and `Aura\Session\Segment` implements it. To type-hint against the
191+
narrowest contract our code needs:
192+
193+
```php
194+
<?php
195+
use Aura\Session_Interface\SessionInterface;
196+
use Aura\Session_Interface\SegmentInterface;
197+
198+
function currentUserId(SessionInterface $session): ?int
199+
{
200+
/** @var SegmentInterface $segment */
201+
$segment = $session->getSegment('Vendor\Package\Auth');
202+
return $segment->get('user_id');
203+
}
204+
?>
205+
```
206+
159207
## Session Security
160208

161209
### Session ID Regeneration

0 commit comments

Comments
 (0)