Skip to content

Commit

Permalink
Merge branch 'next' into develop
Browse files Browse the repository at this point in the history
* next:
  update documentation
  remove unused exception
  make Native constructor private
  Session\Id and Session\Name constructors are now private
  make the Session immutable
  add Session::maybe()
  make Session constructor private
  use mixed type instead of annotation
  update dependencies
  change email
  test against php 8.2
  use ramsey/composer-install
  use CS 2
  require php 8.1
  • Loading branch information
Baptouuuu committed Jan 14, 2023
2 parents a78ad58 + 96b21e6 commit dac7ad6
Show file tree
Hide file tree
Showing 20 changed files with 372 additions and 363 deletions.
47 changes: 10 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['7.4', '8.0']
php-version: ['8.1', '8.2']
name: 'PHPUnit'
steps:
- name: Checkout
Expand All @@ -20,17 +20,8 @@ jobs:
extensions: mbstring, intl
coverage: xdebug
ini-values: xdebug.max_nesting_level=2048
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: Composer
uses: "ramsey/composer-install@v2"
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
- uses: codecov/codecov-action@v1
Expand All @@ -40,7 +31,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4', '8.0']
php-version: ['8.1', '8.2']
name: 'Psalm'
steps:
- name: Checkout
Expand All @@ -50,24 +41,15 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: Composer
uses: "ramsey/composer-install@v2"
- name: Psalm
run: vendor/bin/psalm --shepherd
cs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4']
php-version: ['8.1']
name: 'CS'
steps:
- name: Checkout
Expand All @@ -77,16 +59,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-${{ matrix.php-version }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: Composer
uses: "ramsey/composer-install@v2"
- name: CS
run: vendor/bin/php-cs-fixer fix --diff --dry-run --diff-format udiff
run: vendor/bin/php-cs-fixer fix --diff --dry-run
File renamed without changes.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Changelog

## [Unreleased]

### Added

- `Innmind\HttpSession\Session::maybe()`

### Changed

- `Innmind\HttpSession\Manager\Native` constructor is now private, use `::of()` named constructor instead
- `Innmind\HttpSession\Session` is now immutable
- `Innmind\HttpSession\Session\Id` is now immutable
- `Innmind\HttpSession\Session\Name` is now immutable
- `Innmind\HttpSession\Sesssion::set()` has been renamed to `::with()`
- `Innmind\HttpSession\Manager::start()` now returns `Innmind\Immutable\Maybe<Innmind\HttpSession\Session>` instead of throwing
- `Innmind\HttpSession\Manager::save()`
- now expects the `Session` instead of the `Innmind\Http\Message\ServerRequest`
- now returns `Innmind\Immutable\Maybe<Innmind\Immutable\SideEffect>` instead of throwing
- `Innmind\HttpSession\Manager::close()`
- now expects the `Session` instead of the `Innmind\Http\Message\ServerRequest`
- now returns `Innmind\Immutable\Maybe<Innmind\Immutable\SideEffect>` instead of throwing
- Require php 8.1

### Removed

- `Innmind\HttpSession\Manager::get()`
- `Innmind\HttpSession\Manager::contains()`
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Library to manage session for http requests.

The goal is to break the paradigm of considering the request and response as a global environment. Request and response should be delt as transiting data. The session for a request should obey this principle as well, thus the signature `Manager::start(ServerRequest): Session`.
The goal is to break the paradigm of considering the request and response as a global environment. Request and response should be delt as transiting data. The session for a request should obey this principle as well, thus the signature `Manager::start(ServerRequest): Maybe<Session>`.

## Installation

Expand All @@ -20,6 +20,7 @@ composer require innmind/http-session
use Innmind\HttpSession\Manager\Native;
use Innmind\Http\{
Message\Response\Response,
Message\ServerRequest,
Message\StatusCode,
Headers,
Header\SetCookie,
Expand All @@ -29,15 +30,17 @@ use Innmind\Http\{
};

$manager = new Native;
$request = /* an instance of Innmind\Http\Message\ServerRequest */
$request = /* an instance of ServerRequest */

$session = $manager->start($request);
$session = $manager->start($request)->match(
static fn($session) => $session,
static fn() => throw new \RuntimeException('Unable to start the exception'),
);
// inject some data in the session
$manager->save($request);
$manager->save($session);

$response = new Response(
$code = StatusCode::of('OK'),
$code->associatedReasonPhrase(),
$code = StatusCode::ok,
$request->protocolVersion(),
Headers::of(
SetCookie::of(
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"authors": [
{
"name": "Baptiste Langlade",
"email": "langlade.baptiste@gmail.com"
"email": "baptiste.langlade@hey.com"
}
],
"support": {
"issues": "http://github.com/Innmind/HttpSession/issues"
},
"require": {
"php": "~7.4|~8.0",
"innmind/immutable": "~3.5",
"innmind/http": "~4.2"
"php": "~8.1",
"innmind/immutable": "~4.9",
"innmind/http": "~5.3"
},
"autoload": {
"psr-4": {
Expand All @@ -33,6 +33,6 @@
"require-dev": {
"phpunit/phpunit": "~9.0",
"vimeo/psalm": "~4.4",
"innmind/coding-standard": "^1.1"
"innmind/coding-standard": "~2.0"
}
}
8 changes: 0 additions & 8 deletions src/Exception/ConcurrentSessionNotSupported.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/DomainException.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/FailedToCloseSession.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/FailedToSaveSession.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/FailedToStartSession.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/RuntimeException.php

This file was deleted.

23 changes: 18 additions & 5 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@
namespace Innmind\HttpSession;

use Innmind\Http\Message\ServerRequest;
use Innmind\Immutable\{
Maybe,
SideEffect,
};

interface Manager
{
public function start(ServerRequest $request): Session;
public function get(ServerRequest $request): Session;
public function contains(ServerRequest $request): bool;
public function save(ServerRequest $request): void;
public function close(ServerRequest $request): void;
/**
* @return Maybe<Session>
*/
public function start(ServerRequest $request): Maybe;

/**
* @return Maybe<SideEffect>
*/
public function save(Session $session): Maybe;

/**
* @return Maybe<SideEffect>
*/
public function close(Session $session): Maybe;
}

0 comments on commit dac7ad6

Please sign in to comment.