| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * dmarc-srg - A php parser, viewer and summary report generator for incoming DMARC reports. |
| 5 | * Copyright (C) 2022-2025 Aleksey Andreev (liuch) |
| 6 | * |
| 7 | * Available at: |
| 8 | * https://github.com/liuch/dmarc-srg |
| 9 | * |
| 10 | * This program is free software: you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation, either version 3 of the License. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along with |
| 20 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | * ========================= |
| 23 | * |
| 24 | * This file contains the DomainMapperInterface |
| 25 | * |
| 26 | * @category API |
| 27 | * @package DmarcSrg |
| 28 | * @author Aleksey Andreev (liuch) |
| 29 | * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3 |
| 30 | */ |
| 31 | |
| 32 | namespace Liuch\DmarcSrg\Database; |
| 33 | |
| 34 | interface DomainMapperInterface |
| 35 | { |
| 36 | /** |
| 37 | * Return true if the domain exists or false otherwise. |
| 38 | * |
| 39 | * @param array $data Array with domain data to search |
| 40 | * |
| 41 | * @return bool |
| 42 | */ |
| 43 | public function exists(array &$data): bool; |
| 44 | |
| 45 | /** |
| 46 | * Returns true if the domain exists and is assigned to the user |
| 47 | * |
| 48 | * @param array $data Array with domain data to check |
| 49 | * @param int $user_id User ID to check |
| 50 | * |
| 51 | * @return bool |
| 52 | */ |
| 53 | public function isAssigned(array &$data, int $user_id): bool; |
| 54 | |
| 55 | /** |
| 56 | * Fetch the domain data from the database by its id or name |
| 57 | * |
| 58 | * @param array $data Domain data to update |
| 59 | * |
| 60 | * @return void |
| 61 | */ |
| 62 | public function fetch(array &$data): void; |
| 63 | |
| 64 | /** |
| 65 | * Saves domain data to the database (updates or inserts an record) |
| 66 | * |
| 67 | * @param array $data Domain data |
| 68 | * |
| 69 | * @return void |
| 70 | */ |
| 71 | public function save(array &$data): void; |
| 72 | |
| 73 | /** |
| 74 | * Deletes the domain from the database |
| 75 | * |
| 76 | * Deletes the domain if there are no reports for this domain in the database. |
| 77 | * |
| 78 | * @param int $id Domain ID |
| 79 | * @param bool $force If there are incoming reports for this domain. |
| 80 | * True: Remove the incoming report with the domain |
| 81 | * False: Cancel domain deletion |
| 82 | * |
| 83 | * @return void |
| 84 | */ |
| 85 | public function delete(int $id, bool $force): void; |
| 86 | |
| 87 | /** |
| 88 | * Returns a list of domains data from the database |
| 89 | * |
| 90 | * @param int $user_id User ID to retrieve the list for |
| 91 | * |
| 92 | * @return array |
| 93 | */ |
| 94 | public function list(int $user_id): array; |
| 95 | |
| 96 | /** |
| 97 | * Returns an ordered array with domain names from the database |
| 98 | * |
| 99 | * @param int $user_id User ID to retrieve the list for |
| 100 | * |
| 101 | * @return array |
| 102 | */ |
| 103 | public function names(int $user_id): array; |
| 104 | |
| 105 | /** |
| 106 | * Returns the total number of domains in the database |
| 107 | * |
| 108 | * @param int $user_id User ID |
| 109 | * @param int $max The maximum number of records to count. 0 means no limitation. |
| 110 | * |
| 111 | * @return int The total number of domains |
| 112 | */ |
| 113 | public function count(int $user_id, int $max = 0): int; |
| 114 | |
| 115 | /** |
| 116 | * Assigns the domain to a user |
| 117 | * |
| 118 | * @param array $data Domain data |
| 119 | * @param int $user_id User ID |
| 120 | * |
| 121 | * @return void |
| 122 | */ |
| 123 | public function assignUser(array &$data, int $user_id): void; |
| 124 | |
| 125 | /** |
| 126 | * Unassign the domain from a user |
| 127 | * |
| 128 | * @param array $data Domain data |
| 129 | * @param int $user_id User ID |
| 130 | * |
| 131 | * @return void |
| 132 | */ |
| 133 | public function unassignUser(array &$data, int $user_id): void; |
| 134 | |
| 135 | /** |
| 136 | * Updates the list of domains assigned to a user |
| 137 | * |
| 138 | * @param array $domains List of domains |
| 139 | * @param int $user_id User ID |
| 140 | * |
| 141 | * @return void |
| 142 | */ |
| 143 | public function updateUserDomains(array &$domains, int $user_id): void; |
| 144 | } |