Skip to content

Conversation

@lachlankrautz
Copy link
Contributor

@lachlankrautz lachlankrautz commented Sep 9, 2018

Added initFromKey($key) to get an enum instance from the key.

Mostly useful to convert the db value stored into the Enum on a model.

class Animal extends Enum
{
    const CAT = 'kitty';
    const DOG = 'dog';
    const HORSE = 'horse';
    const PIGEON = 'skyrat';
}

// Init from key in variable (probably loaded from db, or submitted by user)
$kitty = 'kitty'; 
$cat = Animal::initFromKey($kitty);

@jodiedunlop jodiedunlop merged commit a811887 into master Sep 13, 2018
@jodiedunlop jodiedunlop deleted the feature/init-key branch September 13, 2018 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants