You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to develop an extension to the Slim-Http decorator. Unfortunately some useful properties are private. For my example, I had to change the following ones to be protected:
Once changed, I could write an extending class of \Slim\Http\Response. This new class \Slim\ExtendedHttp\Response would contain all methods of the Slim-Http library and defines additional ones (well one at the moment for proof-of-concept purposes):
declare(strict_types=1);
namespaceSlim\ExtendedHttp;
useDOMDocument;
usePsr\Http\Message\ResponseInterface;
class Response extends \Slim\Http\Response
{
/** * Note: This method is not part of the PSR-7 standard. * * @param DOMDocument $document * @param int $status The HTTP status code. * * @return Response */publicfunctionwithXml(DOMDocument$document, int$status = null): ResponseInterface
{
$response = $this->response
->withHeader('Content-Type', 'application/xml;charset=utf-8')
->withBody($this->streamFactory->createStream(
$document->C14N()
));
if ($status !== null) {
$response = $response->withStatus($status);
}
return$response;
}
}
In order to use that decorator, I needed to extend \Slim\Http\Factory\DecoratedResponseFactory too. So \Slim\ExtendedHttp\Factory\DecoratedResponseFactory would actually be the same as the Slim-Http one, but returns the extended response (defined above):
Should we change the properties mentioned at the top to be protected instead of private?
Should we add the possibility to change the value of \Slim\Factory\Psr17\SlimHttpPsr17Factory::$responseFactoryClass? That way we would not have to create a new class just to change this string.
The text was updated successfully, but these errors were encountered:
Hi there
I tried to develop an extension to the Slim-Http decorator. Unfortunately some useful properties are
private
. For my example, I had to change the following ones to beprotected
:\Slim\Http\Response::$response
\Slim\Http\Response::$streamFactory
\Slim\Http\Factory\DecoratedResponseFactory::$responseFactory
\Slim\Http\Factory\DecoratedResponseFactory::$streamFactory
Once changed, I could write an extending class of
\Slim\Http\Response
. This new class\Slim\ExtendedHttp\Response
would contain all methods of the Slim-Http library and defines additional ones (well one at the moment for proof-of-concept purposes):In order to use that decorator, I needed to extend
\Slim\Http\Factory\DecoratedResponseFactory
too. So\Slim\ExtendedHttp\Factory\DecoratedResponseFactory
would actually be the same as the Slim-Http one, but returns the extended response (defined above):Eventually my
index.php
-file became (for simplicity I declared theSlimExtendedHttpPsr17Factory
class right here):Should we change the properties mentioned at the top to be
protected
instead ofprivate
?Should we add the possibility to change the value of
\Slim\Factory\Psr17\SlimHttpPsr17Factory::$responseFactoryClass
? That way we would not have to create a new class just to change thisstring
.The text was updated successfully, but these errors were encountered: