1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\BusinessEntityBundle\Helper; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
6
|
|
|
use Victoire\Bundle\BusinessEntityBundle\Entity\BusinessEntity; |
7
|
|
|
use Victoire\Bundle\BusinessEntityBundle\Entity\BusinessEntityRepository; |
8
|
|
|
use Victoire\Bundle\BusinessEntityBundle\Entity\BusinessProperty; |
9
|
|
|
use Victoire\Bundle\BusinessEntityBundle\Reader\BusinessEntityCacheReader; |
10
|
|
|
use Victoire\Bundle\CoreBundle\Cache\Builder\CacheBuilder; |
11
|
|
|
use Victoire\Bundle\ORMBusinessEntityBundle\Entity\ORMBusinessEntityRepository; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The BusinessEntityHelper. |
15
|
|
|
* |
16
|
|
|
* ref: victoire_core.helper.business_entity_helper |
17
|
|
|
*/ |
18
|
|
|
class BusinessEntityHelper |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var BusinessEntityRepository |
22
|
|
|
*/ |
23
|
|
|
private $businessEntityRepository; |
24
|
|
|
/** |
25
|
|
|
* @var ORMBusinessEntityRepository |
26
|
|
|
*/ |
27
|
|
|
private $ormBusinessEntityRepository; |
28
|
|
|
/** |
29
|
|
|
* @var BusinessEntityCacheReader |
30
|
|
|
*/ |
31
|
|
|
private $cacheReader; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor. |
35
|
|
|
* |
36
|
|
|
* @param EntityRepository|BusinessEntityRepository $businessEntityRepository |
37
|
|
|
* @param EntityRepository $ormBusinessEntityRepository |
38
|
|
|
* @param BusinessEntityCacheReader $cacheReader |
39
|
|
|
* |
40
|
|
|
* @internal param BusinessEntityCacheReader $reader |
41
|
|
|
* @internal param CacheBuilder $builder |
42
|
|
|
*/ |
43
|
|
|
public function __construct(EntityRepository $businessEntityRepository, EntityRepository $ormBusinessEntityRepository, BusinessEntityCacheReader $cacheReader) |
44
|
|
|
{ |
45
|
|
|
$this->ormBusinessEntityRepository = $ormBusinessEntityRepository; |
|
|
|
|
46
|
|
|
$this->businessEntityRepository = $businessEntityRepository; |
|
|
|
|
47
|
|
|
$this->cacheReader = $cacheReader; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get a business entity.q. |
52
|
|
|
* |
53
|
|
|
* @param mixed $entity |
54
|
|
|
* |
55
|
|
|
* @return BusinessEntity |
56
|
|
|
*/ |
57
|
|
|
public function findByEntityInstance($entity) |
58
|
|
|
{ |
59
|
|
|
$businessEntity = null; |
60
|
|
|
$class = new \ReflectionClass($entity); |
61
|
|
|
while (!$businessEntity && $class && $class->name !== null) { |
62
|
|
|
$businessEntity = $this->ormBusinessEntityRepository->findOneBy(['class' => $class->name]); |
63
|
|
|
$class = $class->getParentClass(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $businessEntity; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get a business entity by classname. |
71
|
|
|
* |
72
|
|
|
* @param string $classname |
73
|
|
|
* |
74
|
|
|
* @return BusinessEntity |
75
|
|
|
*/ |
76
|
|
|
public function findByEntityClassname($classname) |
77
|
|
|
{ |
78
|
|
|
return $this->ormBusinessEntityRepository->findOneBy(['class' => $classname]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getAvailableForWidget($widgetName) |
82
|
|
|
{ |
83
|
|
|
$classes = $this->businessEntityRepository->getByAvailableWidgets($widgetName); |
84
|
|
|
|
85
|
|
|
$receiverProperties = $this->cacheReader->getReceiverProperties($widgetName); |
86
|
|
|
foreach ($classes as $businessEntity) { |
87
|
|
|
$businessProperties = $businessEntity->getBusinessProperties(); |
88
|
|
|
foreach ($receiverProperties as $receiverType => $receiverProperty) { |
89
|
|
|
$businessEntity->setDisable(true); |
90
|
|
|
if (count($businessProperties) > 0) { |
91
|
|
|
/** @var BusinessProperty $businessProperty */ |
92
|
|
|
foreach ($businessProperties as $businessProperty) { |
93
|
|
|
if (in_array($receiverType, $businessProperty->getTypes())) { |
94
|
|
|
$businessEntity->setDisable(false); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $classes; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.