-
-
Save asgrim/0d8b1cb7a4fa362db8fed06444d104ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Note we have no $response parameter - it discourages trying to change it on the way "in" the pipe | |
$a = function a($request, $next) { | |
$realResponse = $next($request->withAttribute('yay', 'woo')); | |
return $realResponse->withHeader('X-Foo', 'foo'); | |
} | |
$b = function b($request, $next) { | |
$yay = $request->getAttribute('yay'); // woo | |
return new Response(); | |
} | |
echo $a(new Request(), $b); // Header is set correctly here \o/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = function a($request, $response, $next = null) { | |
$realResponse = $next($request->withAttribute('yay', 'woo'), $response); | |
return $realResponse->withHeader('X-Foo', 'foo'); | |
} | |
$b = function b($request, $response, $next = null) { | |
$yay = $request->getAttribute('yay'); // woo | |
return new Response(); | |
} | |
echo $a(new Request(), new Response(), $b); // Header is set correctly here \o/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = function a($request, $response, $next = null) { | |
$response = $response->withHeader('X-Foo', 'foo'); // Setting a header beforehand... works right?... no. | |
return $next($request->withAttribute('yay', 'woo'), $response); | |
} | |
$b = function b($request, $response, $next = null) { | |
$yay = $request->getAttribute('yay'); // woo | |
return new Response(); | |
} | |
echo $a(new Request(), new Response(), $b); // Header would be missing, because the response returned is a SEPARATE instance entirely |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment