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
> Alas, I do not speak English, and the documentation was compiled through google translator :(
10
11
> I will be glad if you can help me describe the documentation more correctly :)
11
12
12
-
This package will help you transform any dataset into a structured object. This is very convenient when values obtained from a query, database, or any other place can be easily cast to the object you need. But what exactly is this convenient?
13
+
This package will help you transform any dataset into a structured object. This is very convenient when values obtained
14
+
from a query, database, or any other place can be easily cast to the object you need. But what exactly is this
15
+
convenient?
13
16
14
-
When writing code, it is very important to separate logic, adhere to the principle of single responsibility, reduce dependence on other services, and much more.
17
+
When writing code, it is very important to separate logic, adhere to the principle of single responsibility, reduce
18
+
dependence on other services, and much more.
15
19
16
-
When creating a new service to create a user, you only need the necessary data set - name, email and phone. Why do you need to check around separately arrays, separately objects, check for the presence of keys through isset. It is much more convenient to make a DTO model with which the service will already work.
20
+
When creating a new service to create a user, you only need the necessary data set - name, email and phone. Why do you
21
+
need to check around separately arrays, separately objects, check for the presence of keys through isset. It is much
22
+
more convenient to make a DTO model with which the service will already work.
17
23
18
-
This approach guarantees that the service will work with the data it needs, full typing, there is no need to check for the presence of keys if it is an array.
24
+
This approach guarantees that the service will work with the data it needs, full typing, there is no need to check for
If the property is not of a scalar type, but a class of another DTO is allowed, it will also be automatically converted.
64
78
65
-
If you have an array of objects of a certain class, then you must specify the ConvertArray attribute to it, passing it to which class you need to cast the elements.
79
+
### :scroll:**Collection**
80
+
81
+
If you have an array of objects of a certain class, then you must specify the ConvertArray attribute to it, passing it
82
+
to which class you need to cast the elements.
83
+
84
+
It is also possible to specify the class in PHP DOC, but then you need to write the full path to this
85
+
class `array <\ DTO \ ProductDTO>`. This is done in order to know exactly which instance you need to create. Since
86
+
Reflection does not provide out-of-the-box functions for getting the `use *` file. Besides `use *`, you can specify an
87
+
alias, and it will be more difficult to trace it. Example:
66
88
67
-
It is also possible to specify the class in PHP DOC, but then you need to write the full path to this class `array <\ DTO \ ProductDTO>`. This is done in order to know exactly which instance you need to create. Since Reflection does not provide out-of-the-box functions for getting the `use *` file. Besides `use *`, you can specify an alias, and it will be more difficult to trace it.
68
-
Example:
69
89
```php
70
90
71
91
class ProductDTO
@@ -122,9 +142,93 @@ object(PurchaseDTO)[345]
122
142
public float 'balance' => float 10012.23
123
143
```
124
144
145
+
### :scroll:**Anonymous array**
146
+
147
+
In case you need to convert an array of data into an array of class objects, you can implement this through an anonymous
148
+
array. To do this, you just need to wrap the class in **[]**
A constant problem with the style of writing, for example, in the database it is snake_case, and in the camelCase code. And they constantly need to be transformed somehow. The package takes care of this, you just need to specify the WritingStyle attribute on the property:
229
+
A constant problem with the style of writing, for example, in the database it is snake_case, and in the camelCase code.
230
+
And they constantly need to be transformed somehow. The package takes care of this, you just need to specify the
231
+
WritingStyle attribute on the property:
128
232
129
233
```php
130
234
class WritingStyleSnakeCaseDTO
@@ -144,6 +248,7 @@ class WritingStyleSnakeCaseDTO
0 commit comments