1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kami\ApiCoreBundle\RequestProcessor\Step\Create; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\Reader; |
6
|
|
|
use Kami\ApiCoreBundle\Annotation\Form; |
7
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\Step\AbstractBuildFormStep; |
8
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\GetEntityFromReflectionStep; |
9
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\GetReflectionFromRequestStep; |
10
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\ValidateResourceAccessStep; |
11
|
|
|
use Kami\ApiCoreBundle\Security\AccessManager; |
12
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class BuildCreateFormStep extends AbstractBuildFormStep |
16
|
|
|
{ |
17
|
|
|
public function execute() |
18
|
|
|
{ |
19
|
|
|
$builder = $this->getBaseFormBuilder(); |
20
|
|
|
/** @var \ReflectionClass $reflection */ |
21
|
|
|
$reflection = $this->getFromResponse('reflection'); |
22
|
|
|
|
23
|
|
|
foreach ($reflection->getProperties() as $property) { |
24
|
|
|
if ($this->accessManager->canCreateProperty($property)) { |
25
|
|
|
if ($annotation = $this->reader->getPropertyAnnotation($property, Form::class)) { |
26
|
|
|
$builder->add($property->getName(), $annotation->type, $annotation->options); |
27
|
|
|
} |
28
|
|
|
$builder->add($property->getName()); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return $this->createResponse(['form' => $builder->getForm()]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function requiresBefore() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
ValidateResourceAccessStep::class, |
40
|
|
|
GetEntityFromReflectionStep::class, |
41
|
|
|
GetReflectionFromRequestStep::class |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
} |