diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-13 21:57:44 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-13 21:57:44 +0200 |
commit | 066b4b5a22a89fe3b38d37f09153090091928cd5 (patch) | |
tree | e01b7eaf641314259de1a54f146fa3e5d582ce02 /controller/entityapiserializer.php | |
parent | fb85040af65e77e6f4b2e596e259b38b510a8b60 (diff) |
move to new controller layout
Diffstat (limited to 'controller/entityapiserializer.php')
-rw-r--r-- | controller/entityapiserializer.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/controller/entityapiserializer.php b/controller/entityapiserializer.php new file mode 100644 index 000000000..ef5e20fbe --- /dev/null +++ b/controller/entityapiserializer.php @@ -0,0 +1,44 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Alessandro Cosentino 2012 + * @copyright Bernhard Posselt 2012, 2014 + */ + +namespace OCA\News\Controller; + +use \OCP\AppFramework\Http\IResponseSerializer; + +class EntityApiSeralizer implements IResponseSerializer { + + + public function __construct($level) { + $this->level = $level; + } + + + /** + * Wrap a list of entities in an array with $level as index and serialize + * them using the toAPI method + */ + public function serialize($data) { + if(!is_array($data)) { + $data = array($data); + } + + $response = array( + $this->level => array(); + ); + + foreach($data as $entity) { + $response[$this->level][] = $entity->toAPI() + } + } + +}
\ No newline at end of file |