Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit da76736

Browse files
author
Petr Knap
committed
Added example of conversion between value and Enum instance
1 parent 3bd9828 commit da76736

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,38 @@ class MixedValues extends \PetrKnap\Php\Enum\Enum
155155
}
156156
```
157157

158+
You can simply convert value to Enum instance and vice versa.
159+
160+
```php
161+
/**
162+
* @ORM\Entity
163+
*/
164+
class MyEntity
165+
{
166+
/**
167+
* @ORM\Column(type="integer")
168+
* @var int
169+
*/
170+
private $flag;
171+
172+
/**
173+
* @return MyBoolean
174+
*/
175+
public function hasFlag()
176+
{
177+
return MyBoolean::getEnumByValue($this->flag);
178+
}
179+
180+
/**
181+
* @param MyBoolean $value
182+
*/
183+
public function setFlag(MyBoolean $value)
184+
{
185+
$this->flag = $value->getValue();
186+
}
187+
}
188+
```
189+
158190

159191
## How to install
160192

0 commit comments

Comments
 (0)