From c282f4b26d36687b3c4f2eaa289a7c37f7ca3050 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Feb 2026 20:13:15 +0100 Subject: [PATCH 1/2] remove server request environment --- CHANGELOG.md | 6 ++ src/Factory/Environment/Native.php | 39 --------- src/Factory/EnvironmentFactory.php | 46 ----------- src/Factory/ServerRequestFactory.php | 5 -- src/ServerRequest.php | 10 --- src/ServerRequest/Environment.php | 79 ------------------- .../Environment/EnvironmentFactoryTest.php | 22 ------ .../ServerRequestFactoryTest.php | 4 - tests/ServerRequest/EnvironmentTest.php | 74 ----------------- tests/ServerRequest/StringableTest.php | 2 - tests/ServerRequestTest.php | 7 -- 11 files changed, 6 insertions(+), 288 deletions(-) delete mode 100644 src/Factory/Environment/Native.php delete mode 100644 src/Factory/EnvironmentFactory.php delete mode 100644 src/ServerRequest/Environment.php delete mode 100644 tests/Factory/Environment/EnvironmentFactoryTest.php delete mode 100644 tests/ServerRequest/EnvironmentTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b50c43a..6ea62b50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ - Requires `innmind/time:~1.0` - `Innmind\Http\TimeContinuum\Format\Http` has been moved to `Innmind\Http\Time\Format\Http` +### Removed + +- `Innmind\Http\ServerRequest::environment()` +- `Innmind\Http\ServerRequest\Environment` +- `Innmind\Http\Factory\EnvironmentFactory` + ## 8.0.0 - 2025-04-20 ### Added diff --git a/src/Factory/Environment/Native.php b/src/Factory/Environment/Native.php deleted file mode 100644 index 315c2de4..00000000 --- a/src/Factory/Environment/Native.php +++ /dev/null @@ -1,39 +0,0 @@ - $env - */ - private function __construct( - private array $env, - ) { - } - - public function __invoke(): Environment - { - /** @var Map */ - $map = Map::of(); - - foreach ($this->env as $name => $value) { - $map = ($map)($name, $value); - } - - return Environment::of($map); - } - - public static function new(): self - { - return new self(\getenv()); - } -} diff --git a/src/Factory/EnvironmentFactory.php b/src/Factory/EnvironmentFactory.php deleted file mode 100644 index 9f417e7c..00000000 --- a/src/Factory/EnvironmentFactory.php +++ /dev/null @@ -1,46 +0,0 @@ -implementation)(); - } - - #[\NoDiscard] - public static function native(): self - { - return new self(Native::new()); - } - - /** - * @psalm-pure - * - * @param pure-Closure(): Environment $factory - */ - #[\NoDiscard] - public static function of(\Closure $factory): self - { - return new self($factory); - } -} diff --git a/src/Factory/ServerRequestFactory.php b/src/Factory/ServerRequestFactory.php index 7cb41ff5..2179d46e 100644 --- a/src/Factory/ServerRequestFactory.php +++ b/src/Factory/ServerRequestFactory.php @@ -30,7 +30,6 @@ final class ServerRequestFactory private function __construct( private HeadersFactory $headersFactory, private \Closure $bodyFactory, - private EnvironmentFactory $environmentFactory, private CookiesFactory $cookiesFactory, private QueryFactory $queryFactory, private FormFactory $formFactory, @@ -84,7 +83,6 @@ public function __invoke(): ServerRequest ), ($this->headersFactory)(), ($this->bodyFactory)(), - ($this->environmentFactory)(), ($this->cookiesFactory)(), ($this->queryFactory)(), ($this->formFactory)(), @@ -112,7 +110,6 @@ public static function native( ->streams() ->acquire(\fopen('php://input', 'r')), ), - EnvironmentFactory::native(), CookiesFactory::native(), QueryFactory::native(), FormFactory::native(), @@ -131,7 +128,6 @@ public static function native( public static function of( HeadersFactory $headersFactory, \Closure $bodyFactory, - EnvironmentFactory $environmentFactory, CookiesFactory $cookiesFactory, QueryFactory $queryFactory, FormFactory $formFactory, @@ -141,7 +137,6 @@ public static function of( return new self( $headersFactory, $bodyFactory, - $environmentFactory, $cookiesFactory, $queryFactory, $formFactory, diff --git a/src/ServerRequest.php b/src/ServerRequest.php index 2a0beb1a..2264002b 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -4,7 +4,6 @@ namespace Innmind\Http; use Innmind\Http\{ - ServerRequest\Environment, ServerRequest\Cookies, ServerRequest\Query, ServerRequest\Form, @@ -24,7 +23,6 @@ private function __construct( private ProtocolVersion $protocolVersion, private Headers $headers, private Content $body, - private Environment $environment, private Cookies $cookies, private Query $query, private Form $form, @@ -42,7 +40,6 @@ public static function of( ProtocolVersion $protocolVersion, ?Headers $headers = null, ?Content $body = null, - ?Environment $environment = null, ?Cookies $cookies = null, ?Query $query = null, ?Form $form = null, @@ -54,7 +51,6 @@ public static function of( $protocolVersion, $headers ?? Headers::of(), $body ?? Content::none(), - $environment ?? Environment::of(), $cookies ?? Cookies::of(), $query ?? Query::of([]), $form ?? Form::of([]), @@ -92,12 +88,6 @@ public function method(): Method return $this->method; } - #[\NoDiscard] - public function environment(): Environment - { - return $this->environment; - } - #[\NoDiscard] public function cookies(): Cookies { diff --git a/src/ServerRequest/Environment.php b/src/ServerRequest/Environment.php deleted file mode 100644 index 2b191dd5..00000000 --- a/src/ServerRequest/Environment.php +++ /dev/null @@ -1,79 +0,0 @@ - $variables - */ - private function __construct(private Map $variables) - { - } - - /** - * @psalm-pure - * - * @param Map|null $variables - */ - #[\NoDiscard] - public static function of(?Map $variables = null): self - { - return new self($variables ?? Map::of()); - } - - /** - * @return Maybe - */ - #[\NoDiscard] - public function get(string $name): Maybe - { - return $this->variables->get($name); - } - - #[\NoDiscard] - public function contains(string $name): bool - { - return $this->variables->contains($name); - } - - /** - * @param callable(string, string): void $function - */ - #[\NoDiscard] - public function foreach(callable $function): SideEffect - { - return $this->variables->foreach($function); - } - - /** - * @template R - * - * @param R $carry - * @param callable(R, string, string): R $reducer - * - * @return R - */ - #[\NoDiscard] - public function reduce($carry, callable $reducer) - { - return $this->variables->reduce($carry, $reducer); - } - - #[\Override] - #[\NoDiscard] - public function count(): int - { - return $this->variables->size(); - } -} diff --git a/tests/Factory/Environment/EnvironmentFactoryTest.php b/tests/Factory/Environment/EnvironmentFactoryTest.php deleted file mode 100644 index 9b25d3b3..00000000 --- a/tests/Factory/Environment/EnvironmentFactoryTest.php +++ /dev/null @@ -1,22 +0,0 @@ -assertInstanceOf(Environment::class, $e); - } -} diff --git a/tests/Factory/ServerRequest/ServerRequestFactoryTest.php b/tests/Factory/ServerRequest/ServerRequestFactoryTest.php index dfcf983b..703e9e36 100644 --- a/tests/Factory/ServerRequest/ServerRequestFactoryTest.php +++ b/tests/Factory/ServerRequest/ServerRequestFactoryTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Factory\ServerRequestFactory, Factory\HeadersFactory, - Factory\EnvironmentFactory, Factory\CookiesFactory, Factory\QueryFactory, Factory\FormFactory, @@ -34,7 +33,6 @@ public function testMake() $f = ServerRequestFactory::of( HeadersFactory::of(static fn() => Headers::of()), static fn() => Content::none(), - EnvironmentFactory::of(static fn() => Environment::of()), CookiesFactory::of(static fn() => Cookies::of()), QueryFactory::of(static fn() => Query::of([])), FormFactory::of(static fn() => Form::of([])), @@ -58,7 +56,6 @@ public function testMakeWithUser() $factory = ServerRequestFactory::of( HeadersFactory::of(static fn() => Headers::of()), static fn() => Content::none(), - EnvironmentFactory::of(static fn() => Environment::of()), CookiesFactory::of(static fn() => Cookies::of()), QueryFactory::of(static fn() => Query::of([])), FormFactory::of(static fn() => Form::of([])), @@ -83,7 +80,6 @@ public function testMakeWithUserAndPassword() $factory = ServerRequestFactory::of( HeadersFactory::of(static fn() => Headers::of()), static fn() => Content::none(), - EnvironmentFactory::of(static fn() => Environment::of()), CookiesFactory::of(static fn() => Cookies::of()), QueryFactory::of(static fn() => Query::of([])), FormFactory::of(static fn() => Form::of([])), diff --git a/tests/ServerRequest/EnvironmentTest.php b/tests/ServerRequest/EnvironmentTest.php deleted file mode 100644 index 0b2502f3..00000000 --- a/tests/ServerRequest/EnvironmentTest.php +++ /dev/null @@ -1,74 +0,0 @@ -assertTrue($f->contains('foo')); - $this->assertFalse($f->contains('bar')); - $this->assertSame('42', $f->get('foo')->match( - static fn($foo) => $foo, - static fn() => null, - )); - $this->assertSame(1, $f->count()); - } - - public function testReturnNothingWhenAccessingUnknownVariable() - { - $this->assertNull(Environment::of()->get('foo')->match( - static fn($foo) => $foo, - static fn() => null, - )); - } - - public function testForeach() - { - $variables = Environment::of( - Map::of() - ('foo', '42') - ('bar', 'baz'), - ); - - $called = 0; - $this->assertInstanceOf( - SideEffect::class, - $variables->foreach(static function() use (&$called) { - ++$called; - }), - ); - $this->assertSame(2, $called); - } - - public function testReduce() - { - $variables = Environment::of( - Map::of() - ('foo', '42') - ('bar', 'baz'), - ); - - $reduced = $variables->reduce( - [], - static function($carry, $name, $value) { - $carry[] = $name; - $carry[] = $value; - - return $carry; - }, - ); - - $this->assertSame(['foo', '42', 'bar', 'baz'], $reduced); - } -} diff --git a/tests/ServerRequest/StringableTest.php b/tests/ServerRequest/StringableTest.php index 622527a3..9b117b84 100644 --- a/tests/ServerRequest/StringableTest.php +++ b/tests/ServerRequest/StringableTest.php @@ -58,7 +58,6 @@ public function testIntegrateQuery() ), Content::ofString('some body'), null, - null, Query::of([ 'foo' => 'bar', 'bar' => '42', @@ -91,7 +90,6 @@ public function testIntegrateFormWhenNoBody() null, null, null, - null, Form::of([ 'foo' => 'bar', 'bar' => '42', diff --git a/tests/ServerRequestTest.php b/tests/ServerRequestTest.php index 7c25d7b1..7f7359c1 100644 --- a/tests/ServerRequestTest.php +++ b/tests/ServerRequestTest.php @@ -8,7 +8,6 @@ ProtocolVersion, Headers, Method, - ServerRequest\Environment, ServerRequest\Cookies, ServerRequest\Query, ServerRequest\Form, @@ -28,7 +27,6 @@ public function testInterface() $protocol = ProtocolVersion::v20, $headers = Headers::of(), $body = Content::none(), - $env = Environment::of(), $cookies = Cookies::of(), $query = Query::of([]), $form = Form::of([]), @@ -40,7 +38,6 @@ public function testInterface() $this->assertSame($protocol, $r->protocolVersion()); $this->assertSame($headers, $r->headers()); $this->assertSame($body, $r->body()); - $this->assertSame($env, $r->environment()); $this->assertSame($cookies, $r->cookies()); $this->assertSame($query, $r->query()); $this->assertSame($form, $r->form()); @@ -63,10 +60,6 @@ public function testDefaultValues() Content::class, $request->body(), ); - $this->assertInstanceOf( - Environment::class, - $request->environment(), - ); $this->assertInstanceOf( Cookies::class, $request->cookies(), From bc7b33ff8003a58adfc7643bca09e7c27e092296 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Feb 2026 20:20:49 +0100 Subject: [PATCH 2/2] CS --- tests/Factory/ServerRequest/ServerRequestFactoryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Factory/ServerRequest/ServerRequestFactoryTest.php b/tests/Factory/ServerRequest/ServerRequestFactoryTest.php index 703e9e36..7a704a7d 100644 --- a/tests/Factory/ServerRequest/ServerRequestFactoryTest.php +++ b/tests/Factory/ServerRequest/ServerRequestFactoryTest.php @@ -14,7 +14,6 @@ ServerRequest\Query, ServerRequest\Form, ServerRequest\Files, - ServerRequest\Environment, ServerRequest\Cookies, Headers, };