| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Repository; |
| 4 |
|
| 5 |
// phpcs:disable PSR1.Files.SideEffects |
| 6 |
if (!defined('ABSPATH')) { |
| 7 |
exit; // Exit if accessed directly |
| 8 |
} |
| 9 |
|
| 10 |
use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 11 |
|
| 12 |
/** |
| 13 |
* Interface BaseRepositoryInterface |
| 14 |
* |
| 15 |
* @package IvyForms\Repository |
| 16 |
*/ |
| 17 |
interface BaseRepositoryInterface |
| 18 |
{ |
| 19 |
/** |
| 20 |
* Get an entity by ID. |
| 21 |
* |
| 22 |
* @param int $id |
| 23 |
* |
| 24 |
* @return object|null |
| 25 |
*/ |
| 26 |
public function getById(int $id): ?object; |
| 27 |
|
| 28 |
/** |
| 29 |
* Get all entities. |
| 30 |
* |
| 31 |
* @return mixed[]|null |
| 32 |
*/ |
| 33 |
public function getAll(): ?array; |
| 34 |
|
| 35 |
/** |
| 36 |
* Add an entity. |
| 37 |
* |
| 38 |
* @param object $entity |
| 39 |
* @return int |
| 40 |
*/ |
| 41 |
public function add(object $entity): int; |
| 42 |
|
| 43 |
/** |
| 44 |
* Update an entity by ID. |
| 45 |
* |
| 46 |
* @param int $id |
| 47 |
* @param object $entity |
| 48 |
* @return bool |
| 49 |
*/ |
| 50 |
public function update(int $id, object $entity): bool; |
| 51 |
|
| 52 |
/** |
| 53 |
* Delete an entity by ID. |
| 54 |
* |
| 55 |
* @param int $id |
| 56 |
* @return int |
| 57 |
*/ |
| 58 |
public function delete(int $id): int; |
| 59 |
|
| 60 |
/** |
| 61 |
* Delete multiple entities by their IDs in bulk. |
| 62 |
* |
| 63 |
* @param array<int> $ids |
| 64 |
* @return int Number of deleted entities |
| 65 |
*/ |
| 66 |
public function deleteMany(array $ids): int; |
| 67 |
|
| 68 |
/** |
| 69 |
* Delete multiple entities by foreign key values (e.g., form IDs). |
| 70 |
* |
| 71 |
* @param array<int> $foreignIds Array of foreign key values (e.g., form IDs) |
| 72 |
* @param string $foreignColumn Foreign key column name (default: 'formId') |
| 73 |
* @return int Number of deleted entities |
| 74 |
* @throws InvalidArgumentException If no foreign IDs are provided |
| 75 |
*/ |
| 76 |
public function deleteManyByForeignKeyValues(array $foreignIds, string $foreignColumn = 'formId'): int; |
| 77 |
|
| 78 |
/** |
| 79 |
* Delete entities by a single foreign key value (e.g., form ID). |
| 80 |
* |
| 81 |
* @param int $foreignId Foreign key value (e.g., form ID) |
| 82 |
* @param string $foreignColumn Foreign key column name (default: 'formId') |
| 83 |
* @return int Number of deleted entities |
| 84 |
* @throws InvalidArgumentException If invalid foreign column is provided |
| 85 |
*/ |
| 86 |
public function deleteOneByForeignKeyValue(int $foreignId, string $foreignColumn = 'formId'): int; |
| 87 |
|
| 88 |
/** |
| 89 |
* Search for entities based on parameters. |
| 90 |
* |
| 91 |
* @param array<string, mixed> $params |
| 92 |
* @return array<mixed> |
| 93 |
*/ |
| 94 |
public function search(array $params): array; |
| 95 |
|
| 96 |
/** |
| 97 |
* Select query for retrieving data. |
| 98 |
* |
| 99 |
* @return string |
| 100 |
*/ |
| 101 |
public function selectQuery(): string; |
| 102 |
|
| 103 |
/** |
| 104 |
* Begin a database transaction. |
| 105 |
* |
| 106 |
* @return bool |
| 107 |
*/ |
| 108 |
public function beginTransaction(): bool; |
| 109 |
|
| 110 |
/** |
| 111 |
* Commit a database transaction. |
| 112 |
* |
| 113 |
* @return bool |
| 114 |
*/ |
| 115 |
public function commit(): bool; |
| 116 |
|
| 117 |
/** |
| 118 |
* Rollback a database transaction. |
| 119 |
* |
| 120 |
* @return bool |
| 121 |
*/ |
| 122 |
public function rollback(): bool; |
| 123 |
} |
| 124 |
|