diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-08-29 23:39:35 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-09-27 15:35:31 +0200 |
commit | d00d1ab2a28f428223e52b17052c072c64784016 (patch) | |
tree | c019f85fb7ac67147dd43ca64b4ac3cda99832f7 /lib/Controller/ApiPayloadTrait.php | |
parent | 5687baca75d47dbdffd3de74e865ad2f71ef0cb7 (diff) |
Create V2 mapper, Service and management commands
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Controller/ApiPayloadTrait.php')
-rw-r--r-- | lib/Controller/ApiPayloadTrait.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/Controller/ApiPayloadTrait.php b/lib/Controller/ApiPayloadTrait.php new file mode 100644 index 000000000..2bb31784e --- /dev/null +++ b/lib/Controller/ApiPayloadTrait.php @@ -0,0 +1,36 @@ +<?php + + +namespace OCA\News\Controller; + +use OCA\News\Db\IAPI; + +trait ApiPayloadTrait +{ + /** + * Serialize all data + * + * @param mixed $data IAPI or array, + * anything else will return an empty array + * + * @return array + */ + public function serialize($data): array + { + $return = []; + if ($data instanceof IAPI) { + return [$data->toAPI()]; + } + + if (!is_array($data)) { + return $return; + } + + foreach ($data as $entity) { + if ($entity instanceof IAPI) { + $return[] = $entity->toAPI(); + } + } + return $return; + } +} |