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

Extended Php Laravel Package

open-southeners/extended-php

Extended PHP helpers for modern apps: adds convenient functions, utilities, and small enhancements that complement core PHP to reduce boilerplate and speed up everyday development. Lightweight, easy to drop into existing projects.

View on GitHub
Deep Wiki
Context7

description: List of functions that works for PHP enums.

Enums helpers

is_enum

Check if object or class is a PHP enum.

enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\is_enum(MyEnum::class); // true

enum_is_backed

Check if object or class is a backed PHP enum.

enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\enum_is_backed(MyEnum::class); // false

has_case

Check if object or class is a PHP enum that has the specified case.

enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\has_case(MyEnum::class, 'First'); // true

get_enum_class

Get class string from enum object.

enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\get_enum_class(MyEnum::First); // 'MyEnum'

enum_to_array

Converts PHP enum object or class into an array. In case of a backed enum it will add its values.

enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\enum_to_array(MyEnum::class);
// ['First', 'Second', 'Third']

enum_values

Gets array of values from PHP backed enum.

enum MyBackedEnum: string
{
    case First = 'one';

    case Second = 'two';

    case Third = 'three';
}

\OpenSoutheners\ExtendedPhp\Enums\enum_values(MyBackedEnum::class);
// ['one', 'two', 'three']

GetsAttributes

{% hint style="info" %} This is not a function but still serves as a utility. Make sure you only use this with backed enums. {% endhint %}

This trait will add some functions to the PHP enums so they can be converted to arrays to be used in multiple contexts (like HTML selects, etc).

Description

This is a PHP attribute to be used in those enum cases to be used along with GetsAttribute trait:

use OpenSoutheners\ExtendedPhp\Enums\Description;
use OpenSoutheners\ExtendedPhp\Enums\GetsAttributes;

enum MyBackedEnum: string
{
    use GetsAttributes;

    #[Description('First point')]
    case First = 'one';
    #[Description('Second point')]
    case Second = 'two';
    #[Description('Third point')]
    case Third = 'three';
}

More details of their usage below.

asSelectArray

The only public method available on this trait which will get all described cases of your enum.

Now imagine the case having the enum shown before:

MyBackedEnum::asSelectArray();
// ['one' => 'First point', 'two' => 'Second point', 'three' => 'Third point']
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky