PHPackages                             abhi1693/yii2-enum - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. abhi1693/yii2-enum

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

abhi1693/yii2-enum
==================

Enumerable Helper

v1.0.0(11y ago)419.2k↓17.6%2MIT LicensePHP

Since Jan 29Pushed 5y ago2 watchersCompare

[ Source](https://github.com/abhi1693/yii2-enum)[ Packagist](https://packagist.org/packages/abhi1693/yii2-enum)[ RSS](/packages/abhi1693-yii2-enum/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Yii2-Enum
=========

[](#yii2-enum)

[![Dependency Status](https://camo.githubusercontent.com/f5de92763d6192bda4255aef48e2dea0fb492f5419385af536ae9d63fb7cc02f/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3534653165363535306139313062303836353030303165342f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/54e1e6550a910b08650001e4)[![Code Climate](https://camo.githubusercontent.com/07f964ffe03c48df14ce72c708a825967ec77cdcfde3e6d031aea8d5d7bbd055/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f61626869313639332f796969322d656e756d2f6261646765732f6770612e737667)](https://codeclimate.com/github/abhi1693/yii2-enum)[![Latest Stable Version](https://camo.githubusercontent.com/11d57c6d3eacc43f18348c7c922fbc826b46dae5e23efa13915cfc205ef87fa6/68747470733a2f2f706f7365722e707567782e6f72672f61626869313639332f796969322d656e756d2f762f737461626c652e737667)](https://packagist.org/packages/abhi1693/yii2-enum) [![Total Downloads](https://camo.githubusercontent.com/00d567ebaf10939176178932d6fbbbc98b5403ce192311a250b929c1f8189ed2/68747470733a2f2f706f7365722e707567782e6f72672f61626869313639332f796969322d656e756d2f646f776e6c6f6164732e737667)](https://packagist.org/packages/abhi1693/yii2-enum) [![Latest Unstable Version](https://camo.githubusercontent.com/1606f73d7afa27c22a26c31c051a1f3cad7826764d341b2a324fcda9c8e2cb09/68747470733a2f2f706f7365722e707567782e6f72672f61626869313639332f796969322d656e756d2f762f756e737461626c652e737667)](https://packagist.org/packages/abhi1693/yii2-enum) [![License](https://camo.githubusercontent.com/74576330af046fb6edc0ef84ed75ec8b39d01b83803030cf85f23852c1e1f89b/68747470733a2f2f706f7365722e707567782e6f72672f61626869313639332f796969322d656e756d2f6c6963656e73652e737667)](https://packagist.org/packages/abhi1693/yii2-enum)

Documentation
-------------

[](#documentation)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist abhi1693/yii2-enum "1.0.0"

```

or add

```
"abhi1693/yii2-enum": "1.0.0"

```

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

Usage
-----

[](#usage)

The `BaseEnum` class provides support for enumerated types. The class also provides functionality that may be useful in the course of creating and validation enums. To make use of it, you simply create your own class that extends `BaseEnum`:

```
use abhimanyu\enum\helpers;

class Month extends BaseEnum
{
    const January = 1;
    const February = 2;
    const March = 3;
    const April = 4;
    const May = 5;
    const June = 6;
    const July = 7;
    const August = 8;
    const September = 9;
    const October = 10;
    const November = 11;
    const December = 12;
}
```

There are multiple ways to create a new value for an enumerated type:

```
// static call
$month = Month::May();

// direct instantiation
$month = new Month(Month::May);

// by value
$month = Month::createByValue(5);

// by name
$month = Month::createByName('May');
```

It is possible to retrieve the name and value of the instance of the enumerated type:

```
$name = $month->getName();
$value = $month->getValue();
```

> **NOTE:** If you have multiple class constants defined with the same value, then an array of names will be returned instead of a string for only one. It will be up to you to decide which to use.

The class also provides ways of validating names and values:

```
if (Month::isValidName('May')) {
    // it is valid
}

if (Month::isValidValue($value)) {
    // it is valid
}
```

If you need to retrieve a complete list of possible enum values, you can get them either by name or value:

```
$constantsByName = Month::getConstantsByName();

echo $constantsByName['May']; // 5

$constantsByValue = Month::getConstantsByValue();

echo $constantsByValue[5]; // "May"
```

#### How to contribute?

[](#how-to-contribute)

Contributing instructions are located in [CONTRIBUTING.md](CONTRIBUTING.md) file.

License
-------

[](#license)

Yii2-Enum is released under the MIT License. See the bundled [LICENSE](LICENSE) for details.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4127d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a4a99a3f28d332902a07f63e7ba1fbd7d05203aae7b4caf7e065902ccb26fe2c?d=identicon)[abhi1693](/maintainers/abhi1693)

---

Top Contributors

[![abhi1693](https://avatars.githubusercontent.com/u/5083532?v=4)](https://github.com/abhi1693 "abhi1693 (13 commits)")

---

Tags

enumyii2extensionmodule

### Embed Badge

![Health badge](/badges/abhi1693-yii2-enum/health.svg)

```
[![Health](https://phpackages.com/badges/abhi1693-yii2-enum/health.svg)](https://phpackages.com/packages/abhi1693-yii2-enum)
```

###  Alternatives

[onmotion/yii2-telegram

Support chat for site based on Telegram bot

526.3k](/packages/onmotion-yii2-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
