[Pkg-owncloud-commits] [owncloud] 47/172: rename formatter to responder, formatResponse to buildResponse
David Prévot
taffit at moszumanska.debian.org
Sun May 18 20:09:38 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit cb666c18d6dd6863495b1da5fe979fdc5fa42204
Author: Bernhard Posselt <dev at bernhard-posselt.com>
Date: Tue May 6 20:25:41 2014 +0200
rename formatter to responder, formatResponse to buildResponse
---
lib/private/appframework/http/dispatcher.php | 2 +-
lib/public/appframework/controller.php | 24 +++++++++++-----------
.../lib/appframework/controller/ControllerTest.php | 10 ++++-----
tests/lib/appframework/http/DispatcherTest.php | 2 +-
4 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php
index dcc0ff0..d6c0aeb 100644
--- a/lib/private/appframework/http/dispatcher.php
+++ b/lib/private/appframework/http/dispatcher.php
@@ -171,7 +171,7 @@ class Dispatcher {
}
}
- $response = $controller->formatResponse($response, $format);
+ $response = $controller->buildResponse($response, $format);
}
return $response;
diff --git a/lib/public/appframework/controller.php b/lib/public/appframework/controller.php
index f28a1d8..f96f346 100644
--- a/lib/public/appframework/controller.php
+++ b/lib/public/appframework/controller.php
@@ -51,7 +51,7 @@ abstract class Controller {
protected $request;
private $serializer;
- private $formatters;
+ private $responders;
/**
* constructor of the controller
@@ -71,8 +71,8 @@ abstract class Controller {
$this->appName = $appName;
$this->request = $request;
- // default formatters
- $this->formatters = array(
+ // default responders
+ $this->responders = array(
'json' => function ($response) {
return new JSONResponse($response);
}
@@ -94,34 +94,34 @@ abstract class Controller {
/**
* Registers a formatter for a type
* @param string $format
- * @param \Closure $closure
+ * @param \Closure $responder
*/
- protected function registerFormatter($format, \Closure $formatter) {
- $this->formatters[$format] = $formatter;
+ protected function registerResponder($format, \Closure $responder) {
+ $this->responders[$format] = $responder;
}
/**
* Serializes and formats a response
- * @param mixed response the value that was returned from a controller and
+ * @param mixed $response the value that was returned from a controller and
* is not a Response instance
* @param string $format the format for which a formatter has been registered
* @throws \DomainException if format does not match a registered formatter
* @return Response
*/
- public function formatResponse($response, $format='json') {
- if(array_key_exists($format, $this->formatters)) {
+ public function buildResponse($response, $format='json') {
+ if(array_key_exists($format, $this->responders)) {
if ($this->serializer) {
$response = $this->serializer->serialize($response);
}
- $formatter = $this->formatters[$format];
+ $responder = $this->responders[$format];
- return $formatter($response);
+ return $responder($response);
} else {
- throw new \DomainException('No formatter registered for format ' .
+ throw new \DomainException('No responder registered for format ' .
$format . '!');
}
}
diff --git a/tests/lib/appframework/controller/ControllerTest.php b/tests/lib/appframework/controller/ControllerTest.php
index 4785c68..0696d00 100644
--- a/tests/lib/appframework/controller/ControllerTest.php
+++ b/tests/lib/appframework/controller/ControllerTest.php
@@ -38,7 +38,7 @@ class ToUpperCaseSerializer implements IResponseSerializer {
class ChildController extends Controller {
public function custom($in) {
- $this->registerFormatter('json', function ($response) {
+ $this->registerResponder('json', function ($response) {
return new JSONResponse(array(strlen($response)));
});
@@ -155,12 +155,12 @@ class ControllerTest extends \PHPUnit_Framework_TestCase {
* @expectedException \DomainException
*/
public function testFormatResonseInvalidFormat() {
- $this->controller->formatResponse(null, 'test');
+ $this->controller->buildResponse(null, 'test');
}
public function testFormat() {
- $response = $this->controller->formatResponse(array('hi'), 'json');
+ $response = $this->controller->buildResponse(array('hi'), 'json');
$this->assertEquals(array('hi'), $response->getData());
}
@@ -168,7 +168,7 @@ class ControllerTest extends \PHPUnit_Framework_TestCase {
public function testCustomFormatter() {
$response = $this->controller->custom('hi');
- $response = $this->controller->formatResponse($response, 'json');
+ $response = $this->controller->buildResponse($response, 'json');
$this->assertEquals(array(2), $response->getData());
}
@@ -176,7 +176,7 @@ class ControllerTest extends \PHPUnit_Framework_TestCase {
public function testCustomSerializer() {
$response = $this->controller->serializer('hi');
- $response = $this->controller->formatResponse($response, 'json');
+ $response = $this->controller->buildResponse($response, 'json');
$this->assertEquals(array('HI'), $response->getData());
}
diff --git a/tests/lib/appframework/http/DispatcherTest.php b/tests/lib/appframework/http/DispatcherTest.php
index d1296f9..08fb374 100644
--- a/tests/lib/appframework/http/DispatcherTest.php
+++ b/tests/lib/appframework/http/DispatcherTest.php
@@ -41,7 +41,7 @@ class TestController extends Controller {
* @param bool $bool
*/
public function exec($int, $bool) {
- $this->registerFormatter('text', function($in) {
+ $this->registerResponder('text', function($in) {
return new JSONResponse(array('text' => $in));
});
return array($int, $bool);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list