Skip to content

Commit

Permalink
Media::render() now returns a Response object instead of acceptin…
Browse files Browse the repository at this point in the history
…g one by reference. WARNING: this will break BC if you have filters intercepting `Media::render()`.
  • Loading branch information
nateabele committed Mar 18, 2012
1 parent 137ee07 commit 3f6ab4b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
8 changes: 4 additions & 4 deletions action/Controller.php
Expand Up @@ -255,10 +255,10 @@ public function render(array $options = array()) {
if ($options['head']) {
return;
}
$data = $this->_render['data'];
$media::render($this->response, $data, $options + array('request' => $this->request));

return $this->response;
$response = $media::render($this->response, $this->_render['data'], $options + array(
'request' => $this->request
));
return ($this->response = $response ?: $this->response);
}

/**
Expand Down
26 changes: 16 additions & 10 deletions net/http/Media.php
Expand Up @@ -549,22 +549,26 @@ public static function path($path, $type, array $options = array()) {
* Renders data (usually the result of a controller action) and generates a string
* representation of it, based on the type of expected output.
*
* @param object $response A reference to a Response object into which the operation will be
* @param object $response A Response object into which the operation will be
* rendered. The content of the render operation will be assigned to the `$body`
* property of the object, and the `'Content-type'` header will be set accordingly.
* @param mixed $data
* @param array $options
* @return void
* property of the object, the `'Content-type'` header will be set accordingly, and it
* will be returned.
* @param mixed $data The data (usually an associative array) to be rendered in the response.
* @param array $options Any options specific to the response being rendered, such as type
* information, keys (i.e. controller and action) used to generate template paths,
* etc.
* @return object Returns a modified `Response` object with headers and body defined.
* @filter
*/
public static function render(&$response, $data = null, array $options = array()) {
$params = array('response' => &$response) + compact('data', 'options');
$types = static::_types();
public static function render($response, $data = null, array $options = array()) {
$params = compact('response', 'data', 'options');
$types = static::_types();
$handlers = static::_handlers();
$func = __FUNCTION__;

static::_filter(__FUNCTION__, $params, function($self, $params) use ($types, $handlers) {
return static::_filter($func, $params, function($self, $params) use ($types, $handlers) {
$defaults = array('encode' => null, 'template' => null, 'layout' => '', 'view' => null);
$response =& $params['response'];
$response = $params['response'];
$data = $params['data'];
$options = $params['options'] + array('type' => $response->type());

Expand All @@ -584,6 +588,8 @@ public static function render(&$response, $data = null, array $options = array()
$response->headers('Content-Type', $header);
}
$response->body($self::invokeMethod('_handle', array($handler, $data, $response)));

return $response;
});
}

Expand Down
3 changes: 2 additions & 1 deletion tests/mocks/action/MockMediaClass.php
Expand Up @@ -10,9 +10,10 @@

class MockMediaClass extends \lithium\net\http\Media {

public static function render(&$response, $data = null, array $options = array()) {
public static function render($response, $data = null, array $options = array()) {
$response->options = $options;
$response->data = $data;
return $response;
}
}

Expand Down

0 comments on commit 3f6ab4b

Please sign in to comment.