Skip to content

Netsilik/Enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enum

Strict Enumeration class.


MIT Licence

Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Contact: [email protected]
Latest version available at: https://gitlab.com/Netsilik/Enum


Example of usage

// Object creation
final class Species extends Enum {
    protected $enum = array('human','monkey','alien');
}

// Use Enum
function checkSpecies(Species $enum) {
    return ($enum <> 'alien') ? 'Hello' : 'Waaah!';
}
checkSpecies(new Species('monkey')); // returns 'Hello'


// Use Enum with invalid value
function checkSpecies(Species $enum) {
    return ($enum <> 'alien') ? 'Hello' : 'Waaah!';
}
checkSpecies(new Species('lion')); // triggers Fatal Error: 'Provided value is not part of this enumerated list'

Installation

composer require netsilik/enum

About

Strict Enumeration class

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages