Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Contracts/Repository/RepositoryInterface.php
10279 views
1
<?php
2
3
namespace Pterodactyl\Contracts\Repository;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
9
10
interface RepositoryInterface
11
{
12
/**
13
* Return an identifier or Model object to be used by the repository.
14
*/
15
public function model(): string;
16
17
/**
18
* Return the model being used for this repository instance.
19
*/
20
public function getModel(): Model;
21
22
/**
23
* Returns an instance of a query builder.
24
*/
25
public function getBuilder(): Builder;
26
27
/**
28
* Returns the columns to be selected or returned by the query.
29
*/
30
public function getColumns(): array;
31
32
/**
33
* An array of columns to filter the response by.
34
*/
35
public function setColumns(array|string $columns = ['*']): self;
36
37
/**
38
* Stop repository update functions from returning a fresh
39
* model when changes are committed.
40
*/
41
public function withoutFreshModel(): self;
42
43
/**
44
* Return a fresh model with a repository updates a model.
45
*/
46
public function withFreshModel(): self;
47
48
/**
49
* Set whether the repository should return a fresh model
50
* when changes are committed.
51
*/
52
public function setFreshModel(bool $fresh = true): self;
53
54
/**
55
* Create a new model instance and persist it to the database.
56
*
57
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
58
*/
59
public function create(array $fields, bool $validate = true, bool $force = false): mixed;
60
61
/**
62
* Find a model that has the specific ID passed.
63
*
64
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
65
*/
66
public function find(int $id): mixed;
67
68
/**
69
* Find a model matching an array of where clauses.
70
*/
71
public function findWhere(array $fields): Collection;
72
73
/**
74
* Find and return the first matching instance for the given fields.
75
*
76
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
77
*/
78
public function findFirstWhere(array $fields): mixed;
79
80
/**
81
* Return a count of records matching the passed arguments.
82
*/
83
public function findCountWhere(array $fields): int;
84
85
/**
86
* Delete a given record from the database.
87
*/
88
public function delete(int $id): int;
89
90
/**
91
* Delete records matching the given attributes.
92
*/
93
public function deleteWhere(array $attributes): int;
94
95
/**
96
* Update a given ID with the passed array of fields.
97
*
98
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
99
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
100
*/
101
public function update(int $id, array $fields, bool $validate = true, bool $force = false): mixed;
102
103
/**
104
* Perform a mass update where matching records are updated using whereIn.
105
* This does not perform any model data validation.
106
*/
107
public function updateWhereIn(string $column, array $values, array $fields): int;
108
109
/**
110
* Update a record if it exists in the database, otherwise create it.
111
*
112
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
113
*/
114
public function updateOrCreate(array $where, array $fields, bool $validate = true, bool $force = false): mixed;
115
116
/**
117
* Return all records associated with the given model.
118
*/
119
public function all(): Collection;
120
121
/**
122
* Return a paginated result set using a search term if set on the repository.
123
*/
124
public function paginated(int $perPage): LengthAwarePaginator;
125
126
/**
127
* Insert a single or multiple records into the database at once skipping
128
* validation and mass assignment checking.
129
*/
130
public function insert(array $data): bool;
131
132
/**
133
* Insert multiple records into the database and ignore duplicates.
134
*/
135
public function insertIgnore(array $values): bool;
136
137
/**
138
* Get the amount of entries in the database.
139
*/
140
public function count(): int;
141
}
142
143