|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace TZachi\PhalconRepository; |
|
6
|
|
|
|
|
7
|
|
|
use Phalcon\DiInterface; |
|
8
|
|
|
use Phalcon\Mvc\Model; |
|
9
|
|
|
use Phalcon\Mvc\Model\Criteria; |
|
10
|
|
|
use Phalcon\Mvc\Model\Resultset\Simple as SimpleResultset; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Wrapper class for calling \Phalcon\Mvc\Model's static methods as instance methods without getting PHP warnings |
|
14
|
|
|
*/ |
|
15
|
|
|
class ModelWrapper |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $modelName; |
|
21
|
|
|
|
|
22
|
18 |
|
public function __construct(string $modelName) |
|
23
|
|
|
{ |
|
24
|
18 |
|
$this->modelName = $modelName; |
|
25
|
18 |
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
public function getModelName(): string |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $this->modelName; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param mixed[] $parameters |
|
34
|
|
|
* |
|
35
|
|
|
* @return Model|false |
|
36
|
|
|
*/ |
|
37
|
2 |
|
public function findFirst(?array $parameters = null) |
|
38
|
|
|
{ |
|
39
|
2 |
|
return $this->modelName::findFirst($parameters); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param mixed[] $parameters |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function find(?array $parameters = null): SimpleResultset |
|
46
|
|
|
{ |
|
47
|
1 |
|
return $this->modelName::find($parameters); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Generates a criteria for custom queries |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function query(?DiInterface $dependencyInjector = null): Criteria |
|
54
|
|
|
{ |
|
55
|
1 |
|
return $this->modelName::query($dependencyInjector); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param mixed[] $parameters |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function count(?array $parameters = null): int |
|
62
|
|
|
{ |
|
63
|
1 |
|
return $this->modelName::count($parameters); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param mixed[] $parameters |
|
68
|
|
|
*/ |
|
69
|
2 |
|
public function sum(?array $parameters = null): ?string |
|
70
|
|
|
{ |
|
71
|
2 |
|
return $this->modelName::sum($parameters); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param mixed[] $parameters |
|
76
|
|
|
*/ |
|
77
|
2 |
|
public function average(?array $parameters = null): ?string |
|
78
|
|
|
{ |
|
79
|
2 |
|
return $this->modelName::average($parameters); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param mixed[] $parameters |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public function minimum(?array $parameters = null): ?string |
|
86
|
|
|
{ |
|
87
|
2 |
|
return $this->modelName::minimum($parameters); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param mixed[] $parameters |
|
92
|
|
|
*/ |
|
93
|
2 |
|
public function maximum(?array $parameters = null): ?string |
|
94
|
|
|
{ |
|
95
|
2 |
|
return $this->modelName::maximum($parameters); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|