Download the PHP package brnc/psr7-symfony1-adapter without Composer
On this page you can find all versions of the php package brnc/psr7-symfony1-adapter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package psr7-symfony1-adapter
Partial PSR-7 Adapters for Symfony 1.5
To enable the use of future-proof PSR-15 middlewares via partial PSR-7 adapters.
Quickstart
ServerRequest
Please mind the following PSR-7 violation which is enabled by default:
No immutability by default
as this is just an adapter for \sfWebRequest which cannot easily be replaced with another instance.
This adapter – by default – also returns the very same instance when calling with*() methods. For the same reason calls to methods which cannot act on and alter the underlying \sfWebRequest
will throw an \brnc\Symfony1\Message\Exception\LogicException.
This default behaviour can be changed by creating the Request using the Request::OPTION_IMMUTABLE_VIOLATION option set to false. The Request-adapter will then always return new instances when with*()-methods are called and won't throw exceptions on calls which cannot transparently act on the \sfWebRequest- object.
Response
Please mind the default to mutability!
Pass it down to a PSR-15 sub-stack
You may use the ResponseFactory implementing \Psr\Http\Message\ResponseFactoryInterface in order to "spawn" responses within your PSR-15 sub-stack.
Manually transcribe a PSR-7 Response to Symfony1
Assume you couldn't use other means, and you're confronted with an arbitrary PSR-7 response you can use the ResponseTranscriptor to copy the data from your PSR-7 response to your \sfWebResponse.
The ResponseTranscriptor by default uses NoCookieTranscriptor, which fails hard in the presence of Set-Cookie' headers.
Incorporating (present-day) Cookies into the \sfWebResponse is not strait-forward. However, you are free to implement your own Cookie-Handler implementing CookieTranscriptorInterface and pass it as an optional constructor argument.
Implemented CookieTranscriptorInterfaces
There are a few CookieTranscriptors already implemented; each come with their specific compromises.
CookieHeaderTranscriptor
Transcribes Set-Cookie headers from your PSR-7 response, into the cookie management of the Symfony1 response.
This comes with all downsides of the legacy signature of setrawcookie(). Foremost it's not supporting SameSite-attribute, nor everything else being extension-av as of RFC 265.
AbstractCookieDispatchTranscriptor
The (abstract) CookieDispatchTranscriptor uses reflection and swaps the response's EventDispatcher against a new one.
It is very tied against the original implementation of sfWebResponse::sendHttpHeaders especially its logging mechanism via events.
The CookieDispatcher puts itself between sfWebResponse and the original sfEventDispatcher, and fires the cookies from the PSR-7 response right before Symfony1 would have sent theirs.
You need to implement AbstractCookieDispatchTranscriptor's transcribeCookies() method, depending on your source for the cookies being set. E.g. if your using a 3rd party library.
Your code eventually needs to return CookieContainerInterface full of CookieInterfaces. There is already a HeaderCookie, that uses header() and expects an already crafted and complete Set-Cookie-headerline.
There are also SetCookie and SetRawCookie which will use the respective methods with the new signature – i.e. three arguments, with the options-array as a third one.
Pass it down to http-foundation i.e. present-day Symfony
Combine this PSR7-Symfony1 Adapter and symfony/psr-http-message-bridge to connect your Symfony1 stack via PSR-7 to symfony/http-foundation objects and leverage using embedded (present-day) Symfony components.
All versions of psr7-symfony1-adapter with dependencies
guzzlehttp/psr7 Version ^2.4.5
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0
webmozart/assert Version ^1.11