Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Interface instead of enum for UserStatus #2

Open
hosni opened this issue Nov 21, 2023 · 0 comments
Open

Use Interface instead of enum for UserStatus #2

hosni opened this issue Nov 21, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@hosni
Copy link
Member

hosni commented Nov 21, 2023

Hello
I'm trying to implement a package that depends on laravel-aaa.
But, I faced a problem, My User model's status is different than the dnj\AAA\Contracts\UserStatus that defined as contract.
As you know, we can not extend an Enum: Why enums aren't extendable
But, luckily Enums can implement Interface
So I suggest to define an Interface that named dnj\AAA\Contracts\IUserStatus and use this Interface as our input-output type and the UserStatus implements this Interface, see:

namespace dnj\AAA\Contracts;

enum UserStatus: string implements IUserStatus
{
    case ACTIVE = 'ACTIVE';
    case SUSPEND = 'SUSPEND';
}
@hosni hosni added the enhancement New feature or request label Nov 21, 2023
@hosni hosni self-assigned this Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant