-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* v1.6.0 Release * v1.6.0 [bugfix] ClassGeneratorFacadeDefault - logger as optional parameter * v1.6.0 [compatibility] php version 8.0 < 8.2 tested * v1.6.0 [examples] Add usage examples * v1.6.0 [doc] Update README.md
- Loading branch information
Showing
46 changed files
with
980 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,29 +19,62 @@ composer require micro/dto | |
|
||
``` xml | ||
<?xml version="1.0"?> | ||
<dto xmlns="micro:dto-01" | ||
<dto xmlns="micro:dto-1.6" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="micro:dto-01 https://raw.githubusercontent.com/Micro-PHP/dto/master/src/Resource/schema/dto-01.xsd"> | ||
xsi:schemaLocation="micro:dto-1.6 https://raw.githubusercontent.com/Micro-PHP/dto/master/src/Resource/schema/dto-1.6.xsd"> | ||
<class name="User\User"> | ||
<property name="email" type="string"/> | ||
<property name="age" type="int"/> | ||
<property name="email" type="string"> | ||
<validation> | ||
<not_blank grou/> | ||
<length min="6" max="50"/> | ||
<regex pattern="/^(.[aA-zA]+)$/"/> | ||
</validation> | ||
</property> | ||
<property name="age" type="int"> | ||
<validation> | ||
<not_blank groups="put"/> | ||
<greater_than value="18" /> | ||
<less_than value="100" groups="put, patch" /> | ||
</validation> | ||
</property> | ||
<property name="updatedAt" type="datetime" /> | ||
<property name="parent" type="User\User" /> | ||
</class> | ||
</dto> | ||
``` | ||
* And run generator | ||
```php | ||
use Micro\Library\DTO\ClassGeneratorFacadeDefault; | ||
|
||
$classGenerator = new ClassGeneratorFacadeDefault( | ||
$classGenerator = new \Micro\Library\DTO\ClassGeneratorFacadeDefault( | ||
['./example.xml'], // List of class declaration files | ||
'./out', // Path to the folder where to generate | ||
'Transfer' // Suffix for the all DTO classes (optional) | ||
); | ||
|
||
$classGenerator->generate(); | ||
|
||
// Usage example | ||
$user = new \User\User(); | ||
$user | ||
->setAge(19) | ||
->setEmail('[email protected]'); | ||
// OR | ||
// | ||
$user['age'] = 19; | ||
$user['email'] = '[email protected]'; | ||
|
||
// Validation example | ||
$validator = new \Micro\Library\DTO\ValidatorFacadeDefault(); | ||
$validator->validate($user); // Validation groups by default ["Default"] | ||
$validator->validate($user, ['patch', 'put']); // Set validation groups ["patch", "put"] | ||
|
||
// Serialize example | ||
$serializer = new \Micro\Library\DTO\SerializerFacadeDefault(); | ||
$serializer->toArray($user); // Simple array | ||
$serializer->toJson($user); // Simple Json | ||
|
||
// Deserialize example | ||
$serialized = $serializer->toJsonTransfer($user); | ||
$deserialized = $serializer->fromJsonTransfer($serialized); | ||
|
||
``` | ||
|
||
### [See full example](./example/) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.