1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace FSi\Bundle\AdminBundle\Admin\ResourceRepository\Context; |
13
|
|
|
|
14
|
|
|
use FSi\Bundle\AdminBundle\Admin\Context\ContextAbstract; |
15
|
|
|
use FSi\Bundle\AdminBundle\Admin\Context\Request\HandlerInterface; |
16
|
|
|
use FSi\Bundle\AdminBundle\Admin\Element; |
17
|
|
|
use FSi\Bundle\AdminBundle\Event\AdminEvent; |
18
|
|
|
use FSi\Bundle\AdminBundle\Event\FormEvent; |
19
|
|
|
use FSi\Bundle\AdminBundle\Admin\ResourceRepository\Element as ResourceRepositoryElement; |
20
|
|
|
use FSi\Bundle\AdminBundle\Admin\ResourceRepository\ResourceFormBuilder; |
21
|
|
|
use Symfony\Component\Form\FormInterface; |
22
|
|
|
use Symfony\Component\HttpFoundation\Request; |
23
|
|
|
|
24
|
|
|
class ResourceRepositoryContext extends ContextAbstract |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var ResourceRepositoryElement |
28
|
|
|
*/ |
29
|
|
|
protected $element; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var ResourceFormBuilder |
33
|
|
|
*/ |
34
|
|
|
private $resourceFormBuilder; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var FormInterface |
38
|
|
|
*/ |
39
|
|
|
private $form; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param HandlerInterface[] $requestHandlers |
43
|
|
|
* @param string $template |
44
|
|
|
* @param ResourceFormBuilder $resourceFormBuilder |
45
|
|
|
*/ |
46
|
|
|
public function __construct( |
47
|
|
|
array $requestHandlers, |
48
|
|
|
string $template, |
49
|
|
|
ResourceFormBuilder $resourceFormBuilder |
50
|
|
|
) { |
51
|
|
|
parent::__construct($requestHandlers, $template); |
52
|
|
|
|
53
|
|
|
$this->resourceFormBuilder = $resourceFormBuilder; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setElement(Element $element): void |
57
|
|
|
{ |
58
|
|
|
$this->element = $element; |
|
|
|
|
59
|
|
|
$this->form = $this->resourceFormBuilder->build($this->element); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function hasTemplateName(): bool |
63
|
|
|
{ |
64
|
|
|
return $this->element->hasOption('template') || parent::hasTemplateName(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getTemplateName(): string |
68
|
|
|
{ |
69
|
|
|
return $this->element->hasOption('template') |
|
|
|
|
70
|
|
|
? $this->element->getOption('template') |
71
|
|
|
: parent::getTemplateName() |
72
|
|
|
; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getData(): array |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
|
|
'form' => $this->form->createView(), |
79
|
|
|
'element' => $this->element |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function createEvent(Request $request): AdminEvent |
84
|
|
|
{ |
85
|
|
|
return new FormEvent($this->element, $request, $this->form); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function getSupportedRoute(): string |
89
|
|
|
{ |
90
|
|
|
return 'fsi_admin_resource'; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
protected function supportsElement(Element $element): bool |
94
|
|
|
{ |
95
|
|
|
return $element instanceof ResourceRepositoryElement; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.