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
Tags 0.6.0
1 merge request!10update to grifart/scaffolder ^0.5
Pipeline #31711 passed
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
"require": { "require": {
"php": "^8.0", "php": "^8.0",
"dibi/dibi": "^4.0.2", "dibi/dibi": "^4.0.2",
"grifart/scaffolder": "^0.4.0", "grifart/scaffolder": "^0.5.0",
"nette/utils": "^3.0.1" "nette/utils": "^3.0.1"
}, },
"require-dev": { "require-dev": {
......
...@@ -10,6 +10,7 @@ use Grifart\Tables\ModificationsTrait; ...@@ -10,6 +10,7 @@ use Grifart\Tables\ModificationsTrait;
use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\Parameter; use Nette\PhpGenerator\Parameter;
use Nette\PhpGenerator\PhpLiteral; use Nette\PhpGenerator\PhpLiteral;
use Nette\PhpGenerator\PhpNamespace;
final class ModificationsDecorator implements ClassDecorator final class ModificationsDecorator implements ClassDecorator
{ {
...@@ -28,11 +29,8 @@ 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); $namespace->addUse(ModificationsTrait::class);
$classType->addTrait(ModificationsTrait::class); $classType->addTrait(ModificationsTrait::class);
...@@ -47,7 +45,7 @@ final class ModificationsDecorator implements ClassDecorator ...@@ -47,7 +45,7 @@ final class ModificationsDecorator implements ClassDecorator
->setReturnType('self') ->setReturnType('self')
->setParameters([ ->setParameters([
(new Parameter('primaryKey')) (new Parameter('primaryKey'))
->setTypeHint($this->primaryKeyClass) ->setType($this->primaryKeyClass)
]) ])
->setBody('return self::_update($primaryKey);'); ->setBody('return self::_update($primaryKey);');
...@@ -68,7 +66,10 @@ final class ModificationsDecorator implements ClassDecorator ...@@ -68,7 +66,10 @@ final class ModificationsDecorator implements ClassDecorator
]); ]);
// modify*() methods // modify*() methods
foreach ($definition->getFields() as $fieldName => $type) { foreach ($definition->getFields() as $field) {
$fieldName = $field->getName();
$type = $field->getType();
// add getter // add getter
$modifier = $classType->addMethod('modify' . \ucfirst($fieldName)) $modifier = $classType->addMethod('modify' . \ucfirst($fieldName))
->setVisibility('public') ->setVisibility('public')
...@@ -90,10 +91,9 @@ final class ModificationsDecorator implements ClassDecorator ...@@ -90,10 +91,9 @@ final class ModificationsDecorator implements ClassDecorator
$docCommentType = $type->getDocCommentType($namespace); $docCommentType = $type->getDocCommentType($namespace);
$modifier->addComment(\sprintf( $modifier->addComment(\sprintf(
'@param %s $%s%s', '@param %s $%s',
$docCommentType, $docCommentType,
$fieldName, $fieldName,
$type->hasComment() ? ' ' . $type->getComment($namespace) : '',
)); ));
} }
} }
......
...@@ -5,11 +5,12 @@ namespace Grifart\Tables\Scaffolding; ...@@ -5,11 +5,12 @@ namespace Grifart\Tables\Scaffolding;
use Grifart\ClassScaffolder\Decorators\ClassDecorator; use Grifart\ClassScaffolder\Decorators\ClassDecorator;
use Grifart\ClassScaffolder\Definition\ClassDefinition; use Grifart\ClassScaffolder\Definition\ClassDefinition;
use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\PhpNamespace;
final class PrivateConstructorDecorator implements ClassDecorator 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(); $classType->getMethod('__construct')->setPrivate();
} }
......
...@@ -11,7 +11,7 @@ use Nette\PhpGenerator\Property; ...@@ -11,7 +11,7 @@ use Nette\PhpGenerator\Property;
final class ReconstituteConstructorDecorator implements ClassDecorator 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') $reconstitute = $classType->addMethod('reconstitute')
->setReturnType('static') ->setReturnType('static')
......
...@@ -5,7 +5,6 @@ namespace Grifart\Tables\Scaffolding; ...@@ -5,7 +5,6 @@ namespace Grifart\Tables\Scaffolding;
use Grifart\ClassScaffolder\Decorators\ClassDecorator; use Grifart\ClassScaffolder\Decorators\ClassDecorator;
use Grifart\ClassScaffolder\Decorators\DecoratorTools;
use Grifart\ClassScaffolder\Definition\ClassDefinition; use Grifart\ClassScaffolder\Definition\ClassDefinition;
use Grifart\ClassScaffolder\Definition\Types\Type; use Grifart\ClassScaffolder\Definition\Types\Type;
use Grifart\Tables\CaseConvertion; use Grifart\Tables\CaseConvertion;
...@@ -53,10 +52,8 @@ final class TableDecorator implements ClassDecorator ...@@ -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 // implements table
$namespace->addUse(Table::class); $namespace->addUse(Table::class);
$classType->addImplement(Table::class); $classType->addImplement(Table::class);
...@@ -101,7 +98,7 @@ final class TableDecorator implements ClassDecorator ...@@ -101,7 +98,7 @@ final class TableDecorator implements ClassDecorator
$classType->addMethod('find') $classType->addMethod('find')
->setParameters([ ->setParameters([
(new Code\Parameter('primaryKey')) (new Code\Parameter('primaryKey'))
->setTypeHint($this->primaryKeyClass) ->setType($this->primaryKeyClass)
]) ])
->setReturnType($this->rowClass) ->setReturnType($this->rowClass)
->setReturnNullable() ->setReturnNullable()
...@@ -116,7 +113,7 @@ final class TableDecorator implements ClassDecorator ...@@ -116,7 +113,7 @@ final class TableDecorator implements ClassDecorator
$classType->addMethod('get') $classType->addMethod('get')
->setParameters([ ->setParameters([
(new Code\Parameter('primaryKey')) (new Code\Parameter('primaryKey'))
->setTypeHint($this->primaryKeyClass) ->setType($this->primaryKeyClass)
]) ])
->setReturnType($this->rowClass) ->setReturnType($this->rowClass)
->addComment('@throws RowNotFound') ->addComment('@throws RowNotFound')
...@@ -131,7 +128,7 @@ final class TableDecorator implements ClassDecorator ...@@ -131,7 +128,7 @@ final class TableDecorator implements ClassDecorator
$classType->addMethod('findBy') $classType->addMethod('findBy')
->setParameters([ ->setParameters([
(new Code\Parameter('conditions')) (new Code\Parameter('conditions'))
->setTypeHint('array') ->setType('array')
]) ])
->setComment('@return ' . $namespace->unresolveName($this->rowClass) . '[]') ->setComment('@return ' . $namespace->unresolveName($this->rowClass) . '[]')
->setReturnType('array') ->setReturnType('array')
...@@ -169,10 +166,9 @@ final class TableDecorator implements ClassDecorator ...@@ -169,10 +166,9 @@ final class TableDecorator implements ClassDecorator
if ($fieldType->requiresDocComment()) { if ($fieldType->requiresDocComment()) {
$newMethod->addComment(\sprintf( $newMethod->addComment(\sprintf(
'@param %s $%s%s', '@param %s $%s',
$fieldType->getDocCommentType($namespace), $fieldType->getDocCommentType($namespace),
$fieldName, $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