enums icon indicating copy to clipboard operation
enums copied to clipboard

Support defining #[Meta] on traits

Open stancl opened this issue 3 years ago • 0 comments

That way, users can create a trait such as:

/**
 * @method string description()
 */
#[Meta(Description::class)
trait HasDescription
{}

And use this across their enums as:

enum Status
{
+   use HasDescription;

+   #[Description('Completed Task')]
    case COMPLETED;
}

enum Role
{
+   use HasDescription;

+   #[Description('Administrator')]
    case ADMIN;

+   #[Description('Read-only user')]
    case GUEST;
}

Implementation

Edit ArchTech\Enums\Meta\Reflection::metaProperties() to also recursively walk through the enum's traits, and extract the enabled meta properties in their #[Meta] attributes, if they're defined.

stancl avatar Mar 29 '22 17:03 stancl