Blaine Schmeisser
81a2f5b919
Pass the response by reference so it can be overwritten in filters
You can edit the response but you can't overwrite it:
~~~ php
<?php
// https://gist.github.com/3896743
$response = new stdClass();
echo '1): ' . spl_object_hash($response) . PHP_EOL; // 0000000021e89fcd00000000e93b17ba
call_user_func_array(function($response) {
$response = new stdClass();
echo '2): ' . spl_object_hash($response) . PHP_EOL; // 0000000021e89fcf00000000e93b17ba
}, array($response));
echo '3): ' . spl_object_hash($response) . PHP_EOL; // 0000000021e89fcd00000000e93b17ba
call_user_func_array(function($response) {
$response = new stdClass();
echo '4): ' . spl_object_hash($response) . PHP_EOL; // 0000000021e89fcf00000000e93b17ba // hash descoped and reused
}, array(&$response));
echo '5): ' . spl_object_hash($response) . PHP_EOL; // 0000000021e89fcf00000000e93b17ba
~~~
Otherwise you'd make the new response object and overwrite the values one at a time:
~~~ php
<?php
// https://gist.github.com/3897032
Route::filter('after', function($response)
{
$params = \Laravel\Request::$route->parameters;
// The 'type' is the last param
// example: /product/(:num).(:any)
$type = array_pop($params);
if($type == 'json') {
$res = Response::json($response->content->data);
foreach($response as $key => &$value) {
$response->$key = $res->$key;
}
}
});
~~~
Signed-off-by: Blaine Schmeisser <blaine.schmeisser@vitals.com>
2012-10-16 09:12:29 -05:00
..
2012-09-20 17:54:28 -04:00
2012-08-03 18:17:48 +03:00
2012-09-10 03:37:24 -07:00
2012-10-07 12:05:01 -07:00
2012-10-11 08:14:55 +02:00
2012-10-03 00:53:20 +01:00
2012-10-16 09:12:29 -05:00
2012-08-03 18:09:37 +03:00
2012-09-25 18:37:09 -07:00
2012-05-24 11:50:48 +02:00
2012-09-28 10:10:35 +02:00
2012-05-02 16:52:55 -05:00
2012-07-27 11:29:59 +00:00
2012-09-18 17:22:45 +03:00
2012-09-01 17:26:35 -07:00
2012-05-02 16:52:55 -05:00
2012-06-13 11:19:20 -04:00
2012-09-25 16:43:58 -04:00
2012-08-13 12:17:35 -07:00
2012-04-07 14:09:22 -05:00
2012-07-31 09:55:45 +02:00
2012-09-26 16:20:56 -04:00
2012-08-03 18:17:48 +03:00
2012-07-27 11:29:59 +00:00
2012-03-23 22:54:09 -05:00
2012-09-01 17:35:34 -07:00
2012-02-23 14:02:59 -06:00
2012-10-03 15:35:34 +03:00
2012-09-14 22:21:35 +03:00
2012-09-05 16:07:20 -04:00
2012-08-09 20:44:15 -07:00
2012-07-27 11:29:59 +00:00
2012-09-15 20:48:18 -04:00
2012-09-26 10:11:24 -04:00
2012-07-20 22:20:37 +08:00
2012-05-30 08:41:03 -05:00
2012-09-11 07:48:01 +05:30
2012-08-03 18:17:48 +03:00
2012-08-13 12:17:35 -07:00
2012-07-27 11:29:59 +00:00
2012-08-03 18:17:48 +03:00
2012-08-13 12:16:08 -07:00
2012-04-10 11:37:38 -05:00
2012-06-25 13:11:54 -04:00
2012-09-10 21:11:20 +02:00
2012-06-13 11:19:20 -04:00
2012-09-01 22:07:01 -05:00
2012-08-12 12:50:10 -07:00
2012-09-26 16:20:56 -04:00