1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\APIBusinessEntityBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
6
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
8
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessor; |
11
|
|
|
use Victoire\Bundle\BusinessEntityBundle\Entity\BusinessEntity; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Api controller. |
15
|
|
|
* |
16
|
|
|
* @Route("/victoire-dcms/api") |
17
|
|
|
*/ |
18
|
|
|
class APIController extends Controller |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Method used to change of edit modefetch an api. |
22
|
|
|
* |
23
|
|
|
* @Route("/fetch/{businessEntity}", name="victoire_api_fetch", options={"expose"=true}) |
24
|
|
|
* |
25
|
|
|
* @ParamConverter() |
26
|
|
|
* |
27
|
|
|
* @return JsonResponse Empty response |
28
|
|
|
*/ |
29
|
|
|
public function fetchApiAction(Request $request, BusinessEntity $businessEntity) |
30
|
|
|
{ |
31
|
|
|
$accessor = new PropertyAccessor(); |
32
|
|
|
$businessParameter = $businessEntity->getBusinessPropertiesByType(['textable', 'businessParameter'])->first(); |
|
|
|
|
33
|
|
|
if (!$businessParameter) { |
34
|
|
|
throw new \Exception( |
35
|
|
|
sprintf('The BusinessEntity "%s" has no properties that are both "textable" and "BusinessParameter". it is needed to display a text to choose one', |
36
|
|
|
$businessEntity->getName()) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$filter = $request->query->get('q'); |
41
|
|
|
$businessEntities = $this->get('victoire_business_entity.resolver.business_entity_resolver')->searchBusinessEntities($businessEntity, $businessParameter, $filter); |
42
|
|
|
|
43
|
|
|
$results = []; |
44
|
|
|
foreach ($businessEntities as $_businessEntity) { |
45
|
|
|
$results[] = [ |
46
|
|
|
'id' => $accessor->getValue($_businessEntity, $businessEntity->getBusinessIdentifiers()->first()->getName()), |
47
|
|
|
'text' => $accessor->getValue($_businessEntity, $businessParameter->getName()), |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return new JsonResponse($results); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: