Skip to content

Commit

Permalink
base enum
Browse files Browse the repository at this point in the history
  • Loading branch information
nalatreb committed Apr 2, 2016
1 parent 0cb01d0 commit 4f9859c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "wboyz/laravel-enum",
"description": "Base enum class with some features.",
"version": "v0.1.0",
"type": "helper",
"license": "MIT",
"keywords": ["laravel", "enum"],
"homepage": "https://github.com/wboyz/laravel-enum",
"autoload": {
"psr-4": {
"WBoyz\\LaravelEnum\\": "src/"
}
},
"authors": [
{
"name": "Bertalan Verebelyi",
"email": "[email protected]"
},
{
"name": "Csaba Verebelyi",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.5.9"
}
}
41 changes: 41 additions & 0 deletions src/BaseEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace "WBoyz\LaravelEnum";

use ReflectionClass;

abstract class BaseEnum
{
/**
* Returns the enum values.
*
* @return array
*/
public static function getValues()
{
return array_values(static::toDictionary());
}

/**
* Returns the enum keys.
*
* @return array
*/
public static function getKeys()
{
return array_keys(static::toDictionary());
}

/**
* Returns the enum as dictionary.
*
* @return array
*/
public static function toDictionary()
{
$className = get_called_class();
$reflectionClass = new ReflectionClass($className);

return $reflectionClass->getConstants();
}
}

0 comments on commit 4f9859c

Please sign in to comment.