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\Relation; |
15
|
|
|
use Zemit\Config\ConfigInterface; |
16
|
|
|
use Zemit\Models\Audit; |
17
|
|
|
use Zemit\Models\AuditDetail; |
18
|
|
|
use Zemit\Models\User; |
19
|
|
|
use Zemit\Mvc\Model\AbstractTrait\AbstractBehavior; |
20
|
|
|
use Zemit\Mvc\Model\AbstractTrait\AbstractIdentity; |
|
|
|
|
21
|
|
|
use Zemit\Mvc\Model\AbstractTrait\AbstractInjectable; |
22
|
|
|
use Zemit\Mvc\Model\Behavior\Blameable as BlameableBehavior; |
23
|
|
|
|
24
|
|
|
trait Blameable |
25
|
|
|
{ |
26
|
|
|
use AbstractBehavior; |
27
|
|
|
use AbstractIdentity; |
28
|
|
|
use AbstractInjectable; |
29
|
|
|
|
30
|
|
|
use Options; |
31
|
|
|
|
32
|
|
|
use Blameable\Created; |
33
|
|
|
use Blameable\Updated; |
34
|
|
|
use Blameable\Deleted; |
35
|
|
|
use Blameable\Restored; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Initializing Blameable |
39
|
|
|
*/ |
40
|
|
|
public function initializeBlameable(?array $options = null): void |
41
|
|
|
{ |
42
|
|
|
$options ??= $this->getOptionsManager()->get('blameable') ?? []; |
43
|
|
|
|
44
|
|
|
$config = $this->getDI()->get('config'); |
45
|
|
|
assert($config instanceof ConfigInterface); |
46
|
|
|
|
47
|
|
|
$options['auditClass'] ??= $config->getModelClass(Audit::class); |
48
|
|
|
$options['auditDetailClass'] ??= $config->getModelClass(AuditDetail::class); |
49
|
|
|
$options['userClass'] ??= $config->getModelClass(User::class); |
50
|
|
|
|
51
|
|
|
$this->setBlameableBehavior(new BlameableBehavior($options)); |
52
|
|
|
|
53
|
|
|
$userField = $options['userField'] ?? 'userId'; |
54
|
|
|
$this->addUserRelationship($userField, 'User'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Set Blameable Behavior |
59
|
|
|
*/ |
60
|
|
|
public function setBlameableBehavior(BlameableBehavior $blameableBehavior): void |
61
|
|
|
{ |
62
|
|
|
$this->setBehavior('blameable', $blameableBehavior); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get Blameable Behavior |
67
|
|
|
*/ |
68
|
|
|
public function getBlameableBehavior(): BlameableBehavior |
69
|
|
|
{ |
70
|
|
|
$blameableBehavior = $this->getBehavior('blameable'); |
71
|
|
|
assert($blameableBehavior instanceof BlameableBehavior); |
72
|
|
|
return $blameableBehavior; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Add a user relationship |
77
|
|
|
*/ |
78
|
|
|
public function addUserRelationship( |
79
|
|
|
string $field = 'userId', |
80
|
|
|
string $alias = 'UserEntity', |
81
|
|
|
array $params = [], |
82
|
|
|
string $ref = 'id', |
83
|
|
|
string $type = 'belongsTo', |
84
|
|
|
?string $class = null |
85
|
|
|
): ?Relation { |
86
|
|
|
if (property_exists($this, $field)) { |
87
|
|
|
$class ??= $this->getIdentity()->getUserClass() ?: $this->getDI()->get('config')->getModelClass(\Zemit\Models\User::class); |
88
|
|
|
return $this->$type($field, $class, $ref, ['alias' => $alias, 'params ' => $params]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return null; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths