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
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Db\Model;
16
17use Pop\Db\Record;
18use Pop\Db\Record\Collection;
19
20/**
21 * Data model interface
22 *
23 * @category   Pop
24 * @package    Pop\Db
25 * @author     Nick Sagona, III <nick@popphp.org>
26 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
27 * @license    https://www.popphp.org/license     New BSD License
28 * @version    7.0.0
29 */
30interface DataModelInterface
31{
32
33    /**
34     * Get all
35     *
36     * @param  ?string    $sort
37     * @param  mixed      $limit
38     * @param  mixed      $page
39     * @param  bool|array $toArray
40     * @throws Exception
41     * @return array|Collection
42     */
43    public function getAll(?string $sort = null, mixed $limit = null, mixed $page = null, bool|array $toArray = false): array|Collection;
44
45    /**
46     * Get by ID
47     *
48     * @param  mixed $id
49     * @param  bool  $toArray
50     * @throws Exception
51     * @return array|Record
52     */
53    public function getById(mixed $id, bool $toArray = false): array|Record;
54
55    /**
56     * Create
57     *
58     * @param  array $data
59     * @return mixed
60     */
61    public function create(array $data): mixed;
62
63    /**
64     * Replace
65     *
66     * @param  mixed $id
67     * @param  array $data
68     * @return mixed
69     */
70    public function replace(mixed $id, array $data): mixed;
71
72    /**
73     * Update
74     *
75     * @param  mixed $id
76     * @param  array $data
77     * @return mixed
78     */
79    public function update(mixed $id, array $data): mixed;
80
81    /**
82     * Delete
83     *
84     * @param  mixed $id
85     * @throws Exception
86     * @return int
87     */
88    public function delete(mixed $id): int;
89
90    /**
91     * Remove multiple
92     *
93     * @param  array $ids
94     * @throws Exception
95     * @return int
96     */
97    public function remove(array $ids): int;
98
99    /**
100     * Get count
101     *
102     * @throws Exception
103     * @return int
104     */
105    public function count(): int;
106
107    /**
108     * Method to describe columns in the database table
109     *
110     * @param  bool $native     Show the native columns in the table
111     * @param  bool $full       Used with the native flag, returns array of "column" => "type"
112     * @throws Exception
113     * @return array
114     */
115    public function describe(bool $native = false, bool $full = false): array;
116
117    /**
118     * Method to check if model has requirements or validations
119     *
120     * @return bool
121     */
122    public function hasRequirements(): bool;
123
124    /**
125     * Method to validate model data
126     *
127     * @param  array $data
128     * @return bool|array
129     */
130    public function validate(array $data): bool|array;
131
132    /**
133     * Set filters
134     *
135     * @param  mixed $filters
136     * @param  mixed $select
137     * @return DataModelInterface
138     */
139    public function filter(mixed $filters = null, mixed $select = null): DataModelInterface;
140
141    /**
142     * Set select columns
143     *
144     * @param  mixed $select
145     * @return DataModelInterface
146     */
147    public function select(mixed $select = null): DataModelInterface;
148
149    /**
150     * Get table class
151     *
152     * @return string
153     */
154    public function getTableClass(): string;
155
156    /**
157     * Get table primary ID
158     *
159     * @return string
160     */
161    public function getPrimaryId(): string;
162
163    /**
164     * Get offset and limit
165     *
166     * @param  mixed $page
167     * @param  mixed $limit
168     * @return array
169     */
170    public function getOffsetAndLimit(mixed $page = null, mixed $limit = null): array;
171
172    /**
173     * Get order by
174     *
175     * @param  mixed $sort
176     * @param  bool  $toArray
177     * @return string|array|null
178     */
179    public function getOrderBy(mixed $sort = null, bool $toArray = false): string|array|null;
180
181    /**
182     * Method to parse filter for select predicates
183     *
184     * @param  mixed  $filter
185     * @return array
186     */
187    public function parseFilter(mixed $filter): array;
188
189}