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 39a667f

Browse files
committed
Edit docs
1 parent a69f18a commit 39a667f

File tree

4 files changed

+140
-45
lines changed

4 files changed

+140
-45
lines changed

‎docs/readme.md‎

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,18 @@ Using Value Objects will avoid duplication of code, as well as make your propert
44
## Usage
55
Value Objects this library are divided into several logical groups:
66

7+
- [String](usage/string.md)
8+
- [Number](usage/number.md)
9+
- [Enum](usage/enum.md)
710
- [Web](usage/web.md)
811
- [Identity](usage/identity.md)
912
- [Security](usage/security.md)
1013
- [Person](usage/person.md)
1114
- [Geography](usage/geography.md)
1215
- [Money](usage/money.md)
1316
- [Payment](usage/payment.md)
14-
- [Enum](usage/enum.md)
1517

1618
This separation is only a structuring of the Value Objects in library. You can use these objects as you discretion.
1719

1820
### Creating own Value Objects
19-
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:
20-
21-
For string type
22-
```php
23-
use Myks92\ValueObjects\String\StringLiteral;
24-
25-
final class MyTitle extends StringLiteral
26-
{
27-
}
28-
$myTitle = new MyTitle('Title');
29-
$myTitle->getValue(); //Title
30-
```
31-
32-
For integer type
33-
```php
34-
use Myks92\ValueObjects\Number\Integer;
35-
36-
final class MyAge extends Integer
37-
{
38-
}
39-
40-
$myAge = new MyAge(12);
41-
$myAge->getValue(); //12
42-
```
43-
44-
For option type
45-
```php
46-
use Myks92\ValueObjects\Enum\Enum;
47-
/**
48-
* @method static MyStatus wait()
49-
* @method static MyStatus active()
50-
* @method static MyStatus blocked()
51-
*/
52-
final class MyStatus extends Enum
53-
{
54-
private const WAIT = 'wait';
55-
private const ACTIVE = 'active';
56-
private const BLOCKED = 'blocked';
57-
}
58-
59-
$myStatus = MyStatus::wait()->getValue(); //wait
60-
$myStatus = MyStatus::active()->getValue(); //active
61-
$myStatus = MyStatus::blocked()->getValue(); //blocked
62-
```
21+
This library has only popular value objects. But you can always create your own and complement exists objects, extends them.

‎docs/usage/enum.md‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This groups Value Objects use for any options, e.g status, role, gender or anoth
1010
Static methods:
1111
* `toArray()` method Returns all possible values as an array (constant name in key, constant value in value)
1212

13+
### Example Status VO
1314
```php
1415
use Myks92\ValueObjects\Enum\Enum;
1516

@@ -74,4 +75,88 @@ class Status extends Enum
7475
private const ACTIVE = 'active';
7576
private const BLOCKED = 'blocked';
7677
}
78+
```
79+
80+
### Example Gender VO
81+
```php
82+
use Myks92\ValueObjects\Enum\Enum;
83+
84+
/**
85+
* @method static Gender male()
86+
* @method static Gender female()
87+
* @method static Gender other()
88+
*/
89+
class Gender extends Enum
90+
{
91+
/**
92+
* @var string value for male
93+
*/
94+
public const MALE = 'male';
95+
/**
96+
* @var string value for female
97+
*/
98+
public const FEMALE = 'female';
99+
/**
100+
* @var string value for other
101+
*/
102+
public const OTHER = 'other';
103+
104+
/**
105+
* Create male
106+
*
107+
* @return static
108+
*/
109+
public static function male(): self
110+
{
111+
return new self(self::MALE);
112+
}
113+
114+
/**
115+
* Create female
116+
*
117+
* @return static
118+
*/
119+
public static function female(): self
120+
{
121+
return new self(self::FEMALE);
122+
}
123+
124+
/**
125+
* Create other
126+
*
127+
* @return static
128+
*/
129+
public static function other(): self
130+
{
131+
return new self(self::OTHER);
132+
}
133+
134+
/**
135+
* @return bool
136+
*/
137+
public function isMale(): bool
138+
{
139+
return $this->getValue() === self::MALE;
140+
}
141+
142+
/**
143+
* @return bool
144+
*/
145+
public function isFemale(): bool
146+
{
147+
return $this->getValue() === self::FEMALE;
148+
}
149+
150+
/**
151+
* @return bool
152+
*/
153+
public function isOther(): bool
154+
{
155+
return $this->getValue() === self::OTHER;
156+
}
157+
}
158+
// Static method:
159+
$gender = Gender::male();
160+
$gender = Gender::female();
161+
$gender = Gender::other();
77162
```

‎docs/usage/number.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Number
2+
This groups Value Objects use for any string type
3+
4+
## Integer
5+
### Available Methods
6+
* `__construct()` The constructor create the value
7+
* `__toString()` You can `echo $myValue`, it will display the string value.
8+
* `getValue()` Returns the current value
9+
* `isEqualTo()` Tests whether instances are equal (returns `true` if values are equal, `false` otherwise)
10+
11+
### Example
12+
```php
13+
use Myks92\ValueObjects\Number\Integer;
14+
15+
final class MyAge extends Integer
16+
{
17+
}
18+
19+
final class MyAge2 extends Integer
20+
{
21+
}
22+
23+
$myAge = new MyAge(12);
24+
$myAge->getValue(); //12
25+
26+
$myAge2 = new MyAge2(14);
27+
$myAge2->getValue(); //14
28+
$myAge2->isEqualTo($myAge); //false
29+
30+
echo $myAge; //'12'
31+
```

‎docs/usage/string.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# String
2+
This groups Value Objects use for any string type
3+
4+
## String
5+
### Available Methods
6+
* `__construct()` The constructor checks that the value not empty
7+
* `__toString()` You can `echo $myValue`, it will display the string value.
8+
* `getValue()` Returns the current value
9+
* `isEqualTo()` Tests whether instances are equal (returns `true` if values are equal, `false` otherwise)
10+
11+
### Example
12+
```php
13+
use Myks92\ValueObjects\String\StringLiteral;
14+
15+
final class MyTitle extends StringLiteral
16+
{
17+
}
18+
$myTitle = new MyTitle('Title');
19+
$myTitle->getValue(); //Title
20+
```

0 commit comments

Comments
(0)

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