resource_server_context = App::make(IResourceServerContext::class); // auth mappings $this->registry["User"] = [ self::SerializerType_Public => PublicUserSerializer::class, self::SerializerType_Private => PrivateUserSerializer::class, ]; $this->registry["UserRegistrationRequest"] = UserRegistrationRequestSerializer::class; $this->registry["Group"] = [ self::SerializerType_Public => PublicGroupSerializer::class, self::SerializerType_Private => PublicGroupSerializer::class, ]; // oauth2 mappings $this->registry["ResourceServer"] = ResourceServerSerializer::class; $this->registry["Api"] = ApiSerializer::class; $this->registry["ApiScope"] = ApiScopeSerializer::class; $this->registry["ApiEndpoint"] = ApiEndpointSerializer::class; $this->registry["Client"] = ClientSerializer::class; $this->registry["AccessToken"] = AccessTokenSerializer::class; $this->registry["RefreshToken"] = RefreshTokenSerializer::class; $this->registry["ApiScopeGroup"] = ApiScopeGroupSerializer::class; $this->registry["ServerPrivateKey"] = ServerPrivateKeySerializer::class; $this->registry["ClientPublicKey"] = ClientPublicKeySerializer::class; } /** * @param object $object * @param string $type * @return IModelSerializer */ public function getSerializer($object, $type = self::SerializerType_Public){ if(is_null($object)) return null; $reflect = new ReflectionClass($object); $class = $reflect->getShortName(); if(!isset($this->registry[$class])) throw new \InvalidArgumentException('Serializer not found for '.$class); $serializer_class = $this->registry[$class]; if(is_array($serializer_class)){ if(!isset($serializer_class[$type])) throw new \InvalidArgumentException(sprintf('Serializer not found for %s , type %s', $class, $type)); $serializer_class = $serializer_class[$type]; } return new $serializer_class($object, $this->resource_server_context); } }