1 | <?php |
||
21 | abstract class Eloquent implements IEloquent |
||
22 | { |
||
23 | use Containerable, Timestampable, Eventable; |
||
24 | |||
25 | protected $primaryKey; |
||
26 | protected $exists = false; |
||
27 | protected $timestamps = false; |
||
28 | protected $cache = false; |
||
29 | |||
30 | /** @MustBeOverridden */ |
||
31 | const COLLECTION = null; |
||
32 | |||
33 | const PRIMARY_KEY = 'id'; |
||
34 | const CREATED_AT = 'created_at'; |
||
35 | const UPDATED_AT = 'updated_at'; |
||
36 | |||
37 | abstract protected static function di(): Container; |
||
38 | |||
39 | public function __construct(array $attributes = []) |
||
43 | |||
44 | public function setPrimaryKey(string $key) |
||
48 | |||
49 | public function getPrimaryKey(): string |
||
56 | |||
57 | final public static function getCollection(): string |
||
64 | |||
65 | public function exists(bool $value = null): bool |
||
72 | |||
73 | public static function all(IQueryBuilder $query, callable $callback = null): ICollection |
||
84 | |||
85 | public static function find(string $id, array $columns = []): ?IEloquent |
||
100 | |||
101 | public static function findOrFail(string $id, array $columns = []): IEloquent |
||
109 | |||
110 | public static function create(array $attributes): IEloquent |
||
116 | |||
117 | public static function destroy(string $id): void |
||
121 | |||
122 | public function save(): void |
||
123 | { |
||
124 | if ($this->saving() === false) { |
||
125 | return; |
||
126 | } |
||
127 | $repository = $this->di()->getRepository(); |
||
128 | if ($this->timestamps) { |
||
129 | $this->updateTimestamps(); |
||
130 | } |
||
131 | if (!$this->exists) { |
||
132 | $repository->insert($this); |
||
133 | } else { |
||
134 | $repository->update($this); |
||
135 | } |
||
136 | $this->exists = true; |
||
137 | if ($this->saved() === false) { |
||
138 | return; |
||
139 | } |
||
140 | } |
||
141 | |||
142 | public function delete(): void |
||
153 | } |