This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Victoire\Bundle\APIBusinessEntityBundle\Resolver; |
||
4 | |||
5 | use Victoire\Bundle\APIBusinessEntityBundle\Chain\ApiAuthenticationChain; |
||
6 | use Victoire\Bundle\APIBusinessEntityBundle\Entity\APIBusinessEntity; |
||
7 | use Victoire\Bundle\APIBusinessEntityBundle\Entity\APIEndpoint; |
||
8 | use Victoire\Bundle\BusinessEntityBundle\Converter\ParameterConverter; |
||
9 | use Victoire\Bundle\BusinessEntityBundle\Entity\BusinessProperty; |
||
10 | use Victoire\Bundle\BusinessEntityBundle\Resolver\BusinessEntityResolverInterface; |
||
11 | use Victoire\Bundle\CoreBundle\Entity\EntityProxy; |
||
12 | |||
13 | /** |
||
14 | * Class APIBusinessEntityResolver. |
||
15 | */ |
||
16 | class APIBusinessEntityResolver implements BusinessEntityResolverInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var ParameterConverter |
||
20 | */ |
||
21 | private $parameterConverter; |
||
22 | /** |
||
23 | * @var ApiAuthenticationChain |
||
24 | */ |
||
25 | private $authenticationChain; |
||
26 | |||
27 | /** |
||
28 | * APIBusinessEntityResolver constructor. |
||
29 | * |
||
30 | * @param ParameterConverter $parameterConverter |
||
31 | * @param ApiAuthenticationChain $authenticationChain |
||
32 | */ |
||
33 | public function __construct(ParameterConverter $parameterConverter, APIAuthenticationChain $authenticationChain) |
||
34 | { |
||
35 | $this->parameterConverter = $parameterConverter; |
||
36 | $this->authenticationChain = $authenticationChain; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Fetch API to get a single entity. |
||
41 | * |
||
42 | * @param EntityProxy $entityProxy |
||
43 | * |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function getBusinessEntity(EntityProxy $entityProxy) |
||
47 | { |
||
48 | /** @var APIBusinessEntity $businessEntity */ |
||
49 | $businessEntity = $entityProxy->getBusinessEntity(); |
||
50 | $getMethod = $businessEntity->getGetMethod(); |
||
51 | preg_match_all('/{{([a-zA-Z]+)}}/', $getMethod, $matches); |
||
52 | // build an array with businessIdentifiers properties names |
||
53 | $identifiers = array_map(function ($property) { |
||
54 | return $property->getName(); |
||
55 | }, |
||
56 | $businessEntity->getBusinessIdentifiers()->toArray() |
||
57 | ); |
||
58 | foreach ($matches[1] as $match) { |
||
59 | if (in_array($match, $identifiers)) { |
||
60 | $value = $entityProxy->getRessourceId(); |
||
61 | } else { |
||
62 | $props = $entityProxy->getAdditionnalProperties(); |
||
63 | $value = $props[$match]; |
||
64 | } |
||
65 | $getMethod = $this->parameterConverter->convert($getMethod, $match, $value); |
||
66 | } |
||
67 | |||
68 | $entity = $this->callApi($businessEntity->getEndpoint(), $getMethod); |
||
69 | // Then the BusinessEntity is an API result, it's not a proper object but a decoded json result. |
||
70 | // It has no classname so we cannot resolve the related BusinessEntity definition, so we |
||
71 | // store the businessEntity object into the entity. |
||
72 | $entity->_businessEntity = $entityProxy->getBusinessEntity(); |
||
73 | |||
74 | return $entity; |
||
75 | } |
||
76 | |||
77 | /** |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
78 | * Fetch API to get a list of entities. |
||
79 | * |
||
80 | * @param APIBusinessEntity $businessEntity |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | public function getBusinessEntities(APIBusinessEntity $businessEntity, $page = 1) |
||
85 | { |
||
86 | $data = $this->callApi($businessEntity->getEndpoint(), $businessEntity->getListMethod($page)); |
||
87 | |||
88 | foreach ($data as $entity) { |
||
89 | $entity->_businessEntity = $businessEntity; |
||
90 | } |
||
91 | if (count($data) > 0) { |
||
92 | $data = array_merge($data, $this->getBusinessEntities($businessEntity, ++$page)); |
||
93 | } |
||
94 | |||
95 | return $data; |
||
96 | } |
||
97 | |||
98 | /** |
||
0 ignored issues
–
show
|
|||
99 | * filter API to get a list of entities. |
||
100 | * |
||
101 | * @param APIBusinessEntity $businessEntity |
||
102 | * @param array $filter |
||
0 ignored issues
–
show
|
|||
103 | * |
||
104 | * @return mixed |
||
105 | */ |
||
106 | public function searchBusinessEntities(APIBusinessEntity $businessEntity, BusinessProperty $businessProperty, $filter) |
||
107 | { |
||
108 | $getMethod = $businessEntity->getListMethod() |
||
109 | .(false !== strpos($businessEntity->getListMethod(), '?') ? '&' : '?') |
||
0 ignored issues
–
show
|
|||
110 | .$businessProperty->getFilterMethod(); |
||
0 ignored issues
–
show
|
|||
111 | $getMethod = preg_replace('/{{([a-zA-Z]+)}}/', $filter, $getMethod); |
||
112 | |||
113 | $data = $this->callApi($businessEntity->getEndpoint(), $getMethod); |
||
114 | |||
115 | foreach ($data as $entity) { |
||
116 | $entity->businessEntity = $businessEntity; |
||
117 | } |
||
118 | |||
119 | return $data; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Sends a curl request to a given path. |
||
124 | * |
||
125 | * @param APIEndpoint $endPoint |
||
126 | * @param string $getMethod |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | protected function callApi(APIEndpoint $endPoint, $getMethod) |
||
131 | { |
||
132 | $host = $endPoint->getHost(); |
||
133 | $token = $endPoint->getToken(); |
||
134 | $curl = curl_init(); |
||
135 | if ($tokenType = $endPoint->getTokenType()) { |
||
136 | $this->authenticationChain->resolve($tokenType)->handle($curl, $getMethod, $token); |
||
137 | } |
||
138 | curl_setopt($curl, CURLOPT_URL, $host.$getMethod); |
||
139 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
||
140 | |||
141 | $result = curl_exec($curl); |
||
142 | |||
143 | curl_close($curl); |
||
144 | |||
145 | return json_decode($result); |
||
146 | } |
||
147 | } |
||
148 |