Giter Club home page Giter Club logo

enums's People

Contributors

colinmackinlay avatar ejunker avatar hungthai1401 avatar lukinovec avatar parth391 avatar samlev avatar stancl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

enums's Issues

Support defining #[Meta] on traits

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.

Add an Enum::values() helper method

To get a list of all scalar values for an enum, you'd currently have to loop over all ::cases() and get the value.

Having a helper for this would be sweet.

Laravel package

It would be great if a separate package is made for laravel.

e.g. Command for enum annotate method tag

  /**
   * @method static SUPER_ADMIN()
   * @method static ADMIN()
   */
  enum RoleName: string
  {
      use InvokableCases;
  
      case SUPER_ADMIN = 'SUPER_ADMIN';
      case ADMIN = 'ADMIN';
  }

Add an Enum::toOptions() method

This method would essentially map over each variant/case and return an associative array of ->name => ->value. Super useful for creating dropdowns for enums, think status enums, role enums etc.

Filtering

Filterable options, values or names

fromName() & tryFromName()

To instantiate a backed enum using the case name.

Perhaps passing a callback would also work, if transformations or comparisons are needed (e.g. I have a use case that does strtoupper() to convert the readable version to the case name).

CamelCase vs UPPER_CASE

Very interesting library!

One question:
Have you considered using what appears to be the convention for enums: CamelCase?

We had similar discussions for CakePHP for example:
cakephp/bake#972
And in the end seemed to go with those, as the cases are different from the constants in the end.
This way it also seems easier to distinguish the two.
It also seems to be the way they were intended to be in terms of convention by the core PHP (RFC).

Also saw a bit of both in your example so far: fc428d5#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R210

What do you think?

For form options we usually use

<option value="MultiWord">Multi Word</option>

as CamelCase for key vs Humanized Form for text.

Side note:
I also added a specific trait to mine for sorting and custom filtering (for some forms only a subset sometimes is wanted):
https://github.com/dereuromark/cakephp-tools/blob/master/src/Model/Entity/EnumTrait.php
Could be yours with a custom fn can also already do that out of the box, just doesnt mention it yet.

Trait for string conversion

For enum fields, I like to keep a comment in the database that has all the enum values and text. It might be useful to have a Trait with a toString() to get this? I personally also include a $nameFirst parameter to specify if I want:

1 => Admin, 2 => Instructor, 3 => Student
or
Admin => 1, Instructor => 2, Student =>3

Thanks for the great package!

interface implementations

would it be good to implement the interface to identify if the enum has the trait Values, Names..?

Example

use ArchTech\Enums\Names;
use ArchTech\Enums\Traits\Nameable;

enum TaskStatus: int implements Nameable
{
    use Names;

    case INCOMPLETE = 0;
    case COMPLETED = 1;
    case CANCELED = 2;
}

```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.