Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Enumhancer Laravel Package

henzeb/enumhancer

View on GitHub
Deep Wiki
Context7

Extractor

Sometimes you have a piece of text that contains an enum value that you want to use. With this you can simply pass a multiline string and extract all enums that are mentioned by value.

Note: This also works with Mappers, you can either pass along a mapper as second parameter or use the Mapperstrait in case you need the default mapper feature.

Usage

use Henzeb\Enumhancer\Concerns\Extractor;

enum YourEnum: string {
    use Extractor;

    case ENUM = 'enum';
    case ENUM2 = 'another enum';
}

enum YourOtherEnum: int {
    use Extractor;

    case ENUM = 0;
    case ENUM2 = 1;
}

Examples

YourEnum::extract('you can find another enum here'); // returns [YourEnum::ENUM2]
YourEnum::extract('A lot of text with (enum)'); // returns [YourEnum::ENUM]
YourEnum::extract('another enum (enum)'); // returns [YourEnum::ENUM2, YourEnum::ENUM]
YourEnum::extract('extract case sensitive another ENUM') // returns [YourEnum::ENUM2];
YourEnum::extract('contains multiple enums') // returns [];

YourOtherEnum::extract('I found 1 truth'); // returns [YourOtherEnum::ENUM2]
YourOtherEnum::extract('has 1 truth 0 lies'); // returns [YourOtherEnum::ENUM2, YourOtherEnum::ENUM]
YourOtherEnum::extract('I found 100 lies'); // returns []

Note: You can use Mappers in combination with Extractor. This might be helpful when the source has multiple or different notations of your enum cases.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime