2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
|
|
|
|
2017-07-01 20:29:49 +00:00
|
|
|
namespace Pterodactyl\Contracts\Repository;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
2018-01-05 04:49:50 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2018-01-11 05:19:03 +00:00
|
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
2018-01-05 04:49:50 +00:00
|
|
|
|
2017-07-01 20:29:49 +00:00
|
|
|
interface RepositoryInterface
|
2016-12-07 22:46:38 +00:00
|
|
|
{
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
|
|
|
* Return an identifier or Model object to be used by the repository.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function model(): string;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
|
|
|
* Return the model being used for this repository instance.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getModel(): Model;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
|
|
|
* Returns an instance of a query builder.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getBuilder(): Builder;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
2018-05-13 14:50:56 +00:00
|
|
|
* Returns the columns to be selected or returned by the query.
|
2017-07-08 19:07:51 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getColumns(): array;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
|
|
|
* An array of columns to filter the response by.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function setColumns(array|string $columns = ['*']): self;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Stop repository update functions from returning a fresh
|
|
|
|
* model when changes are committed.
|
2017-07-08 19:07:51 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function withoutFreshModel(): self;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return a fresh model with a repository updates a model.
|
2017-07-08 19:07:51 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function withFreshModel(): self;
|
2017-07-08 19:07:51 +00:00
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Set whether the repository should return a fresh model
|
2018-01-05 04:49:50 +00:00
|
|
|
* when changes are committed.
|
2017-07-08 19:07:51 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function setFreshModel(bool $fresh = true): self;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-08-09 02:21:10 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Create a new model instance and persist it to the database.
|
2017-08-09 02:21:10 +00:00
|
|
|
*
|
2018-01-05 04:49:50 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-08-09 02:21:10 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function create(array $fields, bool $validate = true, bool $force = false): mixed;
|
2017-08-09 02:21:10 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
|
|
|
* Find a model that has the specific ID passed.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function find(int $id): mixed;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
|
|
|
* Find a model matching an array of where clauses.
|
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function findWhere(array $fields): Collection;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-07-08 20:04:59 +00:00
|
|
|
/**
|
|
|
|
* Find and return the first matching instance for the given fields.
|
|
|
|
*
|
2017-09-16 03:13:33 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-07-08 20:04:59 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function findFirstWhere(array $fields): mixed;
|
2017-07-08 20:04:59 +00:00
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
/**
|
|
|
|
* Return a count of records matching the passed arguments.
|
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function findCountWhere(array $fields): int;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a given record from the database.
|
|
|
|
*/
|
|
|
|
public function delete(int $id): int;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete records matching the given attributes.
|
|
|
|
*/
|
|
|
|
public function deleteWhere(array $attributes): int;
|
2017-08-05 22:20:07 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
|
|
|
* Update a given ID with the passed array of fields.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function update(int $id, array $fields, bool $validate = true, bool $force = false): mixed;
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-07-24 00:57:43 +00:00
|
|
|
/**
|
|
|
|
* Perform a mass update where matching records are updated using whereIn.
|
|
|
|
* This does not perform any model data validation.
|
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function updateWhereIn(string $column, array $values, array $fields): int;
|
2017-07-24 00:57:43 +00:00
|
|
|
|
2017-07-25 02:34:10 +00:00
|
|
|
/**
|
|
|
|
* Update a record if it exists in the database, otherwise create it.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function updateOrCreate(array $where, array $fields, bool $validate = true, bool $force = false): mixed;
|
2017-07-25 02:34:10 +00:00
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return all records associated with the given model.
|
2017-07-15 16:52:34 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function all(): Collection;
|
2017-07-20 01:49:41 +00:00
|
|
|
|
2018-01-11 05:19:03 +00:00
|
|
|
/**
|
|
|
|
* Return a paginated result set using a search term if set on the repository.
|
|
|
|
*/
|
|
|
|
public function paginated(int $perPage): LengthAwarePaginator;
|
|
|
|
|
2017-07-20 01:49:41 +00:00
|
|
|
/**
|
|
|
|
* Insert a single or multiple records into the database at once skipping
|
|
|
|
* validation and mass assignment checking.
|
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function insert(array $data): bool;
|
2017-08-06 02:10:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert multiple records into the database and ignore duplicates.
|
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function insertIgnore(array $values): bool;
|
2018-05-26 18:58:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-02 21:32:26 +00:00
|
|
|
* Get the amount of entries in the database.
|
2018-05-26 18:58:49 +00:00
|
|
|
*/
|
|
|
|
public function count(): int;
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|