Files
ponzi/laravel
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-08-03 18:17:48 +03: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-06-13 11:19:20 -04:00
2012-09-25 16:43:58 -04: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-02-23 14:02:59 -06:00
2012-10-03 15:35:34 +03:00
2012-07-27 11:29:59 +00:00
2012-09-15 20:48:18 -04:00
2012-05-30 08:41:03 -05:00
2012-08-03 18:17:48 +03:00
2012-07-27 11:29:59 +00:00
2012-08-03 18:17:48 +03:00
2012-04-10 11:37:38 -05:00
2012-06-13 11:19:20 -04:00
2012-09-26 16:20:56 -04:00