Skip to content

Commit 3d1b6f3

Browse files
author
Igor Chepurnoy
authored
Update README.md
1 parent 975315b commit 3d1b6f3

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

README.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,50 @@ or add
2424

2525
to the require section of your `composer.json` file.
2626

27+
## Available Methods:
28+
29+
- `createByName()` - Creates a new type instance using the name of a value.
30+
- `getValueByName()` - Returns the constant key by value(label)
31+
- `createByValue()` - Creates a new type instance using the value.
32+
- `listData()` - Returns the associative array with constants values and labels
33+
- `getLabel()`- Returns the constant label by key
34+
- `getConstantsByName()` - Returns the list of constants (by name) for this type.
35+
- `getConstantsByValue()` - Returns the list of constants (by value) for this type.
36+
- `isValidName()` - Checks if a name is valid for this type.
37+
- `isValidValue()` - Checks if a value is valid for this type.
38+
39+
## Declaration
2740

28-
### Example enumerable class
2941
```php
3042
use yii2mod\enum\helpers\BaseEnum;
31-
class YesNoEnumerable extends BaseEnum
43+
44+
class BooleanEnum extends BaseEnum
3245
{
33-
public static $messageCategory = 'app';
3446
const YES = 1;
35-
const NO = 2;
36-
47+
const NO = 0;
48+
49+
/**
50+
* @var string message category
51+
* You can set your own message category for translate the values in the $list property
52+
* Values in the $list property will be automatically translated in the function `listData()`
53+
*/
54+
public static $messageCategory = 'app';
55+
3756
public static $list = [
3857
self::YES => 'Yes',
39-
self::NO => 'No'
58+
self::NO => 'No'
4059
];
4160
}
4261
```
43-
### Example usage
62+
## Usage
4463
```php
45-
var_dump(YesNoEnumerable::YES);
46-
var_dump(YesNoEnumerable::NO);
47-
var_dump(YesNoEnumerable::getConstantsByValue());
48-
var_dump(YesNoEnumerable::getConstantsByName());
49-
var_dump(YesNoEnumerable::isValidName(1)); // false
50-
var_dump(YesNoEnumerable::isValidName('YES'));
51-
var_dump(YesNoEnumerable::isValidValue(1));
52-
var_dump(YesNoEnumerable::isValidValue('YES')); //false
53-
var_dump(YesNoEnumerable::listData());
54-
var_dump(YesNoEnumerable::getLabel(1));
55-
var_dump(YesNoEnumerable::getLabel('YES')); // false
64+
BooleanEnum::getConstantsByValue() // [1 => 'YES', 0 => 'NO']
65+
BooleanEnum::getConstantsByName() // ['YES' => 1, 'NO' => 0]
66+
BooleanEnum::isValidName(1) // false
67+
BooleanEnum::isValidName('YES') // true
68+
BooleanEnum::isValidValue(1) // true
69+
BooleanEnum::isValidValue('Yes') // false
70+
BooleanEnum::listData() // [1 => 'Yes', 0 => 'No']
71+
BooleanEnum::getLabel(1) // Yes
72+
BooleanEnum::getValueByName('Yes') // 1
5673
```

0 commit comments

Comments
 (0)