You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# dto-converter [](https://packagist.org/packages/riverwaysoft/php-converter)[](https://github.com/riverwaysoft/dto-converter/actions/workflows/php.yml)[](https://github.com/riverwaysoft/dto-converter/actions/workflows/static_analysis.yml)[](https://packagist.org/packages/riverwaysoft/php-converter)
1
+
# php-converter [](https://packagist.org/packages/riverwaysoft/php-converter)[](https://github.com/riverwaysoft/php-converter/actions/workflows/php.yml)[](https://github.com/riverwaysoft/php-converter/actions/workflows/static_analysis.yml)[](https://packagist.org/packages/riverwaysoft/php-converter)
2
2
3
3
<imgwidth="818"alt="Screen Shot 2022-10-07 at 09 04 35"src="https://user-images.githubusercontent.com/22447849/194478818-7276da5c-bf5e-4ad2-8efd-6463c53d01d3.png">
You'll get file `generated.ts` with the following contents:
@@ -60,16 +60,16 @@ type UserOutput = {
60
60
- Flexible class filters with an option to use your own filters
61
61
62
62
## Customize
63
-
If you'd like to customize `dto-converter-ts` you need to copy the generator script to your project folder:
63
+
If you'd like to customize `php-converter-ts` you need to copy the generator script to your project folder:
64
64
65
65
```
66
-
cpvendor/bin/dto-converter-tsbin/dto-converter-ts
66
+
cpvendor/bin/php-converter-tsbin/php-converter-ts
67
67
```
68
68
69
-
Now you can start customizing the dto-converter by editing the executable file.
69
+
Now you can start customizing the php-converter by editing the executable file.
70
70
71
71
### How to customize generated output?
72
-
By default `dto-converter` writes all the types into one file. You can configure it to put each type / class in a separate file with all the required imports. Here is an example how to achieve it:
72
+
By default `php-converter` writes all the types into one file. You can configure it to put each type / class in a separate file with all the required imports. Here is an example how to achieve it:
You can even go further and use `NegationFilter` to exclude specific files as shown in [unit tests](https://github.com/riverwaysoft/dto-converter/blob/a8d5df2c03303c02bc9148bd1d7822d7fe48c5d8/tests/EndToEndTest.php#L297).
130
+
You can even go further and use `NegationFilter` to exclude specific files as shown in [unit tests](https://github.com/riverwaysoft/php-converter/blob/a8d5df2c03303c02bc9148bd1d7822d7fe48c5d8/tests/EndToEndTest.php#L297).
131
131
132
132
### How to write custom type resolvers?
133
-
`dto-converter` takes care of converting basic PHP types like number, string and so on. But what if you have a type that isn't a DTO? For example `\DateTimeImmutable`. You can write a class that implements [UnknownTypeResolverInterface](https://github.com/riverwaysoft/dto-converter/blob/2d434562c1bc73bcb6819257b31dd75c818f4ab1/src/Language/UnknownTypeResolverInterface.php). There is also a shortcut to achieve it - use [InlineTypeResolver](https://github.com/riverwaysoft/dto-converter/blob/2d434562c1bc73bcb6819257b31dd75c818f4ab1/src/Language/TypeScript/InlineTypeResolver.php):
133
+
`php-converter` takes care of converting basic PHP types like number, string and so on. But what if you have a type that isn't a DTO? For example `\DateTimeImmutable`. You can write a class that implements [UnknownTypeResolverInterface](https://github.com/riverwaysoft/php-converter/blob/2d434562c1bc73bcb6819257b31dd75c818f4ab1/src/Language/UnknownTypeResolverInterface.php). There is also a shortcut to achieve it - use [InlineTypeResolver](https://github.com/riverwaysoft/php-converter/blob/2d434562c1bc73bcb6819257b31dd75c818f4ab1/src/Language/TypeScript/InlineTypeResolver.php):
Feel free to create your own processor based on [PrependAutogeneratedNoticeFileProcessor](https://github.com/riverwaysoft/dto-converter/blob/26ee25f07ac97a942e1327165424fc65777b80b0/src/OutputWriter/OutputProcessor/PrependAutogeneratedNoticeFileProcessor.php) source.
194
+
Feel free to create your own processor based on [PrependAutogeneratedNoticeFileProcessor](https://github.com/riverwaysoft/php-converter/blob/26ee25f07ac97a942e1327165424fc65777b80b0/src/OutputWriter/OutputProcessor/PrependAutogeneratedNoticeFileProcessor.php) source.
195
195
196
196
Here is an example how [Prettier](https://prettier.io/) formatter could look like:
197
197
@@ -253,7 +253,7 @@ $application->add(
253
253
To write a custom converter you can implement [LanguageGeneratorInterface](./src/Language/LanguageGeneratorInterface.php). Here is an example how to do it for Go language: [GoGeneratorSimple](./tests/GoGeneratorSimple.php). Check how to use it [here](./tests/GoGeneratorSimpleTest.php). It covers only basic scenarios to get you an idea, so feel free to modify it to your needs.
254
254
255
255
## Error list
256
-
Here is a list of errors `dto-converter` can throw and description what to do if you encounter these errors:
256
+
Here is a list of errors `php-converter` can throw and description what to do if you encounter these errors:
257
257
258
258
### 1. Property z of class X has no type. Please add PHP type
259
259
It means that you've forgotten to add type for property `a` of class Y. Example:
@@ -265,11 +265,11 @@ class X {
265
265
}
266
266
```
267
267
268
-
At the moment there is no strict / loose mode in `dto-converter`. It is always strict. If you don't know the PHP type just use [mixed](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.mixed) type to explicitly convert it to `any`/`Object`. It could silently convert such types to TypeScript `any` or Dart `Object` if we needed it. But we prefer an explicit approach. Feel free to raise an issue if having loose mode makes sense for you.
268
+
At the moment there is no strict / loose mode in `php-converter`. It is always strict. If you don't know the PHP type just use [mixed](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.mixed) type to explicitly convert it to `any`/`Object`. It could silently convert such types to TypeScript `any` or Dart `Object` if we needed it. But we prefer an explicit approach. Feel free to raise an issue if having loose mode makes sense for you.
269
269
270
270
271
271
### 2. PHP Type X is not supported
272
-
It means `dto-converter` doesn't know how to convert the type X into TypeScript or Dart. If you are using `#[Dto]` attribute you probably forgot to add it to class `X`. Example:
272
+
It means `php-converter` doesn't know how to convert the type X into TypeScript or Dart. If you are using `#[Dto]` attribute you probably forgot to add it to class `X`. Example:
273
273
274
274
```php
275
275
#[Dto]
@@ -289,8 +289,8 @@ composer test
289
289
```
290
290
291
291
## How it is different from alternatives?
292
-
- Unlike [spatie/typescript-transformer](https://github.com/spatie/typescript-transformer)`dto-converter` supports not only TypeScript but also Dart. Support for other languages can be easily added by implementing LanguageInterface. `dto-converter` can also output generated types / classes into different files.
293
-
- Unlike [grpc](https://github.com/grpc/grpc/tree/v1.40.0/examples/php)`dto-converter` doesn't require to modify your app or install some extensions.
292
+
- Unlike [spatie/typescript-transformer](https://github.com/spatie/typescript-transformer)`php-converter` supports not only TypeScript but also Dart. Support for other languages can be easily added by implementing LanguageInterface. `php-converter` can also output generated types / classes into different files.
293
+
- Unlike [grpc](https://github.com/grpc/grpc/tree/v1.40.0/examples/php)`php-converter` doesn't require to modify your app or install some extensions.
0 commit comments