diff --git a/src/EntityGenerator.php b/src/EntityGenerator.php index b96d8c4..2681069 100644 --- a/src/EntityGenerator.php +++ b/src/EntityGenerator.php @@ -7,6 +7,7 @@ use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\PhpFile; +use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\PsrPrinter; use RZ\Roadiz\Contracts\NodeType\NodeTypeFieldInterface; use RZ\Roadiz\Contracts\NodeType\NodeTypeInterface; @@ -161,15 +162,19 @@ public function getClassContent(): string $namespace = $file ->addNamespace(trim($this->options['namespace'], '\\')) + ->addUse('ApiPlatform\Metadata\ApiFilter') + ->addUse('ApiPlatform\Metadata\ApiProperty') + ->addUse('ApiPlatform\Serializer\Filter\PropertyFilter') + ->addUse('ApiPlatform\Doctrine\Orm\Filter', 'Filter') + ->addUse('Doctrine\Common\Collections\Collection') + ->addUse($this->options['parent_class']) ->addUse('Doctrine\ORM\Mapping', 'ORM') - ->addUse('JMS\Serializer\Annotation', 'JMS') - ->addUse('Symfony\Component\Serializer\Attribute', 'Serializer') ->addUse('Gedmo\Mapping\Annotation', 'Gedmo') - ->addUse('ApiPlatform\Metadata\ApiFilter') + ->addUse('JMS\Serializer\Annotation', 'JMS') ->addUse('RZ\Roadiz\CoreBundle\Entity\Node') ->addUse('RZ\Roadiz\CoreBundle\Entity\Translation') - ->addUse('ApiPlatform\Metadata\ApiProperty') - ->addUse('Doctrine\Common\Collections\Collection') + ->addUse('RZ\Roadiz\CoreBundle\Entity\UserLogEntry') + ->addUse('Symfony\Component\Serializer\Attribute', 'Serializer') ; $classType = $namespace->addClass($this->nodeType->getSourceEntityClassName()) @@ -178,8 +183,8 @@ public function getClassContent(): string ->addComment($this->nodeType->getDescription() ?? ''); $this - ->addClassAttributes($classType) - ->addClassFields($classType) + ->addClassAttributes($classType, $namespace) + ->addClassFields($classType, $namespace) ->addClassConstructor($classType) ->addClassCloneMethod($classType) ->addClassMethods($classType) @@ -187,16 +192,16 @@ public function getClassContent(): string return (new PsrPrinter())->printFile($file); } - private function addClassAttributes(ClassType $classType): self + private function addClassAttributes(ClassType $classType, PhpNamespace $namespace): self { $classType ->addAttribute( 'Gedmo\Mapping\Annotation\Loggable', - ['logEntryClass' => new Literal('\RZ\Roadiz\CoreBundle\Entity\UserLogEntry::class')] + ['logEntryClass' => new Literal('UserLogEntry::class')] ) ->addAttribute( 'Doctrine\ORM\Mapping\Entity', - ['repositoryClass' => new Literal($this->options['repository_class'] . '::class')] + ['repositoryClass' => new Literal($namespace->simplifyName($this->options['repository_class']) . '::class')] ) ->addAttribute( 'Doctrine\ORM\Mapping\Table', @@ -211,7 +216,7 @@ private function addClassAttributes(ClassType $classType): self if ($this->options['use_api_platform_filters'] === true) { $classType->addAttribute( 'ApiPlatform\Metadata\ApiFilter', - [new Literal('\ApiPlatform\Serializer\Filter\PropertyFilter::class')] + [new Literal($namespace->simplifyName('\ApiPlatform\Serializer\Filter\PropertyFilter') . '::class')] ); } @@ -219,10 +224,10 @@ private function addClassAttributes(ClassType $classType): self } - private function addClassFields(ClassType $classType): self + private function addClassFields(ClassType $classType, PhpNamespace $namespace): self { foreach ($this->fieldGenerators as $fieldGenerator) { - $fieldGenerator->addField($classType); + $fieldGenerator->addField($classType, $namespace); } return $this; } diff --git a/src/Field/AbstractFieldGenerator.php b/src/Field/AbstractFieldGenerator.php index 8bf539e..18c6f4e 100644 --- a/src/Field/AbstractFieldGenerator.php +++ b/src/Field/AbstractFieldGenerator.php @@ -7,6 +7,7 @@ use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\Method; +use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\Property; use RZ\Roadiz\Contracts\NodeType\NodeTypeFieldInterface; use RZ\Roadiz\Contracts\NodeType\SerializableInterface; @@ -24,14 +25,14 @@ public function __construct( /** * Generate PHP code for current doctrine field. */ - public function addField(ClassType $classType): void + public function addField(ClassType $classType, PhpNamespace $namespace): void { $property = $this->getFieldProperty($classType); $this ->addFieldAnnotation($property) - ->addFieldAttributes($property, $this->isExcludingFieldFromJmsSerialization()) - ->addFieldGetter($classType) + ->addFieldAttributes($property, $namespace, $this->isExcludingFieldFromJmsSerialization()) + ->addFieldGetter($classType, $namespace) ->addFieldAlternativeGetter($classType) ->addFieldSetter($classType) ; @@ -89,7 +90,7 @@ protected function getFieldDefaultValueDeclaration(): Literal|string|null return null; } - protected function addFieldAttributes(Property $property, bool $exclude = false): self + protected function addFieldAttributes(Property $property, PhpNamespace $namespace, bool $exclude = false): self { if ($exclude) { $property->addAttribute('JMS\Serializer\Annotation\Exclude'); @@ -139,56 +140,56 @@ protected function addFieldAttributes(Property $property, bool $exclude = false) switch (true) { case $this->field->isString(): $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - 0 => new Literal('\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class'), + 0 => new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\SearchFilter') . '::class'), 'strategy' => 'partial' ]); $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\RZ\Roadiz\CoreBundle\Api\Filter\NotFilter::class') + new Literal($namespace->simplifyName('\RZ\Roadiz\CoreBundle\Api\Filter\NotFilter') . '::class') ]); break; case $this->field->isMultiple(): case $this->field->isEnum(): $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - 0 => new Literal('\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class'), + 0 => new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\SearchFilter') . '::class'), 'strategy' => 'exact' ]); $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\RZ\Roadiz\CoreBundle\Api\Filter\NotFilter::class') + new Literal($namespace->simplifyName('\RZ\Roadiz\CoreBundle\Api\Filter\NotFilter') . '::class') ]); break; case $this->field->isBool(): $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\ApiPlatform\Doctrine\Orm\Filter\OrderFilter::class'), + new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\OrderFilter') . '::class'), ]); $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\ApiPlatform\Doctrine\Orm\Filter\BooleanFilter::class'), + new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\BooleanFilter') . '::class'), ]); break; case $this->field->isManyToOne(): case $this->field->isManyToMany(): $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\ApiPlatform\Doctrine\Orm\Filter\ExistsFilter::class'), + new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\ExistsFilter') . '::class'), ]); break; case $this->field->isInteger(): case $this->field->isDecimal(): $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\ApiPlatform\Doctrine\Orm\Filter\OrderFilter::class'), + new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\OrderFilter') . '::class'), ]); $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\ApiPlatform\Doctrine\Orm\Filter\NumericFilter::class'), + new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\NumericFilter') . '::class'), ]); $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\ApiPlatform\Doctrine\Orm\Filter\RangeFilter::class'), + new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\RangeFilter') . '::class'), ]); break; case $this->field->isDate(): case $this->field->isDateTime(): $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\ApiPlatform\Doctrine\Orm\Filter\OrderFilter::class'), + new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\OrderFilter') . '::class'), ]); $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - new Literal('\ApiPlatform\Doctrine\Orm\Filter\DateFilter::class'), + new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\DateFilter') . '::class'), ]); break; } @@ -200,7 +201,7 @@ protected function addFieldAttributes(Property $property, bool $exclude = false) /** * Generate PHP alternative getter method block. */ - abstract protected function addFieldGetter(ClassType $classType): self; + abstract protected function addFieldGetter(ClassType $classType, PhpNamespace $namespace): self; /** * Generate PHP alternative getter method block. diff --git a/src/Field/CustomFormsFieldGenerator.php b/src/Field/CustomFormsFieldGenerator.php index 2c93880..b09c1d5 100644 --- a/src/Field/CustomFormsFieldGenerator.php +++ b/src/Field/CustomFormsFieldGenerator.php @@ -7,6 +7,7 @@ use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\Method; +use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\Property; final class CustomFormsFieldGenerator extends AbstractFieldGenerator @@ -39,7 +40,7 @@ protected function getFieldDefaultValueDeclaration(): Literal|string|null return new Literal('null'); } - public function addFieldGetter(ClassType $classType): self + public function addFieldGetter(ClassType $classType, PhpNamespace $namespace): self { $method = $classType ->addMethod($this->field->getGetterName()) @@ -53,7 +54,7 @@ public function addFieldGetter(ClassType $classType): self if (null === \$this->{$this->field->getVarName()}) { if (null !== \$this->objectManager) { \$this->{$this->field->getVarName()} = \$this->objectManager - ->getRepository({$this->options['custom_form_class']}::class) + ->getRepository({$namespace->simplifyName($this->options['custom_form_class'])}::class) ->findByNodeAndFieldName( \$this->getNode(), '{$this->field->getName()}' diff --git a/src/Field/DocumentsFieldGenerator.php b/src/Field/DocumentsFieldGenerator.php index ba30e45..c750129 100644 --- a/src/Field/DocumentsFieldGenerator.php +++ b/src/Field/DocumentsFieldGenerator.php @@ -7,6 +7,7 @@ use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\Method; +use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\Property; use Symfony\Component\String\UnicodeString; @@ -45,7 +46,7 @@ protected function getFieldDefaultValueDeclaration(): Literal|string|null return new Literal('null'); } - public function addFieldGetter(ClassType $classType): self + public function addFieldGetter(ClassType $classType, PhpNamespace $namespace): self { $getter = $classType->addMethod($this->field->getGetterName()) ->setReturnType('array') @@ -55,7 +56,7 @@ public function addFieldGetter(ClassType $classType): self if (null === \$this->{$this->field->getVarName()}) { if (null !== \$this->objectManager) { \$this->{$this->field->getVarName()} = \$this->objectManager - ->getRepository({$this->options['document_class']}::class) + ->getRepository({$namespace->simplifyName($this->options['document_class'])}::class) ->findByNodeSourceAndFieldName( \$this, '{$this->field->getName()}' diff --git a/src/Field/ManyToManyFieldGenerator.php b/src/Field/ManyToManyFieldGenerator.php index de2cb74..5bb5388 100644 --- a/src/Field/ManyToManyFieldGenerator.php +++ b/src/Field/ManyToManyFieldGenerator.php @@ -6,6 +6,7 @@ use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; +use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\Property; use Symfony\Component\String\UnicodeString; @@ -20,9 +21,9 @@ protected function getFieldProperty(ClassType $classType): Property } - protected function addFieldAttributes(Property $property, bool $exclude = false): self + protected function addFieldAttributes(Property $property, PhpNamespace $namespace, bool $exclude = false): self { - parent::addFieldAttributes($property, $exclude); + parent::addFieldAttributes($property, $namespace, $exclude); /* * Many Users have Many Groups. @@ -73,7 +74,7 @@ protected function addFieldAttributes(Property $property, bool $exclude = false) if ($this->options['use_api_platform_filters'] === true) { $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - 0 => new Literal('\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class'), + 0 => new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\SearchFilter') . '::class'), 'strategy' => 'exact' ]); } @@ -97,13 +98,18 @@ protected function getFieldTypeDeclaration(): string return '\Doctrine\Common\Collections\Collection'; } - public function addFieldGetter(ClassType $classType): self + public function addFieldGetter(ClassType $classType, PhpNamespace $namespace): self { $classType->addMethod($this->field->getGetterName()) ->setReturnType('\Doctrine\Common\Collections\Collection') ->setPublic() ->setBody('return $this->' . $this->field->getVarName() . ';') - ->addComment('@return \Doctrine\Common\Collections\CollectiongetFullyQualifiedClassName() . '>'); + ->addComment( + '@return ' . + $namespace->simplifyName('\Doctrine\Common\Collections\Collection') . + 'getFullyQualifiedClassName() . + '>' + ); return $this; } diff --git a/src/Field/ManyToOneFieldGenerator.php b/src/Field/ManyToOneFieldGenerator.php index 6726efb..a35bad0 100644 --- a/src/Field/ManyToOneFieldGenerator.php +++ b/src/Field/ManyToOneFieldGenerator.php @@ -6,13 +6,14 @@ use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; +use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\Property; final class ManyToOneFieldGenerator extends AbstractConfigurableFieldGenerator { - protected function addFieldAttributes(Property $property, bool $exclude = false): self + protected function addFieldAttributes(Property $property, PhpNamespace $namespace, bool $exclude = false): self { - parent::addFieldAttributes($property, $exclude); + parent::addFieldAttributes($property, $namespace, $exclude); /* * Many Users have One Address. @@ -31,7 +32,7 @@ protected function addFieldAttributes(Property $property, bool $exclude = false) if ($this->options['use_api_platform_filters'] === true) { $property->addAttribute('ApiPlatform\Metadata\ApiFilter', [ - 0 => new Literal('\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class'), + 0 => new Literal($namespace->simplifyName('\ApiPlatform\Doctrine\Orm\Filter\SearchFilter') . '::class'), 'strategy' => 'exact' ]); } @@ -61,7 +62,7 @@ protected function getFieldDefaultValueDeclaration(): Literal|string|null return new Literal('null'); } - public function addFieldGetter(ClassType $classType): self + public function addFieldGetter(ClassType $classType, PhpNamespace $namespace): self { $classType->addMethod($this->field->getGetterName()) ->setReturnType($this->getFieldTypeDeclaration()) diff --git a/src/Field/NodesFieldGenerator.php b/src/Field/NodesFieldGenerator.php index e93fb63..9a64c21 100644 --- a/src/Field/NodesFieldGenerator.php +++ b/src/Field/NodesFieldGenerator.php @@ -5,8 +5,8 @@ namespace RZ\Roadiz\EntityGenerator\Field; use Nette\PhpGenerator\ClassType; -use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\Method; +use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\Property; use RZ\Roadiz\Contracts\NodeType\NodeTypeFieldInterface; use RZ\Roadiz\Contracts\NodeType\NodeTypeResolverInterface; @@ -23,9 +23,9 @@ public function __construct( parent::__construct($field, $defaultValuesResolver, $options); } - public function addField(ClassType $classType): void + public function addField(ClassType $classType, PhpNamespace $namespace): void { - $this->addFieldGetter($classType); + $this->addFieldGetter($classType, $namespace); $this->addFieldSetter($classType); } @@ -89,7 +89,7 @@ protected function getRepositoryClass(): string return $this->options['parent_class']; } - public function addFieldGetter(ClassType $classType): self + public function addFieldGetter(ClassType $classType, PhpNamespace $namespace): self { $property = $classType->addProperty($this->getFieldSourcesName()) ->setType('?array') @@ -99,7 +99,7 @@ public function addFieldGetter(ClassType $classType): self ->addComment('@var ' . $this->getRepositoryClass() . '[]|null'); $this->addFieldAutodoc($property); - $this->addFieldAttributes($property, $this->isExcludingFieldFromJmsSerialization()); + $this->addFieldAttributes($property, $namespace, $this->isExcludingFieldFromJmsSerialization()); $getter = $classType->addMethod($this->field->getGetterName() . 'Sources') diff --git a/src/Field/NonVirtualFieldGenerator.php b/src/Field/NonVirtualFieldGenerator.php index d9bcb69..3a2c524 100644 --- a/src/Field/NonVirtualFieldGenerator.php +++ b/src/Field/NonVirtualFieldGenerator.php @@ -6,6 +6,7 @@ use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; +use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\Property; class NonVirtualFieldGenerator extends AbstractFieldGenerator @@ -62,9 +63,9 @@ protected function isExcludingFieldFromJmsSerialization(): bool return false; } - protected function addFieldAttributes(Property $property, bool $exclude = false): self + protected function addFieldAttributes(Property $property, PhpNamespace $namespace, bool $exclude = false): self { - parent::addFieldAttributes($property, $exclude); + parent::addFieldAttributes($property, $namespace, $exclude); /* * ?string $name = null, @@ -147,7 +148,7 @@ protected function getFieldDefaultValueDeclaration(): Literal|string|null }; } - public function addFieldGetter(ClassType $classType): self + public function addFieldGetter(ClassType $classType, PhpNamespace $namespace): self { $type = $this->getFieldTypeDeclaration(); $method = $classType->addMethod($this->field->getGetterName()) diff --git a/src/Field/ProxiedManyToManyFieldGenerator.php b/src/Field/ProxiedManyToManyFieldGenerator.php index 6a8fa90..6bd62f3 100644 --- a/src/Field/ProxiedManyToManyFieldGenerator.php +++ b/src/Field/ProxiedManyToManyFieldGenerator.php @@ -7,6 +7,7 @@ use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\Method; +use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\Property; use Symfony\Component\String\UnicodeString; @@ -49,7 +50,7 @@ protected function getFieldProperty(ClassType $classType): Property ->setType('\Doctrine\Common\Collections\Collection'); } - protected function addFieldAttributes(Property $property, bool $exclude = false): self + protected function addFieldAttributes(Property $property, PhpNamespace $namespace, bool $exclude = false): self { $property->addAttribute('JMS\Serializer\Annotation\Exclude'); $property->addAttribute('Symfony\Component\Serializer\Attribute\Ignore'); @@ -91,13 +92,19 @@ public function addFieldAnnotation(Property $property): self return $this; } - public function addFieldGetter(ClassType $classType): self + public function addFieldGetter(ClassType $classType, PhpNamespace $namespace): self { $classType->addMethod($this->getProxiedGetterName()) ->setReturnType('\Doctrine\Common\Collections\Collection') ->setPublic() ->setBody('return $this->' . $this->getProxiedVarName() . ';') - ->addComment('@return \Doctrine\Common\Collections\CollectiongetProxyClassname() . '>'); + ->addComment( + '@return ' . + $namespace->simplifyName('\Doctrine\Common\Collections\Collection') . + 'getProxyClassname() . + '>' + ); // Real getter $getter = $classType->addMethod($this->field->getGetterName()) diff --git a/src/Field/YamlFieldGenerator.php b/src/Field/YamlFieldGenerator.php index 3d466ca..ca84fac 100644 --- a/src/Field/YamlFieldGenerator.php +++ b/src/Field/YamlFieldGenerator.php @@ -5,7 +5,6 @@ namespace RZ\Roadiz\EntityGenerator\Field; use Nette\PhpGenerator\ClassType; -use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\Method; use Nette\PhpGenerator\Property; diff --git a/tests/Mocks/GeneratedNodesSources/NSMock.php b/tests/Mocks/GeneratedNodesSources/NSMock.php index 5d86234..daa8d62 100644 --- a/tests/Mocks/GeneratedNodesSources/NSMock.php +++ b/tests/Mocks/GeneratedNodesSources/NSMock.php @@ -9,20 +9,24 @@ namespace RZ\Roadiz\EntityGenerator\Tests\Mocks\GeneratedNodesSources; +use ApiPlatform\Doctrine\Orm\Filter; use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Serializer\Filter\PropertyFilter; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; use JMS\Serializer\Annotation as JMS; use RZ\Roadiz\CoreBundle\Entity\Node; use RZ\Roadiz\CoreBundle\Entity\Translation; +use RZ\Roadiz\CoreBundle\Entity\UserLogEntry; use Symfony\Component\Serializer\Attribute as Serializer; +use mock\Entity\NodesSources; /** * Mock node-source entity. */ -#[Gedmo\Loggable(logEntryClass: \RZ\Roadiz\CoreBundle\Entity\UserLogEntry::class)] +#[Gedmo\Loggable(logEntryClass: UserLogEntry::class)] #[ORM\Entity(repositoryClass: \mock\Entity\Repository\NodesSourcesRepository::class)] #[ORM\Table(name: 'ns_mock')] #[ORM\Index(columns: ['foo_datetime'])] @@ -30,16 +34,16 @@ #[ORM\Index(columns: ['boolIndexed'])] #[ORM\Index(columns: ['foo_decimal_excluded'])] #[ORM\Index(columns: ['layout'])] -#[ApiFilter(\ApiPlatform\Serializer\Filter\PropertyFilter::class)] -class NSMock extends \mock\Entity\NodesSources +#[ApiFilter(PropertyFilter::class)] +class NSMock extends NodesSources { /** Foo DateTime field. */ #[Serializer\SerializedName(serializedName: 'fooDatetime')] #[Serializer\Groups(['nodes_sources', 'nodes_sources_default', 'foo_datetime'])] #[ApiProperty(description: 'Foo DateTime field')] #[Serializer\MaxDepth(2)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\OrderFilter::class)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\DateFilter::class)] + #[ApiFilter(Filter\OrderFilter::class)] + #[ApiFilter(Filter\DateFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'foo_datetime', type: 'datetime', nullable: true)] #[JMS\Groups(['nodes_sources', 'nodes_sources_default', 'foo_datetime'])] @@ -70,7 +74,7 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\Groups(['nodes_sources', 'nodes_sources_default'])] #[ApiProperty(description: 'Foo indexed field: Maecenas sed diam eget risus varius blandit sit amet non magna')] #[Serializer\MaxDepth(1)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'partial')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'partial')] #[ApiFilter(\RZ\Roadiz\CoreBundle\Api\Filter\NotFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'fooIndexed', type: 'string', nullable: true, length: 250)] @@ -87,8 +91,8 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\Groups(['nodes_sources', 'nodes_sources_default'])] #[ApiProperty(description: 'Bool indexed field: Maecenas sed diam eget risus varius blandit sit amet non magna')] #[Serializer\MaxDepth(1)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\OrderFilter::class)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\BooleanFilter::class)] + #[ApiFilter(Filter\OrderFilter::class)] + #[ApiFilter(Filter\BooleanFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'boolIndexed', type: 'boolean', nullable: false, options: ['default' => false])] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] @@ -163,9 +167,9 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\Groups(['nodes_sources', 'nodes_sources_default'])] #[ApiProperty(description: 'Foo expression excluded decimal: Maecenas sed diam eget risus varius blandit sit amet non magna')] #[Serializer\MaxDepth(2)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\OrderFilter::class)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\NumericFilter::class)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\RangeFilter::class)] + #[ApiFilter(Filter\OrderFilter::class)] + #[ApiFilter(Filter\NumericFilter::class)] + #[ApiFilter(Filter\RangeFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'foo_decimal_excluded', type: 'decimal', nullable: true, precision: 18, scale: 3)] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] @@ -201,7 +205,7 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\MaxDepth(2)] #[ORM\ManyToOne(targetEntity: \App\Entity\Base\Event::class)] #[ORM\JoinColumn(name: 'single_event_reference_id', referencedColumnName: 'id', onDelete: 'SET NULL')] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] #[JMS\MaxDepth(2)] private ?\App\Entity\Base\Event $singleEventReference = null; @@ -237,7 +241,7 @@ class NSMock extends \mock\Entity\NodesSources #[ORM\JoinColumn(name: 'node_type_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\InverseJoinColumn(name: 'event_references_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\OrderBy(['sortingLastDateTime' => 'DESC'])] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] #[JMS\MaxDepth(2)] private Collection $eventReferences; @@ -285,7 +289,7 @@ class NSMock extends \mock\Entity\NodesSources #[ORM\JoinColumn(name: 'node_type_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\InverseJoinColumn(name: 'event_references_excluded_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\OrderBy(['sortingLastDateTime' => 'DESC'])] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Exclude] #[Serializer\Ignore] private Collection $eventReferencesExcluded; @@ -361,7 +365,7 @@ class NSMock extends \mock\Entity\NodesSources schema: ['type' => 'string', 'enum' => ['light', 'dark', 'transparent'], 'example' => 'light'], )] #[Serializer\MaxDepth(2)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[ApiFilter(\RZ\Roadiz\CoreBundle\Api\Filter\NotFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'layout', type: 'string', nullable: true, length: 11)] @@ -382,7 +386,7 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\MaxDepth(2)] #[ORM\ManyToOne(targetEntity: \MyCustomEntity::class)] #[ORM\JoinColumn(name: 'foo_many_to_one_id', referencedColumnName: 'id', onDelete: 'SET NULL')] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] #[JMS\MaxDepth(2)] private ?\MyCustomEntity $fooManyToOne = null; @@ -406,7 +410,7 @@ class NSMock extends \mock\Entity\NodesSources #[ORM\JoinColumn(name: 'node_type_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\InverseJoinColumn(name: 'foo_many_to_many_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\OrderBy(['name' => 'asc'])] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] #[JMS\MaxDepth(2)] private Collection $fooManyToMany; @@ -569,7 +573,7 @@ public function setSingleEventReference(?\App\Entity\Base\Event $singleEventRefe } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getEventReferences(): Collection { @@ -591,7 +595,7 @@ public function setEventReferences(Collection|array $eventReferences): static } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getEventReferencesProxiedProxy(): Collection { @@ -649,7 +653,7 @@ public function setEventReferencesProxied(Collection|array|null $eventReferences } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getEventReferencesExcluded(): Collection { @@ -897,7 +901,7 @@ public function setFooManyToOne(?\MyCustomEntity $fooManyToOne): static } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getFooManyToMany(): Collection { @@ -919,7 +923,7 @@ public function setFooManyToMany(Collection|array $fooManyToMany): static } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getFooManyToManyProxiedProxy(): Collection { diff --git a/tests/Mocks/GeneratedNodesSourcesWithRepository/NSMock.php b/tests/Mocks/GeneratedNodesSourcesWithRepository/NSMock.php index dccf9ea..82f2052 100644 --- a/tests/Mocks/GeneratedNodesSourcesWithRepository/NSMock.php +++ b/tests/Mocks/GeneratedNodesSourcesWithRepository/NSMock.php @@ -9,37 +9,41 @@ namespace RZ\Roadiz\EntityGenerator\Tests\Mocks\GeneratedNodesSourcesWithRepository; +use ApiPlatform\Doctrine\Orm\Filter; use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Serializer\Filter\PropertyFilter; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; use JMS\Serializer\Annotation as JMS; use RZ\Roadiz\CoreBundle\Entity\Node; use RZ\Roadiz\CoreBundle\Entity\Translation; +use RZ\Roadiz\CoreBundle\Entity\UserLogEntry; use Symfony\Component\Serializer\Attribute as Serializer; +use mock\Entity\NodesSources; /** * Mock node-source entity. */ -#[Gedmo\Loggable(logEntryClass: \RZ\Roadiz\CoreBundle\Entity\UserLogEntry::class)] -#[ORM\Entity(repositoryClass: \RZ\Roadiz\EntityGenerator\Tests\Mocks\GeneratedNodesSourcesWithRepository\Repository\NSMockRepository::class)] +#[Gedmo\Loggable(logEntryClass: UserLogEntry::class)] +#[ORM\Entity(repositoryClass: Repository\NSMockRepository::class)] #[ORM\Table(name: 'ns_mock')] #[ORM\Index(columns: ['foo_datetime'])] #[ORM\Index(columns: ['fooIndexed'])] #[ORM\Index(columns: ['boolIndexed'])] #[ORM\Index(columns: ['foo_decimal_excluded'])] #[ORM\Index(columns: ['layout'])] -#[ApiFilter(\ApiPlatform\Serializer\Filter\PropertyFilter::class)] -class NSMock extends \mock\Entity\NodesSources +#[ApiFilter(PropertyFilter::class)] +class NSMock extends NodesSources { /** Foo DateTime field. */ #[Serializer\SerializedName(serializedName: 'fooDatetime')] #[Serializer\Groups(['nodes_sources', 'nodes_sources_default', 'foo_datetime'])] #[ApiProperty(description: 'Foo DateTime field')] #[Serializer\MaxDepth(2)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\OrderFilter::class)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\DateFilter::class)] + #[ApiFilter(Filter\OrderFilter::class)] + #[ApiFilter(Filter\DateFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'foo_datetime', type: 'datetime', nullable: true)] #[JMS\Groups(['nodes_sources', 'nodes_sources_default', 'foo_datetime'])] @@ -70,7 +74,7 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\Groups(['nodes_sources', 'nodes_sources_default'])] #[ApiProperty(description: 'Foo indexed field: Maecenas sed diam eget risus varius blandit sit amet non magna')] #[Serializer\MaxDepth(1)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'partial')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'partial')] #[ApiFilter(\RZ\Roadiz\CoreBundle\Api\Filter\NotFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'fooIndexed', type: 'string', nullable: true, length: 250)] @@ -87,8 +91,8 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\Groups(['nodes_sources', 'nodes_sources_default'])] #[ApiProperty(description: 'Bool indexed field: Maecenas sed diam eget risus varius blandit sit amet non magna')] #[Serializer\MaxDepth(1)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\OrderFilter::class)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\BooleanFilter::class)] + #[ApiFilter(Filter\OrderFilter::class)] + #[ApiFilter(Filter\BooleanFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'boolIndexed', type: 'boolean', nullable: false, options: ['default' => false])] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] @@ -163,9 +167,9 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\Groups(['nodes_sources', 'nodes_sources_default'])] #[ApiProperty(description: 'Foo expression excluded decimal: Maecenas sed diam eget risus varius blandit sit amet non magna')] #[Serializer\MaxDepth(2)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\OrderFilter::class)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\NumericFilter::class)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\RangeFilter::class)] + #[ApiFilter(Filter\OrderFilter::class)] + #[ApiFilter(Filter\NumericFilter::class)] + #[ApiFilter(Filter\RangeFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'foo_decimal_excluded', type: 'decimal', nullable: true, precision: 18, scale: 3)] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] @@ -201,7 +205,7 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\MaxDepth(2)] #[ORM\ManyToOne(targetEntity: \App\Entity\Base\Event::class)] #[ORM\JoinColumn(name: 'single_event_reference_id', referencedColumnName: 'id', onDelete: 'SET NULL')] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] #[JMS\MaxDepth(2)] private ?\App\Entity\Base\Event $singleEventReference = null; @@ -237,7 +241,7 @@ class NSMock extends \mock\Entity\NodesSources #[ORM\JoinColumn(name: 'node_type_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\InverseJoinColumn(name: 'event_references_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\OrderBy(['sortingLastDateTime' => 'DESC'])] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] #[JMS\MaxDepth(2)] private Collection $eventReferences; @@ -285,7 +289,7 @@ class NSMock extends \mock\Entity\NodesSources #[ORM\JoinColumn(name: 'node_type_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\InverseJoinColumn(name: 'event_references_excluded_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\OrderBy(['sortingLastDateTime' => 'DESC'])] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Exclude] #[Serializer\Ignore] private Collection $eventReferencesExcluded; @@ -361,7 +365,7 @@ class NSMock extends \mock\Entity\NodesSources schema: ['type' => 'string', 'enum' => ['light', 'dark', 'transparent'], 'example' => 'light'], )] #[Serializer\MaxDepth(2)] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[ApiFilter(\RZ\Roadiz\CoreBundle\Api\Filter\NotFilter::class)] #[Gedmo\Versioned] #[ORM\Column(name: 'layout', type: 'string', nullable: true, length: 11)] @@ -382,7 +386,7 @@ class NSMock extends \mock\Entity\NodesSources #[Serializer\MaxDepth(2)] #[ORM\ManyToOne(targetEntity: \MyCustomEntity::class)] #[ORM\JoinColumn(name: 'foo_many_to_one_id', referencedColumnName: 'id', onDelete: 'SET NULL')] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] #[JMS\MaxDepth(2)] private ?\MyCustomEntity $fooManyToOne = null; @@ -406,7 +410,7 @@ class NSMock extends \mock\Entity\NodesSources #[ORM\JoinColumn(name: 'node_type_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\InverseJoinColumn(name: 'foo_many_to_many_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\OrderBy(['name' => 'asc'])] - #[ApiFilter(\ApiPlatform\Doctrine\Orm\Filter\SearchFilter::class, strategy: 'exact')] + #[ApiFilter(Filter\SearchFilter::class, strategy: 'exact')] #[JMS\Groups(['nodes_sources', 'nodes_sources_default'])] #[JMS\MaxDepth(2)] private Collection $fooManyToMany; @@ -569,7 +573,7 @@ public function setSingleEventReference(?\App\Entity\Base\Event $singleEventRefe } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getEventReferences(): Collection { @@ -591,7 +595,7 @@ public function setEventReferences(Collection|array $eventReferences): static } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getEventReferencesProxiedProxy(): Collection { @@ -649,7 +653,7 @@ public function setEventReferencesProxied(Collection|array|null $eventReferences } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getEventReferencesExcluded(): Collection { @@ -897,7 +901,7 @@ public function setFooManyToOne(?\MyCustomEntity $fooManyToOne): static } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getFooManyToMany(): Collection { @@ -919,7 +923,7 @@ public function setFooManyToMany(Collection|array $fooManyToMany): static } /** - * @return \Doctrine\Common\Collections\Collection + * @return Collection */ public function getFooManyToManyProxiedProxy(): Collection {