Skip to content

Instantly share code, notes, and snippets.

@maxpou
Created May 26, 2016 13:00
Show Gist options
  • Save maxpou/649f831685cf05ed64c9886d2f96410e to your computer and use it in GitHub Desktop.
Save maxpou/649f831685cf05ed64c9886d2f96410e to your computer and use it in GitHub Desktop.
<?php
namespace Bim\Bam\BingoEnum;
use Symfony\Component\Validator\Exception\InvalidArgumentException;
abstract class BeerErrorCode
{
const BARRELEMPTY = 4;
const SERVICESTOP = 8;
const YOURDRUNK = 15;
const SHITTYBEER = 16;
const PAYFIRST = 23;
const NOTENOUGHMONEY = 42;
protected static $errorNames = array(
self::BARRELEMPTY => 'Oh no! Barrel is empty!',
self::SERVICESTOP => 'It\'s over guys. See you tomorrow :)',
self::YOURDRUNK => 'You\'re drunk. Go Home!',
self::SHITTYBEER => 'We don\'t serve Kronembourg.',
self::PAYFIRST => 'You need to pay first!',
self::NOTENOUGHMONEY => 'Not a charitable organization'
);
/**
* Return error name
* @param int $errorCode Error's code
* @return string Error's name
*/
public static function getErrorName($errorCode)
{
if (!isset(static::$errorNames[$errorCode])) {
return "Unknown error (code: $errorCode)";
}
return static::$errorNames[$errorCode];
}
}
//--------------------------------------------
// Using:
echo BeerErrorCode::BARRELEMPTY;
// 4
echo BeerErrorCode::getErrorName(BeerErrorCode::BARRELEMPTY);
// Oh no! Barrel is empty!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment