1 | <?php |
||
12 | class RuntimeCacheRepository implements ICacheRepository |
||
13 | { |
||
14 | private $collection; |
||
15 | |||
16 | public function __construct() |
||
17 | { |
||
18 | $this->collection = new Collection(); |
||
19 | } |
||
20 | |||
21 | private function getHash(string $class, string $id): string |
||
22 | { |
||
23 | return $class . '@' . $id; |
||
24 | } |
||
25 | |||
26 | public function instantiate(string $class): Storable |
||
27 | { |
||
28 | $instance = new $class; |
||
29 | if (!$instance instanceof IEloquent) { |
||
30 | throw new ClassTypeErrorException(IEloquent::class); |
||
31 | } |
||
32 | return $instance; |
||
33 | } |
||
34 | |||
35 | public function find(string $id, string $class, array $columns = []): ?Storable |
||
36 | { |
||
37 | $model = $this->collection->get($this->getHash($class, $id)); |
||
38 | if ($model != null && $columns) { |
||
|
|||
39 | return $model->fill(array_intersect_key($model->toArray(), array_flip($columns))); |
||
40 | } |
||
41 | return $model; |
||
42 | } |
||
43 | |||
44 | public function all(IQueryBuilder $query, string $class, callable $callback = null): ICollection |
||
45 | { |
||
46 | return $this->collection; |
||
47 | } |
||
48 | |||
49 | public function insert(Storable $model) |
||
53 | |||
54 | public function update(Storable $model) |
||
58 | |||
59 | public function delete(Storable $model) |
||
63 | |||
64 | public function getCachedAttributes(string $id, string $class): array |
||
68 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.