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
+58-28Lines changed: 58 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,36 @@ type User = {
55
55
- Generate a single output file or multiple files (entity per class)
56
56
- Custom class filters
57
57
58
+
## Error list
59
+
Here is a list of errors `dto-converter` can throw and description what to do if you encounter these errors:
60
+
61
+
### 1. Property z of class X has no type. Please add PHP type
62
+
It means that you've forgotten to add type for property `a` of class Y. Example:
63
+
64
+
```php
65
+
#[Dto]
66
+
classX {
67
+
public $z;
68
+
}
69
+
```
70
+
71
+
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.
72
+
73
+
74
+
### 2. PHP Type X is not supported
75
+
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:
76
+
77
+
```php
78
+
#[Dto]
79
+
class A {
80
+
public X $x;
81
+
}
82
+
83
+
class X {
84
+
public int $foo;
85
+
}
86
+
```
87
+
58
88
## Customize
59
89
If you'd like to customize dto-convert you need to copy the generator script to your project folder:
60
90
@@ -125,35 +155,35 @@ $application->add(
125
155
126
156
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).
127
157
158
+
### How to write custom type resolvers?
159
+
`dto-converter` takes care of converting basic PHP types like number, string and so on. But what to do if you have to convert 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). `dto-convert` already includes such class in core functionality. There is also a shortcut to achieve it - use [InlineTypeResolver](https://github.com/riverwaysoft/dto-converter/blob/2d434562c1bc73bcb6819257b31dd75c818f4ab1/src/Language/TypeScript/InlineTypeResolver.php):
128
160
129
-
## Error list
130
-
Here is a list of errors `dto-converter` can throw and description what to do if you encounter these errors:
131
-
132
-
### 1. Property z of class X has no type. Please add PHP type
133
-
It means that you've forgotten to add type for property `a` of class Y. Example:
134
-
135
-
```php
136
-
#[Dto]
137
-
class X {
138
-
public $z;
139
-
}
140
-
```
141
-
142
-
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.
143
-
144
-
145
-
### 2. PHP Type X is not supported
146
-
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:
0 commit comments