PHPackages                             panlatent/craft-enums - 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. panlatent/craft-enums

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

panlatent/craft-enums
=====================

2381PHP

Since May 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/panlatent/craft-enums)[ Packagist](https://packagist.org/packages/panlatent/craft-enums)[ RSS](/packages/panlatent-craft-enums/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (1)

Craft Enums
===========

[](#craft-enums)

The Craft Enum is a PHP enum generator. It generates all Fields, Section, Volume ... handles write to code as cases.

```
// Get a section
$section = Section::Posts->section()
// Create a entry with sectionId
$entry = Section::Posts->new()
// Entry query with section
$entryQuery = Section::Post->find();
// Replace string handle (Not recommended)
$section = Craft::$app->secionts->getSectionByHandle(Section::Posts->value);
```

```
Note: You cannot use PHP enumerations to directly replace string. You should write `getSectionByHandle(Section::Posts->value)` instead of `getSectionByHandle(Section::Posts)`(error).
      Maybe, never try to use enums instead of strings or constants, but use the convenience methods of the enum class.

```

Requirements
------------

[](#requirements)

- PHP 8.2
- Craft CMS 4.3.5 or later.

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

[](#installation)

```
composer require panlatent/craft-enum --dev
```

Usage
-----

[](#usage)

### Generate

[](#generate)

- Manual

Reference: [CraftCMS Docs](https://craftcms.com/docs/5.x/extend/generator.html#usage)

```
php craft make enums
```

Generate enums to `src/enums`

```
ddev craft make enums --path=src
```

- Automatic

It is recommended that you register events to generate real-time:

```
use panlatent\craft\enums\Enums;
Event::on(ProjectConfig::class, ProjectConfig::EVENT_AFTER_WRITE_YAML_FILES), function() {
    (new \Symfony\Component\Process\Process(['php', 'craft', 'make', 'enums', '--path=src', '--interactive=1'], Craft::getAlias('@root'), [Enums::DISABLE_INTERACTIVE => true]))->mustRun();
});
```

We use the `Symfony Process` component to run build commands when the project changes, using `--interactive=1` and `Enums::DISABLE_INTERACTIVE => true` in order to bypass CraftCMS limitation.

### Coding

[](#coding)

See generate codes.

References
----------

[](#references)

License
-------

[](#license)

The project is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![panlatent](https://avatars.githubusercontent.com/u/4393268?v=4)](https://github.com/panlatent "panlatent (16 commits)")

---

Tags

constcraftcmsenumyii2yii2-extension

### Embed Badge

![Health badge](/badges/panlatent-craft-enums/health.svg)

```
[![Health](https://phpackages.com/badges/panlatent-craft-enums/health.svg)](https://phpackages.com/packages/panlatent-craft-enums)
```

###  Alternatives

[tobion/retry

A generic library to retry an operation in case of an error. You can configure the behavior like the exceptions to retry on.

16396.8k](/packages/tobion-retry)[franzose/laravel-smpp

SMS sending via SMPP protocol for Laravel framework.

3941.6k1](/packages/franzose-laravel-smpp)[cammac/carbony

convert from/to Hijri and Gregorian

2443.0k](/packages/cammac-carbony)[steevanb/symfony-container-introspection

Get all Symfony Container informations you need: registered services, instanciated services etc

1034.5k](/packages/steevanb-symfony-container-introspection)

PHPackages © 2026

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