diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 13beea7..373abb5 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -10,10 +10,10 @@ permissions:
contents: read
jobs:
- codecheck:
+ phpstan:
runs-on: ubuntu-latest
steps:
- - uses: shivammathur/setup-php@2cb9b829437ee246e9b3cac53555a39208ca6d28
+ - uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- uses: actions/checkout@v3
@@ -31,13 +31,16 @@ jobs:
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: PHPStan
- run: composer phpstan
+ run: vendor/bin/phpstan analyse --memory-limit=1G
+
test:
+ needs: [phpstan]
runs-on: ubuntu-latest
steps:
- - uses: shivammathur/setup-php@2cb9b829437ee246e9b3cac53555a39208ca6d28
+ - uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
+ coverage: xdebug
- uses: actions/checkout@v3
- name: Cache Composer packages
@@ -53,4 +56,12 @@ jobs:
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: PHPUnit
- run: composer test
\ No newline at end of file
+ run: vendor/bin/phpunit --coverage-html coverage-report
+
+ - name: Upload Coverage Report
+ uses: actions/upload-artifact@v4
+ if: always()
+ with:
+ name: coverage-report
+ path: coverage-report/
+ retention-days: 30
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 38eb219..55809c8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,5 @@ vendor/
.phpunit.cache/
tests/data/Generated
composer.lock
-.DS_Store
\ No newline at end of file
+.DS_Store
+coverage-report
\ No newline at end of file
diff --git a/LICENSE b/LICENSE.md
similarity index 100%
rename from LICENSE
rename to LICENSE.md
diff --git a/README.md b/README.md
index 558417c..6e83f0e 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,26 @@
# Transfer Bundle
-### Requirements:
-* php: >= 8.3
-* symfony: >= 7.2
-* ext-simplexml: *
+[](https://github.com/philipphermes/transfer-bundle/actions/workflows/ci.yml)
+[]((https://img.shields.io/badge/php-%3E%3D%208.3-8892BF.svg))
+[]((https://img.shields.io/badge/symfony-%3E%3D%207.4-8892BF.svg))
-## Usage:
+## Table of Contents
+
+1. [Installation](#installation)
+ 1. [configuration](#configuration)
+ 2. [openApi](#openapi)
+2. [Code Quality](#code-quality)
+ 2. [phpstan](#phpstan)
+3. [Test](#test)
+ 1. [phpunit](#phpunit)
+
+## Installation
```shell
composer require philipphermes/transfer-bundle
```
-### Configuration:
+### Configuration
```php
// config/bundles.php
@@ -21,15 +30,17 @@ return [
];
```
-#### Optional Configs:
+#### Optional Configs
+
* `transfer.namespace`: `App\\Generated\\Transfers`
* `transfer.schema_dir`: `%kernel.project_dir%/transfers`
* `transfer.output_dir`: `%kernel.project_dir%/src/Generated/Transfers`
-### Define Transfers:
+### Define Transfers
+
* you can create multiple files
* if multiple files have the same transfer they will be merged
- * if you define the same property twice the first on it gets is taken
+ * if you define the same property twice the first on it gets is taken
```xml
@@ -39,7 +50,8 @@ return [
-
+
@@ -48,34 +60,113 @@ return [
```
-#### Security Bundle Integration
-If you want to use this feature make sure you have the Security Bundle installed.
-```shell
-composer require symfony/security-bundle
-```
+### OpenAPI
-Then you can define your transfer eg. like this:
+> [!CAUTION]
+> This currently does not work with Symfony 8
+
+you can add `api="true"` to transfers to add attributes and a ref automatically.
+child transfers won't get it automatically.
```xml
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
```
-it will implement the UserInterface and have all required methods like:
-* getUserIdentifier
-* eraseCredentials
-* get/set Roles
+then you can use it in api routes for example like this:
+
+```php
+userFacade->getUserById($id);
+
+ return $this->json($user);
+ }
+}
+```
+
+## Generate transfers
-### Run
```shell
symfony console transfer:generate
+```
+
+## Code Quality
+
+### Phpstan
+
+```bash
+vendor/bin/phpstan analyse --memory-limit=1G
+```
+
+## Test
+
+### Phpunit
+
+```bash
+vendor/bin/phpunit
+
+# With coverage
+XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html coverage-report
```
\ No newline at end of file
diff --git a/composer.json b/composer.json
index ba45c4a..b0a3980 100644
--- a/composer.json
+++ b/composer.json
@@ -23,28 +23,23 @@
"require": {
"php": ">=8.3",
"ext-simplexml": "*",
- "nette/php-generator": "^4.1",
- "symfony/config": "^7.2",
- "symfony/console": "^7.2",
- "symfony/dependency-injection": "^7.2",
- "symfony/filesystem": "^7.2",
- "symfony/finder": "^7.2",
- "symfony/framework-bundle": "^7.2"
+ "nette/php-generator": "^v4.2",
+ "symfony/config": "^7.4",
+ "symfony/console": "^7.4",
+ "symfony/dependency-injection": "^7.4",
+ "symfony/filesystem": "^7.4",
+ "symfony/finder": "^7.4",
+ "symfony/framework-bundle": "^7.4"
},
"require-dev": {
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^12.1",
- "symfony/security-bundle": "^7.2"
+ "zircote/swagger-php": "^5.7"
+ },
+ "suggest": {
+ "zircote/swagger-php": "^5.7"
},
"config": {
"sort-packages": true
- },
- "scripts": {
- "phpstan": [
- "vendor/bin/phpstan analyse -c phpstan.neon"
- ],
- "test": [
- "XDEBUG_MODE=coverage vendor/bin/phpunit"
- ]
}
}
diff --git a/src/PhilippHermesTransferBundle.php b/src/PhilippHermesTransferBundle.php
index 4b7ba11..392480d 100644
--- a/src/PhilippHermesTransferBundle.php
+++ b/src/PhilippHermesTransferBundle.php
@@ -22,7 +22,6 @@ class PhilippHermesTransferBundle extends AbstractBundle
*/
public function configure(DefinitionConfigurator $definition): void
{
- /** @phpstan-ignore-next-line */
$definition->rootNode()
->children()
->scalarNode('schema_dir')
@@ -39,10 +38,9 @@ public function configure(DefinitionConfigurator $definition): void
}
/**
- *
* @inheritDoc
*
- * @param array $config
+ * @param array $config
*/
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
@@ -66,4 +64,84 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
->setArgument('$outputDir', '%transfer.output_dir%')
->setArgument('$namespace', '%transfer.namespace%');
}
+
+ /**
+ * @inheritDoc
+ */
+ public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
+ {
+ try {
+ $outputDir = $builder->getParameter('transfer.output_dir');
+ } catch (\Exception) {
+ $projectDir = $builder->getParameter('kernel.project_dir');
+ if (!is_string($projectDir)) {
+ return;
+ }
+ $outputDir = $projectDir . '/src/Generated/Transfers';
+ }
+
+ try {
+ $namespace = $builder->getParameter('transfer.namespace');
+ } catch (\Exception) {
+ $namespace = 'App\\Generated\\Transfers';
+ }
+
+ if (!is_string($outputDir) || !is_string($namespace) || !is_dir($outputDir)) {
+ return;
+ }
+
+ $models = [];
+ $filePaths = glob($outputDir . '/*Transfer.php');
+ if (!$filePaths) {
+ return;
+ }
+
+ foreach ($filePaths as $filePath) {
+ $className = $this->classFromPath($filePath, $namespace, $outputDir);
+
+ $data = file_get_contents($filePath);
+ if (!$data || !str_contains($data, 'use OpenApi\Attributes as OA;')) {
+ continue;
+ }
+
+ $models[] = [
+ 'alias' => $this->aliasFromPath($filePath),
+ 'type' => $className,
+ ];
+ }
+
+ if ($models !== []) {
+ $builder->prependExtensionConfig('nelmio_api_doc', [
+ 'models' => [
+ 'names' => $models,
+ ],
+ ]);
+ }
+ }
+
+ /**
+ * @param string $filePath
+ * @param string $namespace
+ * @param string $outputDir
+ *
+ * @return string
+ */
+ protected function classFromPath(string $filePath, string $namespace, string $outputDir): string
+ {
+ $relativePath = str_replace([$outputDir, '/', '.php'], ['', '\\', ''], $filePath);
+
+ return $namespace . $relativePath;
+ }
+
+ /**
+ * @param string $filePath
+ *
+ * @return string|null
+ */
+ protected function aliasFromPath(string $filePath): ?string
+ {
+ $filename = basename($filePath, '.php');
+
+ return preg_replace('/Transfer$/', '', $filename);
+ }
}
\ No newline at end of file
diff --git a/src/Resources/schema/transfer.xsd b/src/Resources/schema/transfer.xsd
index d27fe7f..fce718b 100644
--- a/src/Resources/schema/transfer.xsd
+++ b/src/Resources/schema/transfer.xsd
@@ -20,13 +20,6 @@
-
-
-
-
-
-
-
@@ -41,13 +34,11 @@
-
-
-
+
diff --git a/src/Service/Model/Generator/Generator.php b/src/Service/Model/Generator/Generator.php
index ff66879..aebec82 100644
--- a/src/Service/Model/Generator/Generator.php
+++ b/src/Service/Model/Generator/Generator.php
@@ -10,7 +10,6 @@
use PhilippHermes\TransferBundle\Service\Model\Generator\PropertyGeneratorSteps\PropertyGeneratorStepInterface;
use PhilippHermes\TransferBundle\Service\Model\Type\PropertyTypeMapper;
use PhilippHermes\TransferBundle\Transfer\GeneratorConfigTransfer;
-use PhilippHermes\TransferBundle\Transfer\PropertyTransfer;
use PhilippHermes\TransferBundle\Transfer\TransferCollectionTransfer;
use PhilippHermes\TransferBundle\Transfer\TransferTransfer;
@@ -33,7 +32,6 @@ public function generate(
TransferCollectionTransfer $transferCollectionTransfer,
): void {
foreach ($transferCollectionTransfer->getTransfers() as $transfer) {
- $transfer = $this->addRoleProperty($transfer);
$this->generateTransfer($generatorConfigTransfer, $transfer);
}
}
@@ -53,24 +51,14 @@ protected function generateTransfer(GeneratorConfigTransfer $generatorConfig, Tr
$this->generateUses($transfer, $namespace);
$class = $namespace->addClass($transfer->getName() . 'Transfer');
- $this->generateInheritance($transfer, $class);
+ $this->generateAnnotations($transfer, $class);
foreach ($transfer->getProperties() as $property) {
foreach ($this->propertyGeneratorSteps as $propertyGeneratorStep) {
- $propertyGeneratorStep->generate($property, $class);
- }
-
- if ($property->isIdentifier()) {
- $transfer->setIdentifierProperty($property);
- }
-
- if ($property->isSensitive()) {
- $transfer->addSensitiveProperty($property);
+ $propertyGeneratorStep->generate($transfer, $property, $class);
}
}
- $this->generateUserProperties($transfer, $class);
-
if (!is_dir($generatorConfig->getOutputDirectory())) {
mkdir($generatorConfig->getOutputDirectory(), 0777, true);
}
@@ -94,81 +82,31 @@ protected function generateUses(TransferTransfer $transfer, PhpNamespace $namesp
$namespace->addUse($propertyTransfer->getSingularType());
}
}
- }
-
- /**
- * @param TransferTransfer $transfer
- * @param ClassType $class
- * @return void
- */
- protected function generateInheritance(TransferTransfer $transfer, ClassType $class): void
- {
- if ($transfer->getType() !== 'user') {
- return;
- }
-
- $class->addImplement('Symfony\Component\Security\Core\User\UserInterface');
- foreach ($transfer->getProperties() as $property) {
- if ($property->getName() === 'password') {
- $class->addImplement('Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface');
- break;
- }
+ if ($transfer->isApi()) {
+ $namespace->addUse('OpenApi\Attributes', 'OA');
}
}
/**
* @param TransferTransfer $transfer
* @param ClassType $class
+ *
* @return void
*/
- protected function generateUserProperties(
- TransferTransfer $transfer,
- ClassType $class,
- ): void {
- if ($transfer->getType() !== 'user' || !$transfer->getIdentifierProperty()?->getName()) { //TODO validate
- return;
- }
-
- $methodUserIdentifier = $class->addMethod('getUserIdentifier');
- $methodUserIdentifier->setPublic();
- $methodUserIdentifier->setReturnType('string');
- $methodUserIdentifier->setComment('@return string');
- $methodUserIdentifier->addBody('return $this->' . $transfer->getIdentifierProperty()->getName() . ';');
-
- $methodEraseCredentials = $class->addMethod('eraseCredentials');
- $methodEraseCredentials->setPublic();
- $methodEraseCredentials->setReturnType('void');
- $methodEraseCredentials->setComment('@return void');
-
- foreach ($transfer->getSensitiveProperties() as $property) {
- $methodEraseCredentials->addBody('$this->' . $property->getName() . ' = null;');
- }
- }
-
- /**
- * @param TransferTransfer $transfer
- * @return TransferTransfer
- */
- protected function addRoleProperty(TransferTransfer $transfer): TransferTransfer
+ protected function generateAnnotations(TransferTransfer $transfer, ClassType $class): void
{
- if ($transfer->getType() !== 'user') {
- return $transfer;
- }
-
- foreach ($transfer->getProperties() as $propertyTransfer) {
- if ($propertyTransfer->getName() === 'roles') {
- return $transfer;
- }
+ if (!$transfer->isApi()) {
+ return;
}
- return $transfer->addProperty((new PropertyTransfer())
- ->setName('roles')
- ->setSingular('role')
- ->setType('array')
- ->setSingularType('string')
- ->setAnnotationType('array')
- ->setSingularAnnotationType('string'),
+ $class->addAttribute(
+ 'OpenApi\Attributes\Schema',
+ [
+ 'schema' => $transfer->getName(),
+ 'title' => $transfer->getName(),
+ 'type' => 'object',
+ ]
);
}
}
\ No newline at end of file
diff --git a/src/Service/Model/Generator/PropertyGeneratorSteps/AdderPropertyGeneratorStep.php b/src/Service/Model/Generator/PropertyGeneratorSteps/AdderPropertyGeneratorStep.php
index 1338033..3868d34 100644
--- a/src/Service/Model/Generator/PropertyGeneratorSteps/AdderPropertyGeneratorStep.php
+++ b/src/Service/Model/Generator/PropertyGeneratorSteps/AdderPropertyGeneratorStep.php
@@ -6,13 +6,14 @@
use Nette\PhpGenerator\ClassType;
use PhilippHermes\TransferBundle\Transfer\PropertyTransfer;
+use PhilippHermes\TransferBundle\Transfer\TransferTransfer;
class AdderPropertyGeneratorStep implements PropertyGeneratorStepInterface
{
/**
* @inheritDoc
*/
- public function generate(PropertyTransfer $propertyTransfer, ClassType $class): void
+ public function generate(TransferTransfer $transferTransfer, PropertyTransfer $propertyTransfer, ClassType $class): void
{
if (!$propertyTransfer->getSingularType()) {
return;
diff --git a/src/Service/Model/Generator/PropertyGeneratorSteps/GetterPropertyGeneratorStep.php b/src/Service/Model/Generator/PropertyGeneratorSteps/GetterPropertyGeneratorStep.php
index 82ec424..3f953a4 100644
--- a/src/Service/Model/Generator/PropertyGeneratorSteps/GetterPropertyGeneratorStep.php
+++ b/src/Service/Model/Generator/PropertyGeneratorSteps/GetterPropertyGeneratorStep.php
@@ -6,13 +6,14 @@
use Nette\PhpGenerator\ClassType;
use PhilippHermes\TransferBundle\Transfer\PropertyTransfer;
+use PhilippHermes\TransferBundle\Transfer\TransferTransfer;
class GetterPropertyGeneratorStep implements PropertyGeneratorStepInterface
{
/**
* @inheritDoc
*/
- public function generate(PropertyTransfer $propertyTransfer, ClassType $class): void
+ public function generate(TransferTransfer $transferTransfer, PropertyTransfer $propertyTransfer, ClassType $class): void
{
$method = $class->addMethod('get' . ucfirst($propertyTransfer->getName()));
$method->setPublic();
diff --git a/src/Service/Model/Generator/PropertyGeneratorSteps/PropertyGeneratorStepInterface.php b/src/Service/Model/Generator/PropertyGeneratorSteps/PropertyGeneratorStepInterface.php
index ad76b39..e65aa4e 100644
--- a/src/Service/Model/Generator/PropertyGeneratorSteps/PropertyGeneratorStepInterface.php
+++ b/src/Service/Model/Generator/PropertyGeneratorSteps/PropertyGeneratorStepInterface.php
@@ -6,13 +6,16 @@
use Nette\PhpGenerator\ClassType;
use PhilippHermes\TransferBundle\Transfer\PropertyTransfer;
+use PhilippHermes\TransferBundle\Transfer\TransferTransfer;
interface PropertyGeneratorStepInterface
{
/**
+ * @param TransferTransfer $transferTransfer
* @param PropertyTransfer $propertyTransfer
* @param ClassType $class
+ *
* @return void
*/
- public function generate(PropertyTransfer $propertyTransfer, ClassType $class): void;
+ public function generate(TransferTransfer $transferTransfer, PropertyTransfer $propertyTransfer, ClassType $class): void;
}
\ No newline at end of file
diff --git a/src/Service/Model/Generator/PropertyGeneratorSteps/PropertyPropertyGeneratorStep.php b/src/Service/Model/Generator/PropertyGeneratorSteps/PropertyPropertyGeneratorStep.php
index 29a1c60..ba52ab8 100644
--- a/src/Service/Model/Generator/PropertyGeneratorSteps/PropertyPropertyGeneratorStep.php
+++ b/src/Service/Model/Generator/PropertyGeneratorSteps/PropertyPropertyGeneratorStep.php
@@ -5,20 +5,29 @@
namespace PhilippHermes\TransferBundle\Service\Model\Generator\PropertyGeneratorSteps;
use Nette\PhpGenerator\ClassType;
+use Nette\PhpGenerator\Literal;
use PhilippHermes\TransferBundle\Transfer\PropertyTransfer;
+use PhilippHermes\TransferBundle\Transfer\TransferTransfer;
class PropertyPropertyGeneratorStep implements PropertyGeneratorStepInterface
{
/**
* @inheritDoc
*/
- public function generate(PropertyTransfer $propertyTransfer, ClassType $class): void
+ public function generate(TransferTransfer $transferTransfer, PropertyTransfer $propertyTransfer, ClassType $class): void
{
$property = $class->addProperty($propertyTransfer->getName());
$property->setPrivate();
$property->setType(($propertyTransfer->isNullable() ? '?' : '') . $propertyTransfer->getType());
$property->addComment('@var ' . $propertyTransfer->getAnnotationType() . ($propertyTransfer->isNullable() ? '|null' : ''));
+ if ($transferTransfer->isApi()) {
+ $property->addAttribute(
+ 'OpenApi\Attributes\Property',
+ $this->resolveOAAttributeArguments($propertyTransfer),
+ );
+ }
+
if ($propertyTransfer->isNullable()) {
$property->setValue(null);
}
@@ -27,4 +36,87 @@ public function generate(PropertyTransfer $propertyTransfer, ClassType $class):
$property->setValue([]);
}
}
+
+ /**
+ * @param PropertyTransfer $propertyTransfer
+ *
+ * @return array
+ */
+ protected function resolveOAAttributeArguments(PropertyTransfer $propertyTransfer): array
+ {
+ $type = $this->resolveOAType($propertyTransfer->getType());
+ $singularType = $propertyTransfer->getSingularType() ? $this->resolveOAType($propertyTransfer->getSingularType()) : null;
+
+ $arguments = [];
+
+ if (str_contains($propertyTransfer->getType(), 'Transfer')) {
+ $arguments['ref'] = sprintf(
+ '#/components/schemas/%s',
+ $this->resolveTransferType($propertyTransfer->getType()),
+ );
+ } else {
+ $arguments['type'] = $type;
+ }
+
+ if ($singularType) {
+ if ($propertyTransfer->getSingularType() && str_contains($propertyTransfer->getSingularType(), 'Transfer')) {
+ $arguments['items'] = Literal::new(
+ 'OA\Items',
+ [
+ 'ref' => sprintf(
+ '#/components/schemas/%s',
+ $this->resolveTransferType($propertyTransfer->getSingularType()),
+ ),
+ ]
+ );
+ } else {
+ $arguments['items'] = Literal::new(
+ 'OA\Items',
+ [
+ 'type' => $singularType,
+ ],
+ );
+ }
+ }
+
+ if ($propertyTransfer->getType() === 'DateTime' || $propertyTransfer->getType() === 'DateTimeImmutable') {
+ $arguments['format'] = 'date-time';
+ }
+
+ if ($propertyTransfer->isNullable()) {
+ $arguments['nullable'] = true;
+ }
+
+ return $arguments;
+ }
+
+ /**
+ * @param string $type
+ *
+ * @return string
+ */
+ protected function resolveOAType(string $type): string
+ {
+ return match ($type) {
+ 'string', 'DateTime', 'DateTimeImmutable' => 'string',
+ 'int' => 'integer',
+ 'float' => 'number',
+ 'bool' => 'boolean',
+ 'array', 'ArrayObject' => 'array',
+ default => 'object',
+ };
+ }
+
+ /**
+ * @param string $type
+ *
+ * @return string
+ */
+ function resolveTransferType(string $type): string
+ {
+ $parts = explode('\\', $type);
+ $shortType = end($parts);
+
+ return str_replace('Transfer', '', $shortType);
+ }
}
\ No newline at end of file
diff --git a/src/Service/Model/Generator/PropertyGeneratorSteps/SetterPropertyGeneratorStep.php b/src/Service/Model/Generator/PropertyGeneratorSteps/SetterPropertyGeneratorStep.php
index 13d8efe..6cd348e 100644
--- a/src/Service/Model/Generator/PropertyGeneratorSteps/SetterPropertyGeneratorStep.php
+++ b/src/Service/Model/Generator/PropertyGeneratorSteps/SetterPropertyGeneratorStep.php
@@ -6,13 +6,14 @@
use Nette\PhpGenerator\ClassType;
use PhilippHermes\TransferBundle\Transfer\PropertyTransfer;
+use PhilippHermes\TransferBundle\Transfer\TransferTransfer;
class SetterPropertyGeneratorStep implements PropertyGeneratorStepInterface
{
/**
* @inheritDoc
*/
- public function generate(PropertyTransfer $propertyTransfer, ClassType $class): void
+ public function generate(TransferTransfer $transferTransfer, PropertyTransfer $propertyTransfer, ClassType $class): void
{
$method = $class->addMethod('set' . ucfirst($propertyTransfer->getName()));
diff --git a/src/Service/Model/Parser/TransferParser.php b/src/Service/Model/Parser/TransferParser.php
index e81fa76..56835d1 100644
--- a/src/Service/Model/Parser/TransferParser.php
+++ b/src/Service/Model/Parser/TransferParser.php
@@ -60,7 +60,7 @@ public function parse(GeneratorConfigTransfer $generatorConfigTransfer): Transfe
if (!$transfer) {
$transfer = new TransferTransfer();
$transfer->setName((string)$transferElement['name']);
- $transfer->setType((string)($transferElement['type'] ?? 'default'));
+ $transfer->setIsApi(isset($transferElement['api']) && ((string)$transferElement['api'] === 'true'));
}
foreach ($transferElement->property as $propertyElement) {
@@ -95,9 +95,7 @@ public function parse(GeneratorConfigTransfer $generatorConfigTransfer): Transfe
->setName((string)$propertyElement['name'])
->setDescription(isset($propertyElement['description']) ? (string)$propertyElement['description'] : null)
->setSingular(isset($propertyElement['singular']) ? (string)$propertyElement['singular'] : null)
- ->setIsNullable(isset($propertyElement['isNullable']) && ((string)$propertyElement['isNullable'] === 'true'))
- ->setIsIdentifier(isset($propertyElement['isIdentifier']) && ((string)$propertyElement['isIdentifier'] === 'true'))
- ->setIsSensitive(isset($propertyElement['isSensitive']) && ((string)$propertyElement['isSensitive'] === 'true'));
+ ->setIsNullable(isset($propertyElement['isNullable']) && ((string)$propertyElement['isNullable'] === 'true'));
$property = $this->propertyTypeMapper->addTypes($generatorConfigTransfer, $property, (string)$propertyElement['type']);
diff --git a/src/Transfer/PropertyTransfer.php b/src/Transfer/PropertyTransfer.php
index 0624df7..00c92c6 100644
--- a/src/Transfer/PropertyTransfer.php
+++ b/src/Transfer/PropertyTransfer.php
@@ -8,14 +8,13 @@ class PropertyTransfer
{
protected string $name;
protected ?string $singular = null;
+
protected string $type;
protected ?string $singularType = null;
protected string $annotationType;
protected ?string $singularAnnotationType = null;
protected ?string $description = null;
protected bool $isNullable = false;
- protected bool $isIdentifier = false;
- protected bool $isSensitive = false;
/**
* @return string
@@ -160,40 +159,4 @@ public function setIsNullable(bool $isNullable): PropertyTransfer
$this->isNullable = $isNullable;
return $this;
}
-
- /**
- * @return bool
- */
- public function isIdentifier(): bool
- {
- return $this->isIdentifier;
- }
-
- /**
- * @param bool $isIdentifier
- * @return PropertyTransfer
- */
- public function setIsIdentifier(bool $isIdentifier): PropertyTransfer
- {
- $this->isIdentifier = $isIdentifier;
- return $this;
- }
-
- /**
- * @return bool
- */
- public function isSensitive(): bool
- {
- return $this->isSensitive;
- }
-
- /**
- * @param bool $isSensitive
- * @return PropertyTransfer
- */
- public function setIsSensitive(bool $isSensitive): PropertyTransfer
- {
- $this->isSensitive = $isSensitive;
- return $this;
- }
}
\ No newline at end of file
diff --git a/src/Transfer/TransferTransfer.php b/src/Transfer/TransferTransfer.php
index 8ffb2e0..524785e 100644
--- a/src/Transfer/TransferTransfer.php
+++ b/src/Transfer/TransferTransfer.php
@@ -10,8 +10,6 @@ class TransferTransfer
{
protected string $name;
- protected string $type;
-
/**
* @var ArrayObject
*/
@@ -24,6 +22,8 @@ class TransferTransfer
protected ?PropertyTransfer $identifierProperty = null;
+ protected bool $isApi = false;
+
/**
* @return string
*/
@@ -42,24 +42,6 @@ public function setName(string $name): TransferTransfer
return $this;
}
- /**
- * @return string
- */
- public function getType(): string
- {
- return $this->type;
- }
-
- /**
- * @param string $type
- * @return TransferTransfer
- */
- public function setType(string $type): TransferTransfer
- {
- $this->type = $type;
- return $this;
- }
-
/**
* @return ArrayObject
*/
@@ -137,4 +119,22 @@ public function setIdentifierProperty(?PropertyTransfer $identifierProperty): Tr
$this->identifierProperty = $identifierProperty;
return $this;
}
+
+ /**
+ * @return bool
+ */
+ public function isApi(): bool
+ {
+ return $this->isApi;
+ }
+
+ /**
+ * @param bool $isApi
+ * @return TransferTransfer
+ */
+ public function setIsApi(bool $isApi): TransferTransfer
+ {
+ $this->isApi = $isApi;
+ return $this;
+ }
}
\ No newline at end of file
diff --git a/tests/Data/Address/Transfers/address.xml b/tests/Data/Address/Transfers/address.xml
index 2c624d7..887c2a6 100644
--- a/tests/Data/Address/Transfers/address.xml
+++ b/tests/Data/Address/Transfers/address.xml
@@ -2,7 +2,12 @@
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/Data/Foo/Transfers/foo.xml b/tests/Data/Foo/Transfers/foo.xml
index 0f89eec..300b658 100644
--- a/tests/Data/Foo/Transfers/foo.xml
+++ b/tests/Data/Foo/Transfers/foo.xml
@@ -2,8 +2,13 @@
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/Data/User/Transfers/user.xml b/tests/Data/User/Transfers/user.xml
index 0fc95c0..e3ca05f 100644
--- a/tests/Data/User/Transfers/user.xml
+++ b/tests/Data/User/Transfers/user.xml
@@ -2,20 +2,14 @@
-
-
+
+
-
-
+
-
-
-
-
-
\ No newline at end of file
diff --git a/tests/Service/TransferServiceTest.php b/tests/Service/TransferServiceTest.php
index 2cb5aa4..f579a60 100644
--- a/tests/Service/TransferServiceTest.php
+++ b/tests/Service/TransferServiceTest.php
@@ -4,13 +4,6 @@
namespace PhilippHermes\TransferBundle\Tests\Service;
-use PhilippHermes\TransferBundle\Service\Model\Generate\ClassGenerator;
-use PhilippHermes\TransferBundle\Service\Model\Generate\GetterGenerator;
-use PhilippHermes\TransferBundle\Service\Model\Generate\PropertyGenerator;
-use PhilippHermes\TransferBundle\Service\Model\Generate\SetterGenerator;
-use PhilippHermes\TransferBundle\Service\Model\Generate\UserGenerator;
-use PhilippHermes\TransferBundle\Service\Model\Generator\Helper\GeneratorHelper;
-use PhilippHermes\TransferBundle\Service\Model\TransferGenerator;
use PhilippHermes\TransferBundle\Service\TransferService;
use PhilippHermes\TransferBundle\Service\TransferServiceFactory;
use PhilippHermes\TransferBundle\Service\TransferServiceInterface;
@@ -43,6 +36,7 @@ protected function tearDown(): void
unlink(__DIR__ . '/../Data/Generated/AddressTransfer.php');
unlink(__DIR__ . '/../Data/Generated/UserTransfer.php');
unlink(__DIR__ . '/../Data/Generated/CountryTransfer.php');
+ unlink(__DIR__ . '/../Data/Generated/FooTransfer.php');
rmdir(__DIR__ . '/../Data/Generated');
}
@@ -91,28 +85,15 @@ public function testGenerate(): void
$user->setEmail('test@example.com');
self::assertSame('test@example.com', $user->getEmail());
- self::assertSame('test@example.com', $user->getUserIdentifier());
$user->setPassword('password');
self::assertSame('password', $user->getPassword());
- self::assertNull($user->getPlainPassword());
- $user->setPlainPassword('password');
- self::assertSame('password', $user->getPlainPassword());
- $user->eraseCredentials();
- self::assertNull($user->getPlainPassword());
-
$user->setAddresses(new \ArrayObject([$address]));
self::assertSame('test', $user->getAddresses()->offsetGet(0)->getStreet());
$user->addAddress($address);
self::assertCount(2, $user->getAddresses());
- $user->setRoles(['ROLE_USER']);
- self::assertSame(['ROLE_USER'], $user->getRoles());
-
- $user->addRole('ROLE_ADMIN');
- self::assertSame(['ROLE_USER', 'ROLE_ADMIN'], $user->getRoles());
-
$foo->setBar([
'foo' => 'bar',
]);