1
|
|
|
<?php |
2
|
|
|
namespace keeko\tools\generator\action\base; |
3
|
|
|
|
4
|
|
|
use gossi\codegen\model\PhpTrait; |
5
|
|
|
use keeko\core\schema\ActionSchema; |
6
|
|
|
use keeko\tools\generator\AbstractActionTraitGenerator; |
7
|
|
|
use keeko\tools\utils\NameUtils; |
8
|
|
|
|
9
|
|
|
class UpdateActionTraitGenerator extends AbstractActionTraitGenerator { |
10
|
|
|
|
11
|
|
|
/* (non-PHPdoc) |
12
|
|
|
* @see \keeko\tools\generator\AbstractTraitGenerator::addMethods() |
13
|
|
|
*/ |
14
|
|
|
protected function addMethods(PhpTrait $trait, ActionSchema $action) { |
15
|
|
|
$modelName = $this->modelService->getModelNameByAction($action); |
16
|
|
|
$modelVariableName = NameUtils::toCamelCase($modelName); |
17
|
|
|
$modelObjectName = NameUtils::toStudlyCase($modelName); |
18
|
|
|
$fullModelObjectName = $this->modelService->getFullModelObjectName($action); |
19
|
|
|
|
20
|
|
|
// method: configureParams(OptionsResolver $resolver) |
21
|
|
|
$this->addConfigureParamsMethod($trait, $this->twig->render('update-configureParams.twig')); |
22
|
|
|
|
23
|
|
|
// method: run(Request $request) |
24
|
|
|
$trait->addUseStatement($fullModelObjectName); |
25
|
|
|
$trait->addUseStatement($fullModelObjectName . 'Query'); |
26
|
|
|
$trait->addUseStatement('keeko\\core\\exceptions\\ValidationException'); |
27
|
|
|
$trait->addUseStatement('keeko\\core\\utils\\HydrateUtils'); |
28
|
|
|
$trait->addUseStatement('Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException'); |
29
|
|
|
$trait->setMethod($this->generateRunMethod($this->twig->render('update-run.twig', [ |
30
|
|
|
'model' => $modelVariableName, |
31
|
|
|
'class' => $modelObjectName, |
32
|
|
|
'fields' => $this->codegenService->getWriteFields($modelName) |
33
|
|
|
]))); |
34
|
|
|
} |
35
|
|
|
} |