|
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 keeko\tools\model\ManyRelationship; |
|
8
|
|
|
use keeko\tools\services\CommandService; |
|
9
|
|
|
|
|
10
|
|
|
class ToManyRelationshipJsonResponderGenerator extends AbstractPayloadJsonResponderGenerator { |
|
11
|
|
|
|
|
12
|
|
|
/** @var ManyRelationship */ |
|
13
|
|
|
private $relationship; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct(CommandService $service, ManyRelationship $relationship) { |
|
16
|
|
|
parent::__construct($service); |
|
17
|
|
|
$this->relationship = $relationship; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
protected function addMethods(PhpClass $class, ActionSchema $action) { |
|
|
|
|
|
|
21
|
|
|
$this->generateGetPayloadMethods($class, $this->twig->render('to-many/getPayloadMethods.twig')); |
|
22
|
|
|
$this->generateNotValid($class); |
|
23
|
|
|
$this->generateNotFound($class); |
|
24
|
|
|
|
|
25
|
|
|
// method: updated(Request $request, Updated $payload) : JsonResponse |
|
26
|
|
|
$model = $this->relationship->getModel(); |
|
27
|
|
|
$updated = $this->generatePayloadMethod('updated', $this->twig->render('to-many/updated.twig', [ |
|
28
|
|
|
'class' => $model->getPhpName(), |
|
29
|
|
|
'related' => NameUtils::pluralize(NameUtils::toCamelCase($this->relationship->getRelatedName())) |
|
30
|
|
|
]), 'Updated'); |
|
31
|
|
|
|
|
32
|
|
|
$class->setMethod($updated); |
|
33
|
|
|
$class->addUseStatement('keeko\\framework\\domain\\payload\\Updated'); |
|
34
|
|
|
$class->addUseStatement($model->getNamespace() . '\\' . $model->getPhpName()); |
|
35
|
|
|
|
|
36
|
|
|
// method: notUpdated(Request $request, NotUpdated $payload) : JsonResponse |
|
37
|
|
|
$notUpdated = $this->generatePayloadMethod('notUpdated', $this->twig->render('payload/notUpdated.twig'), |
|
38
|
|
|
'NotUpdated'); |
|
39
|
|
|
$class->setMethod($notUpdated); |
|
40
|
|
|
$class->addUseStatement('keeko\\framework\\domain\\payload\\NotUpdated'); |
|
41
|
|
|
} |
|
42
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.