yethee/enum-bundle
Symfony bundle that integrates PHP 8.1 enums into your app: autowire enum instances, use enum-aware form types and validator constraints, map enums with Doctrine types, and simplify enum choices in configuration and templates.
composer require yethee/enum-bundle (or the yethee/biplane-enum library if you only want the core). Check the bundle's composer.json first: this is a Symfony 2-era bundle, so its symfony/symfony constraint will likely block installation on Symfony 4+. Then register it manually in AppKernel::registerBundles() — there is no Flex recipe.vendor/yethee/enum-bundle/README.mdBiplane\Enum\AbstractEnum — this is where getValues(), getReadableValues(), isValid(), and create() live.Form/Type/EnumType.php and Validator/Constraints/Enum.php — the two integration points you will actually touch day to day.Command/ — the enum generator, if it ships in your version.app/console biplane:enum:generate ...) or hand-write a class extending the bundle's enum base, defining one constant per member and overriding the readable-label method (e.g. getReadable() / getReadableValues()).<select> via EnumType, validated with the Enum constraint, with the enum class as the single source of truth for both allowed codes and display labels. That end-to-end slice is the fastest way to see whether the package earns its place.1/'active' literals through templates and services.class option or the type's constructor, depending on the version). Populate choices from getReadableValues() so the select shows labels while submitting values. For a multi-select, use the same type with multiple => true.Enum constraint to the scalar property (or to request DTOs) so tampered POSTs are rejected before conversion. Validate the raw scalar, not the enum object.string/integer. On hydrate, wrap with the enum's static factory (create()/createByValue()); on persist, write ->getValue(). Do this in the entity accessor/mutator or a lifecycle callback rather than a custom Doctrine type — it keeps the mapping portable and avoids surprises in DQL.Enum::getReadableValues(). If entities hold enum objects, rely on __toString()/readable getter. Either way, centralise it so label changes are one edit.Enum::isValid($input) fails, then construct the enum. Serialize back out as ->getValue(), never as the object, so your JSON contract survives refactors.getValues() catch coverage gaps; add an assertion that every constant has a readable label so new members can't ship with a raw value as their display name.getReadable()-equivalent method on the enum for labels.AbstractEnum caches reflected constants statically. Constants must be declared on the class — you cannot register enum members at runtime, and dynamic or conditionally-defined subclasses will behave unpredictably. If you run APC/opcache and change enum classes on deploy, clear caches.isValid(1) and isValid('1') are not necessarily interchangeable depending on the version; request data always arrives as strings. Cast explicitly at the boundary before validating, or you will reject valid input or accept invalid input depending on the enum's value type.setDefaultOptions() and a constructor argument; newer ones use configureOptions() and a class option. Passing the wrong one throws an InvalidConfigurationException that doesn't clearly point at the cause. Read the type's option configuration before wiring it.findBy, and ORDER BY becomes painful. Also avoid keeping enum objects in session or queued messages — a class refactor or removed constant turns stored data into an unserializable blob. Persist scalars.class/choices, and write your own constraint if you need richer error messages than the bundled one. These are all small classes — copying them into your app is often cleaner than depending on them.How can I help you explore Laravel packages today?