|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.6 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com) |
|
8
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://www.gixx-web.com |
|
11
|
|
|
*/ |
|
12
|
|
|
namespace WebHemi\Data\Coupler; |
|
13
|
|
|
|
|
14
|
|
|
use RuntimeException; |
|
15
|
|
|
use WebHemi\Data\Coupler\Traits\PolicyEntityTrait; |
|
16
|
|
|
use WebHemi\Data\Coupler\Traits\UserGroupEntityTrait; |
|
17
|
|
|
use WebHemi\Data\Entity\DataEntityInterface; |
|
18
|
|
|
use WebHemi\Data\Entity\User\UserGroupEntity; |
|
19
|
|
|
use WebHemi\Data\Entity\AccessManagement\PolicyEntity; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class UserToPolicyCoupler. |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
class UserGroupToPolicyCoupler extends AbstractDataCoupler |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
protected $connectorIdKey = 'id_user_group_to_am_policy'; |
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
protected $connectorDataGroup = 'webhemi_user_group_to_am_policy'; |
|
30
|
|
|
/** @var array */ |
|
31
|
|
|
protected $dependentDataGroups = [ |
|
32
|
|
|
UserGroupEntity::class => [ |
|
33
|
|
|
'source_key' => 'fk_user_group', |
|
34
|
|
|
'connector_key' => 'fk_am_policy', |
|
35
|
|
|
'depending_group' => 'webhemi_am_policy', |
|
36
|
|
|
'depending_id_key' => 'id_am_policy', |
|
37
|
|
|
], |
|
38
|
|
|
PolicyEntity::class => [ |
|
39
|
|
|
'source_key' => 'fk_am_policy', |
|
40
|
|
|
'connector_key' => 'fk_user_group', |
|
41
|
|
|
'depending_group' => 'webhemi_user_group', |
|
42
|
|
|
'depending_id_key' => 'id_user_group', |
|
43
|
|
|
] |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
use UserGroupEntityTrait; |
|
47
|
|
|
use PolicyEntityTrait; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Gets all the entities those are depending from the given entity. |
|
51
|
|
|
* |
|
52
|
|
|
* @param DataEntityInterface $entity |
|
53
|
|
|
* @throws RuntimeException |
|
54
|
|
|
* @return array<DataEntityInterface> |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getEntityDependencies(DataEntityInterface $entity) |
|
57
|
|
|
{ |
|
58
|
|
|
$entityClass = get_class($entity); |
|
59
|
|
|
if (!isset($this->dataEntityPrototypes[$entityClass])) { |
|
60
|
|
|
throw new RuntimeException( |
|
61
|
|
|
sprintf('Cannot use this coupler class to find dependencies for %s.', $entityClass) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$entityList = []; |
|
66
|
|
|
$dataList = $this->getEntityDataSet($entity); |
|
67
|
|
|
|
|
68
|
|
|
foreach ($dataList as $entityData) { |
|
69
|
|
|
$entityList[] = $entity instanceof UserGroupEntity |
|
70
|
|
|
? $this->createPolicyEntity($entityData) |
|
71
|
|
|
: $this->createUserGroupEntity($entityData); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $entityList; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.