1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Mvc\Model; |
13
|
|
|
|
14
|
|
|
use Phalcon\Mvc\Model\BehaviorInterface; |
15
|
|
|
use Phalcon\Mvc\Model\Manager as PhalconModelsManager; |
16
|
|
|
use Phalcon\Mvc\ModelInterface; |
17
|
|
|
|
18
|
|
|
class Manager extends PhalconModelsManager implements ManagerInterface |
19
|
|
|
{ |
20
|
|
|
public function getBehaviors(): array |
21
|
|
|
{ |
22
|
|
|
return $this->behaviors; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function setBehaviors(array $behaviors): void |
26
|
|
|
{ |
27
|
|
|
$this->behaviors = $behaviors; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get a behavior using the behavior name |
32
|
|
|
*/ |
33
|
|
|
public function getBehavior(ModelInterface $model, string $behaviorName) |
34
|
|
|
{ |
35
|
|
|
$entityName = strtolower(get_class($model)); |
36
|
|
|
|
37
|
|
|
return $this->behaviors[$entityName][$behaviorName] ?? null; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Set a behavior using the behavior name |
42
|
|
|
*/ |
43
|
56 |
|
public function setBehavior(ModelInterface $model, string $behaviorName, BehaviorInterface $behavior): void |
44
|
|
|
{ |
45
|
56 |
|
$entityName = strtolower(get_class($model)); |
46
|
|
|
|
47
|
56 |
|
if (!isset($this->behaviors[$entityName])) { |
48
|
7 |
|
$this->behaviors[$entityName] = []; |
49
|
|
|
} |
50
|
|
|
|
51
|
56 |
|
$this->behaviors[$entityName][$behaviorName] = $behavior; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Return true if the behavior is set |
56
|
|
|
*/ |
57
|
|
|
public function hasBehavior(ModelInterface $model, string $behaviorName): bool |
58
|
|
|
{ |
59
|
|
|
$entityName = strtolower(get_class($model)); |
60
|
|
|
|
61
|
|
|
return isset($this->behaviors[$entityName][$behaviorName]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Merge two arrays of find parameters |
66
|
|
|
*/ |
67
|
|
|
// public function _mergeFindParameters(?array $findParamsOne = [], ?array $findParamsTwo = []): array |
68
|
|
|
// { |
69
|
|
|
// return $this->mergeFindParameters($findParamsOne, $findParamsTwo); |
70
|
|
|
// } |
71
|
|
|
} |
72
|
|
|
|