1. 16 Oct, 2012 1 commit
    • Pass the response by reference so it can be overwritten in filters · 81a2f5b9
      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>
      Blaine Schmeisser committed
  2. 24 Jun, 2012 1 commit
  3. 13 Jun, 2012 1 commit
  4. 10 May, 2012 1 commit
  5. 03 May, 2012 1 commit
  6. 13 Apr, 2012 1 commit
  7. 21 Mar, 2012 1 commit
  8. 28 Feb, 2012 2 commits
  9. 24 Feb, 2012 1 commit
  10. 14 Feb, 2012 1 commit
  11. 13 Feb, 2012 2 commits
  12. 12 Feb, 2012 2 commits
  13. 10 Feb, 2012 2 commits
  14. 06 Feb, 2012 1 commit
  15. 04 Feb, 2012 1 commit
  16. 03 Feb, 2012 2 commits
  17. 19 Jan, 2012 1 commit
  18. 18 Jan, 2012 4 commits
  19. 16 Jan, 2012 1 commit
  20. 23 Nov, 2011 1 commit
  21. 22 Nov, 2011 1 commit
  22. 21 Nov, 2011 3 commits
  23. 15 Nov, 2011 2 commits
  24. 09 Nov, 2011 2 commits
  25. 03 Nov, 2011 1 commit
  26. 27 Oct, 2011 1 commit
  27. 23 Oct, 2011 1 commit
  28. 21 Oct, 2011 1 commit