get(GetTokenAction::class)->__invoke($idToken)->toArray(); return $token; } /** * Get info tokens for user. * * @param integer $page Page. * @param integer $pageSize Size page. * @param string|null $sortField Sort field. * @param string|null $sortDirection Sort direction. * @param array $filters Filters. * * @return array */ function list_user_tokens( int $page=0, int $pageSize=0, ?string $sortField=null, ?string $sortDirection=null, array $filters=[] ): array { global $config; global $container; $tokenFilter = new TokenFilter; $tokenFilter->setPage($page); $tokenFilter->setSizePage($pageSize); $tokenFilter->setSortField($sortField); $tokenFilter->setSortDirection($sortDirection); if (empty($filters['freeSearch']) === false) { $tokenFilter->setFreeSearch($filters['freeSearch']); } // phpcs:ignore /** @var Token $entityFilter */ $entityFilter = $tokenFilter->getEntityFilter(); if (empty($filters['idUser']) === true) { $entityFilter->setIdUser($config['id_user']); } else { $entityFilter->setIdUser($filters['idUser']); } $result = $container->get(ListTokenAction::class)->__invoke($tokenFilter); return $result; } /** * Create token. * * @param array $params Params. * * @return array */ function create_user_token(array $params): array { global $config; global $container; $token = new Token; $token->setIdUser($config['id_user']); $token->setLabel(io_safe_output($params['label'])); $token->setValidity((empty($params['validity']) === false) ? io_safe_output($params['validity']) : null); $result = $container->get(CreateTokenAction::class)->__invoke($token)->toArray(); return $result; } /** * Update token. * * @param integer $idToken Token ID. * @param array $params Params. * * @return array */ function update_user_token(int $idToken, array $params): array { global $config; global $container; $token = $container->get(GetTokenAction::class)->__invoke($idToken); $oldToken = clone $token; $token->setIdUser($config['id_user']); $token->setLabel(io_safe_output($params['label'])); $token->setValidity((empty($params['validity']) === false) ? io_safe_output($params['validity']) : null); $result = $container->get(UpdateTokenAction::class)->__invoke($token, $oldToken)->toArray(); return $result; } /** * Delete token. * * @param integer $idToken Token ID. * * @return boolean */ function delete_user_token(int $idToken): bool { global $container; $token = $container->get(GetTokenAction::class)->__invoke($idToken); $container->get(DeleteTokenAction::class)->__invoke($token); $result = true; return $result; }