1
|
|
|
<?php |
2
|
|
|
namespace keeko\tools\generator\responder; |
3
|
|
|
|
4
|
|
|
use gossi\codegen\model\PhpClass; |
5
|
|
|
use keeko\framework\schema\ActionSchema; |
6
|
|
|
use keeko\framework\utils\NameUtils; |
7
|
|
|
use Propel\Generator\Model\Table; |
8
|
|
|
use keeko\tools\services\CommandService; |
9
|
|
|
|
10
|
|
|
class ToManyRelationshipJsonResponderGenerator extends AbstractPayloadJsonResponderGenerator { |
11
|
|
|
|
12
|
|
|
/** @var Table */ |
13
|
|
|
private $foreign; |
14
|
|
|
|
15
|
|
|
/** @var Table */ |
16
|
|
|
private $model; |
17
|
|
|
|
18
|
|
|
public function __construct(CommandService $service, Table $model, Table $foreign) { |
19
|
|
|
parent::__construct($service); |
20
|
|
|
$this->model = $model; |
21
|
|
|
$this->foreign = $foreign; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function addMethods(PhpClass $class, ActionSchema $action) { |
25
|
|
|
$this->generateGetPayloadMethods($class, $this->twig->render('to-many/getPayloadMethods.twig')); |
26
|
|
|
$this->generateNotValid($class); |
27
|
|
|
$this->generateNotFound($class); |
28
|
|
|
|
29
|
|
|
// method: updated(Request $request, Updated $payload) : JsonResponse |
30
|
|
|
$modelName = $this->modelService->getModelNameByAction($action); |
31
|
|
|
$model = $this->modelService->getModel($modelName); |
32
|
|
|
|
33
|
|
|
$updated = $this->generatePayloadMethod('updated', $this->twig->render('to-many/updated.twig', [ |
34
|
|
|
'class' => $model->getPhpName(), |
35
|
|
|
'related' => NameUtils::pluralize($this->foreign->getCamelCaseName()) |
36
|
|
|
]), 'Updated'); |
37
|
|
|
|
38
|
|
|
$class->setMethod($updated); |
39
|
|
|
$class->addUseStatement('keeko\\framework\\domain\\payload\\Updated'); |
40
|
|
|
$class->addUseStatement($this->model->getNamespace() . '\\' . $this->model->getPhpName()); |
41
|
|
|
|
42
|
|
|
// method: notUpdated(Request $request, NotUpdated $payload) : JsonResponse |
43
|
|
|
$notUpdated = $this->generatePayloadMethod('notUpdated', $this->twig->render('payload/notUpdated.twig'), |
44
|
|
|
'NotUpdated'); |
45
|
|
|
$class->setMethod($notUpdated); |
46
|
|
|
$class->addUseStatement('keeko\\framework\\domain\\payload\\NotUpdated'); |
47
|
|
|
} |
48
|
|
|
} |