* @git Joomla Component Builder * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access to this JCB template file (EVER) defined('_JCB_TEMPLATE') or die; ?> ###BOM### namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Api\Serializer; ###API_VIEW_SERIALIZER_HEADER### // No direct access to this file \defined('_JEXEC') or die; /** * ###View### Api Serializer * * Builds the relationships of the ###view### resource, for the item and * the list representation alike. * * @since 4.0.0 */ class ###View###Serializer extends JoomlaSerializer {###API_VIEW_SERIALIZER_RELATIONS### /** * Build the relationship to one related resource, or to many when the value holds several ids. * * @param mixed $value The id of the related resource, or the ids of the related resources. * @param string $type The type of the related resource. * * @return Relationship * * @since 4.0.0 */ protected function related($value, string $type): Relationship { $serializer = new JoomlaSerializer($type); if (is_array($value)) { $resources = []; foreach ($value as $id) { if ($id !== null && $id !== '' && !is_array($id) && !is_object($id)) { $resources[] = new Resource($id, $serializer); } } return new Relationship(new Collection($resources, $serializer)); } return new Relationship(new Resource($value, $serializer)); } }