'id:json_int', 'Name' => 'name:json_string', 'Description' => 'description:json_string', 'Active' => 'active:json_boolean', ]; protected static $allowed_relations = [ 'scopes', 'endpoints', ]; /** * @param null $expand * @param array $fields * @param array $relations * @param array $params * @return array */ public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array()) { $api = $this->object; if(!$api instanceof Api) return []; if(!count($relations)) $relations = $this->getAllowedRelations(); $values = parent::serialize($expand, $fields, $relations, $params); if(in_array('scopes', $relations)) $values['scopes'] = $api->getScopeIds(); if(in_array('endpoints', $relations)) $values['endpoints'] = $api->getEndpointsIds(); if (!empty($expand)) { foreach (explode(',', $expand) as $relation) { $relation = trim($relation); switch (trim($relation)) { case 'scopes': { if(!in_array('scopes', $relations)) break; $scopes = []; unset($values['scopes']); foreach ($api->getScopes() as $s) { $scopes[] = SerializerRegistry::getInstance()->getSerializer($s)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation)); } $values['scopes'] = $scopes; } break; case 'endpoints': { if(!in_array('endpoints', $relations)) break; $endpoints = []; unset($values['endpoints']); foreach ($api->getEndpoints() as $e) { $endpoints[] = SerializerRegistry::getInstance()->getSerializer($e)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation)); } $values['endpoints'] = $endpoints; } break; } } } return $values; } }