Skip to content
Snippets Groups Projects
Commit 47a9b90a authored by Jan Kuchař's avatar Jan Kuchař
Browse files

Merge branch 'update-to-scaffolder-5' into 'master'

update to grifart/scaffolder ^0.5

See merge request !10
parents d5d30557 5b4147d7
No related branches found
No related tags found
1 merge request!10update to grifart/scaffolder ^0.5
Pipeline #31711 passed
......@@ -24,7 +24,7 @@
"require": {
"php": "^8.0",
"dibi/dibi": "^4.0.2",
"grifart/scaffolder": "^0.4.0",
"grifart/scaffolder": "^0.5.0",
"nette/utils": "^3.0.1"
},
"require-dev": {
......
......@@ -10,6 +10,7 @@ use Grifart\Tables\ModificationsTrait;
use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\Parameter;
use Nette\PhpGenerator\PhpLiteral;
use Nette\PhpGenerator\PhpNamespace;
final class ModificationsDecorator implements ClassDecorator
{
......@@ -28,11 +29,8 @@ final class ModificationsDecorator implements ClassDecorator
}
public function decorate(ClassType $classType, ClassDefinition $definition): void
public function decorate(PhpNamespace $namespace, ClassType $classType, ClassDefinition $definition): void
{
$namespace = $classType->getNamespace();
\assert($namespace !== NULL, 'Class Generator always generate class in namespace.');
$namespace->addUse(ModificationsTrait::class);
$classType->addTrait(ModificationsTrait::class);
......@@ -47,7 +45,7 @@ final class ModificationsDecorator implements ClassDecorator
->setReturnType('self')
->setParameters([
(new Parameter('primaryKey'))
->setTypeHint($this->primaryKeyClass)
->setType($this->primaryKeyClass)
])
->setBody('return self::_update($primaryKey);');
......@@ -68,7 +66,10 @@ final class ModificationsDecorator implements ClassDecorator
]);
// modify*() methods
foreach ($definition->getFields() as $fieldName => $type) {
foreach ($definition->getFields() as $field) {
$fieldName = $field->getName();
$type = $field->getType();
// add getter
$modifier = $classType->addMethod('modify' . \ucfirst($fieldName))
->setVisibility('public')
......@@ -90,10 +91,9 @@ final class ModificationsDecorator implements ClassDecorator
$docCommentType = $type->getDocCommentType($namespace);
$modifier->addComment(\sprintf(
'@param %s $%s%s',
'@param %s $%s',
$docCommentType,
$fieldName,
$type->hasComment() ? ' ' . $type->getComment($namespace) : '',
));
}
}
......
......@@ -5,11 +5,12 @@ namespace Grifart\Tables\Scaffolding;
use Grifart\ClassScaffolder\Decorators\ClassDecorator;
use Grifart\ClassScaffolder\Definition\ClassDefinition;
use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\PhpNamespace;
final class PrivateConstructorDecorator implements ClassDecorator
{
public function decorate(ClassType $classType, ClassDefinition $definition): void
public function decorate(PhpNamespace $namespace, ClassType $classType, ClassDefinition $definition): void
{
$classType->getMethod('__construct')->setPrivate();
}
......
......@@ -11,7 +11,7 @@ use Nette\PhpGenerator\Property;
final class ReconstituteConstructorDecorator implements ClassDecorator
{
public function decorate(ClassType $classType, ClassDefinition $definition): void
public function decorate(Code\PhpNamespace $namespace, ClassType $classType, ClassDefinition $definition): void
{
$reconstitute = $classType->addMethod('reconstitute')
->setReturnType('static')
......
......@@ -5,7 +5,6 @@ namespace Grifart\Tables\Scaffolding;
use Grifart\ClassScaffolder\Decorators\ClassDecorator;
use Grifart\ClassScaffolder\Decorators\DecoratorTools;
use Grifart\ClassScaffolder\Definition\ClassDefinition;
use Grifart\ClassScaffolder\Definition\Types\Type;
use Grifart\Tables\CaseConvertion;
......@@ -53,10 +52,8 @@ final class TableDecorator implements ClassDecorator
}
public function decorate(Code\ClassType $classType, ClassDefinition $definition): void
public function decorate(Code\PhpNamespace $namespace, Code\ClassType $classType, ClassDefinition $definition): void
{
$namespace = DecoratorTools::extractNamespace($classType);
// implements table
$namespace->addUse(Table::class);
$classType->addImplement(Table::class);
......@@ -101,7 +98,7 @@ final class TableDecorator implements ClassDecorator
$classType->addMethod('find')
->setParameters([
(new Code\Parameter('primaryKey'))
->setTypeHint($this->primaryKeyClass)
->setType($this->primaryKeyClass)
])
->setReturnType($this->rowClass)
->setReturnNullable()
......@@ -116,7 +113,7 @@ final class TableDecorator implements ClassDecorator
$classType->addMethod('get')
->setParameters([
(new Code\Parameter('primaryKey'))
->setTypeHint($this->primaryKeyClass)
->setType($this->primaryKeyClass)
])
->setReturnType($this->rowClass)
->addComment('@throws RowNotFound')
......@@ -131,7 +128,7 @@ final class TableDecorator implements ClassDecorator
$classType->addMethod('findBy')
->setParameters([
(new Code\Parameter('conditions'))
->setTypeHint('array')
->setType('array')
])
->setComment('@return ' . $namespace->unresolveName($this->rowClass) . '[]')
->setReturnType('array')
......@@ -169,10 +166,9 @@ final class TableDecorator implements ClassDecorator
if ($fieldType->requiresDocComment()) {
$newMethod->addComment(\sprintf(
'@param %s $%s%s',
'@param %s $%s',
$fieldType->getDocCommentType($namespace),
$fieldName,
$fieldType->hasComment() ? ' ' . $fieldType->getComment($namespace) : '',
));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment