Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3/**
4 * Database service interface for login_token table.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2024.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Database
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development:plugins:database_gateways Wiki
28 */
29
30namespace VuFind\Db\Service;
31
32use VuFind\Db\Entity\LoginTokenEntityInterface;
33use VuFind\Db\Entity\UserEntityInterface;
34use VuFind\Exception\LoginToken as LoginTokenException;
35
36/**
37 * Database service interface for login_token table.
38 *
39 * @category VuFind
40 * @package  Database
41 * @author   Demian Katz <demian.katz@villanova.edu>
42 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
43 * @link     https://vufind.org/wiki/development:plugins:database_gateways Wiki
44 */
45interface LoginTokenServiceInterface extends DbServiceInterface
46{
47    /**
48     * Create a new login token entity.
49     *
50     * @return LoginTokenEntityInterface
51     */
52    public function createEntity(): LoginTokenEntityInterface;
53
54    /**
55     * Create and persist a token.
56     *
57     * @param UserEntityInterface $user      User identifier
58     * @param string              $token     Login token
59     * @param string              $series    Series the token belongs to
60     * @param string              $browser   User browser
61     * @param string              $platform  User platform
62     * @param int                 $expires   Token expiration timestamp
63     * @param string              $sessionId Session associated with the token
64     *
65     * @return LoginTokenEntityInterface
66     */
67    public function createAndPersistToken(
68        UserEntityInterface $user,
69        string $token,
70        string $series,
71        string $browser = '',
72        string $platform = '',
73        int $expires = 0,
74        string $sessionId = ''
75    ): LoginTokenEntityInterface;
76
77    /**
78     * Check if a login token matches one in database.
79     *
80     * @param array $token array containing user id, token and series
81     *
82     * @return ?LoginTokenEntityInterface
83     * @throws LoginTokenException
84     */
85    public function matchToken(array $token): ?LoginTokenEntityInterface;
86
87    /**
88     * Delete all tokens in a given series.
89     *
90     * @param string $series         series
91     * @param ?int   $currentTokenId Current token ID to keep
92     *
93     * @return void
94     */
95    public function deleteBySeries(string $series, ?int $currentTokenId = null): void;
96
97    /**
98     * Delete all tokens for a user.
99     *
100     * @param UserEntityInterface|int $userOrId User entity object or identifier
101     *
102     * @return void
103     */
104    public function deleteByUser(UserEntityInterface|int $userOrId): void;
105
106    /**
107     * Get tokens for a given user.
108     *
109     * @param UserEntityInterface|int $userOrId User entity object or identifier
110     * @param bool                    $grouped  Whether to return results grouped by series
111     *
112     * @return LoginTokenEntityInterface[]
113     */
114    public function getByUser(UserEntityInterface|int $userOrId, bool $grouped = true): array;
115
116    /**
117     * Get token by series.
118     *
119     * @param string $series Series identifier
120     *
121     * @return LoginTokenEntityInterface[]
122     */
123    public function getBySeries(string $series): array;
124}