hansott/psr7-cookies
Add and manage HTTP cookies on PSR-7 responses with a simple SetCookie helper. Create custom cookies, delete cookies, set long-lived cookies, or set cookies that expire at a specific time, then attach them to any Psr\Http\Message\ResponseInterface.
Psr\Http\Message\MessageInterface), making it a natural fit for Laravel (v8+) and modern PHP frameworks that adhere to PSR standards. Laravel’s built-in HTTP layer (e.g., Illuminate\Http\Request, Illuminate\Http\Response) is PSR-7 compatible, ensuring seamless integration.Illuminate\Cookie\CookieJar) abstracts cookie logic, but this package provides a PSR-7-centric approach, which could be valuable for:
Request/Response objects extend PSR-7 interfaces, but the package may require explicit casting (e.g., (new \hansott\Psr7Cookies\CookieJar())->setCookie()) to avoid conflicts with Laravel’s CookieJar.psr/http-message or symfony/http-foundation (if Laravel’s Illuminate\Http pulls in conflicting implementations).composer require with --prefer-stable and test in a sandbox environment.CookieJar.Request::cookie() in favor of PSR-7 methods)?CookieJar?Illuminate\Cookie\CookieJar::make() for critical paths.actingAs(), withCookie())?Laravel Version:
symfony/http-foundation).fruitcake/laravel-psr7).Component Placement:
| Layer | Integration Strategy | Example Use Case |
|---|---|---|
| Middleware | Wrap hanott/psr7-cookies around PSR-7 logic. |
Inject cookies into API responses before Laravel processes them. |
| HTTP Clients | Use with Guzzle/Psr7 clients for outbound requests. | Modify cookies in requests to external services. |
| Testing | Replace Laravel’s MockRequest with PSR-7 messages. |
Test cookie behavior in isolation. |
| Service Containers | Bind the package to Laravel’s container. | Share cookie logic across services. |
Dependencies:
psr/http-message and symfony/http-foundation versions are compatible with Laravel’s constraints (check composer why-not).composer.json snippet:
"require": {
"hansott/psr7-cookies": "^1.0",
"psr/http-message": "^1.0", // Aligned with Laravel’s symfony/http-foundation
}
hansott/psr7-cookies for setting a custom header.Request::cookie() with PSR-7 methods in new code first.CookiePsr7::set()) for backward compatibility.CookieJar in a PSR-7 adapter (e.g., Psr7CookieAdapter).class Psr7CookieAdapter implements Psr\Http\Message\RequestInterface {
use Psr7CookieTrait;
public function withCookie(Cookie $cookie) {
return $this->request->withCookie($cookie);
}
}
Symfony\Component\HttpFoundation\Cookie, which may differ from the package’s format.hansott/psr7-cookies.Request::cookie() in critical paths.CookieJar.CookieJar and hansott/psr7-cookies could increase complexity.How can I help you explore Laravel packages today?