Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b53d4b9

Browse files
committed
Update docs
1 parent dd73bb0 commit b53d4b9

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

‎docs/readme.md‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,50 @@ Value Objects this library are divided into several logical groups:
1515
- [Content](usage/content.md)
1616
- [Enum](usage/enum.md)
1717

18-
But, this separation is only a structuring of the Value Objects in library. You can use these objects as you discretion.
18+
This separation is only a structuring of the Value Objects in library. You can use these objects as you discretion.
19+
20+
### Creating own Value Objects
21+
This library has only popular value objects. But you can always create your own objects. Abstract classes are available in this library (`StringLiteral`,` Integer`, `Enum`), with which you can implement your own value objects, for example:
22+
23+
For string type
24+
```php
25+
use Myks92\ValueObjects\String\StringLiteral;
26+
27+
final class MyTitle extends StringLiteral
28+
{
29+
}
30+
$myTitle = new MyTitle('Title');
31+
$myTitle->getValue(); //Title
32+
```
33+
34+
For integer type
35+
```php
36+
use Myks92\ValueObjects\Number\Integer;
37+
38+
final class MyAge extends Integer
39+
{
40+
}
41+
42+
$myAge = new MyAge(12);
43+
$myAge->getValue(); //12
44+
```
45+
46+
For option type
47+
```php
48+
use Myks92\ValueObjects\Enum\Enum;
49+
/**
50+
* @method static MyStatus wait()
51+
* @method static MyStatus active()
52+
* @method static MyStatus blocked()
53+
*/
54+
final class MyStatus extends Enum
55+
{
56+
private const WAIT = 'wait';
57+
private const ACTIVE = 'active';
58+
private const BLOCKED = 'blocked';
59+
}
60+
61+
$myStatus = MyStatus::wait()->getValue(); //wait
62+
$myStatus = MyStatus::active()->getValue(); //active
63+
$myStatus = MyStatus::blocked()->getValue(); //blocked
64+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /