Skip to content

Commit

Permalink
Docs: use attributes by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Jan 1, 2025
1 parent 162fede commit 13c3e0b
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@

##

<details open>
<summary>Attributes definition</summary>

```php
use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Rules\MappedObjectValue;
use Orisai\ObjectMapper\Rules\StringValue;

final class UserInput implements MappedObject
{

#[StringValue(notEmpty=true)]
public string $firstName;

#[StringValue(notEmpty=true)]
public string $lastName;

#[MappedObjectValue(UserAddressInput::class)]
public UserAddressInput $address;

}
```

```php
use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Rules\StringValue;

final class UserAddressInput implements MappedObject
{

#[StringValue(notEmpty=true)]
public string $street;

// ...
}
```
</details>

<details>
<summary>Annotations definition</summary>

```php
use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Rules\MappedObjectValue;
Expand Down Expand Up @@ -62,6 +103,10 @@ final class UserAddressInput implements MappedObject
// ...
}
```
</details>

<details open>
<summary>Processing</summary>

```php
use Orisai\ObjectMapper\Exception\InvalidData;
Expand Down Expand Up @@ -90,3 +135,4 @@ try {

echo "User name is: {$user->firstName} {$user->lastName}";
```
</details>
49 changes: 49 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@ installation.

After you have finished [setup](#setup), define a mapped object:

<details open>
<summary>Either with attributes</summary>

```php
use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Rules\StringValue;

final class UserInput implements MappedObject
{

#[StringValue(notEmpty=true)]
public string $firstName;

#[StringValue(notEmpty=true)]
public string $lastName;

}
```
</details>

<details>
<summary>Or doctrine/annotations</summary>

```php
use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Rules\StringValue;
Expand All @@ -124,7 +147,9 @@ final class UserInput implements MappedObject
/** @StringValue(notEmpty=true) */
public string $lastName;

}
```
</details>

Map data to the object:

Expand Down Expand Up @@ -209,6 +234,29 @@ $input = $processor->process($data, WithAnnotationsAndAttributesInput::class); /

Expects bool

<details open>
<summary><code>#[Attributes()]</code></summary>

```php
use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Rules\BoolValue;

final class BoolInput implements MappedObject
{

#[BoolValue()]
public bool $field;

#[BoolValue(castBoolLike=true)]
public bool $anotherField;

}
```
</details>

<details>
<summary><code>@Annotations()</code></summary>

```php
use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Rules\BoolValue;
Expand All @@ -224,6 +272,7 @@ final class BoolInput implements MappedObject

}
```
</details>

```php
$data = [
Expand Down

0 comments on commit 13c3e0b

Please sign in to comment.