Skip to content
Browse files

Fixing up browser response support.

  • Loading branch information...
1 parent 004c186 commit 728fac9c43f331047d75cff9b3d94a85ddcf11e1 @nateabele committed
Showing with 17 additions and 9 deletions.
  1. +4 −1 action/Resource.php
  2. +12 −7 action/resource/Responder.php
  3. +1 −1 net/http/Resources.php
View
5 action/Resource.php
@@ -146,10 +146,13 @@ protected function _response($request, $result, array $resources, array $options
if (is_object($result) && $result instanceof $classes['response']) {
return $result;
}
+
$options = $this->_result($result, $options) + array(
'controller' => $this->_name(),
'viewData' => $this->_viewData($request, $resources),
);
+ $options['data'] = $options['data'] ?: reset($resources);
+
return $this->_responder->handle($request, $resources, $options);
}
@@ -196,7 +199,7 @@ protected function _result($result, array $options = array()) {
}
$options['state'][$i] = reset($options['state'][$i]);
}
- return $options;
+ return $options + (is_array($result) ? array_diff_key($result, array(0, 0)) : array());
}
/**
View
19 action/resource/Responder.php
@@ -109,7 +109,7 @@ protected function _init() {
}
}
- $options += array('template' => $options['method']);
+ $options += array('template' => $options['method'], 'layout' => 'default');
$options['status'] = $options['status'] ?: 200;
$options['controller'] = Inflector::underscore($options['controller']);
$options['data'] = array($key => $options['data']);
@@ -123,7 +123,8 @@ protected function _init() {
if (!$options['next'] || $options['location'] || !$options['requiresView']) {
return $options;
}
- return array('location' => $url($request, $options['next'])) + $options;
+ $location = $url($request, $options['next']);
+ return compact('location') + array('status' => 302) + $options;
},
'location' => function($request, array $resources, array $options) use ($url) {
$validStatus = in_array($options['status'], array(201, 301, 302, 303));
@@ -170,6 +171,9 @@ public function handle($request, array $resources, array $options = array()) {
$data = $options['data'];
$options = array_diff_key($options, $defaults);
+ if ($config['location']) {
+ return $response;
+ }
return $classes['media']::render($response, $data, $options + compact('request'));
}
@@ -199,11 +203,12 @@ protected function _requiresView($request) {
protected function _url() {
$classes = $this->_classes;
- return function($request, $data) use ($classes) {
- $url = array('id' => $data->_id) + $options['params'];
- $location = $classes['router']::match($url, $request, array('absolute' => true));
- $response->headers("location", $location);
- return $response;
+ // @todo: Rewrite this to map parameters from resource configuration.
+ return function($request, $url) use ($classes) {
+ if (is_object($url)) {
+ $url = isset($url->_id) ? array('id' => $url->_id) : array();
+ }
+ return $classes['router']::match($url, $request, array('absolute' => true));
};
}
View
2 net/http/Resources.php
@@ -352,7 +352,7 @@ public static function export(array $resources, array $options = array()) {
$remap[$resource] = $config;
$names[] = "[{$first}" . ucfirst($first) . "]" . substr($path, 1);
}
- $template = $options['prefix'] . '/{:controller:' . join('|', $names) . '}';
+ $template = $options['prefix'] . '/{:controller:' . join('|', $names) . '}/{:action}';
$template .= '/{:id:(?:[0-9a-f]{24})|(?:\d+)}'; //'.{:type}';
return static::_instance('route', compact('template') + array(

0 comments on commit 728fac9

Please sign in to comment.
Something went wrong with that request. Please try again.