1. Go to this page and download the library: Download frameck/awesome-enums library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
frameck / awesome-enums example snippets
namespace App\Enums;
use Frameck\AwesomeEnums\Traits\Comparable;
use Frameck\AwesomeEnums\Traits\HasDetails;
use Frameck\AwesomeEnums\Traits\HasHelpers;
enum DeclineCode: string
{
use Comparable;
use HasDetails;
use HasHelpers;
}
enum DeclineCode: string
{
use Comparable;
use HasDetails;
use HasHelpers;
case DEFAULT = 'default';
case CARD_NOT_SUPPORTED = 'card_not_supported';
case DO_NOT_HONOR = 'do_not_honor';
case EXPIRED_CARD = 'expired_card';
case GENERIC_DECLINE = 'generic_decline';
}
DeclineCode::EXPIRED_CARD() // equivalent to DeclineCode::EXPIRED_CARD->value
DeclineCode::EXPIRED_CARD('name') // equivalent to DeclineCode::EXPIRED_CARD->name
DeclineCode::EXPIRED_CARD('value') // equivalent to DeclineCode::EXPIRED_CARD->value
$declineCode = DeclineCode::EXPIRED_CARD;
$declineCode() // equivalent to $declineCode->value
$declineCode('name') // equivalent to $declineCode->name
$declineCode('value') // equivalent to $declineCode->value
private function defaultDetails(): array
{
return [
'name' => 'Call Issuer',
'select' => 'Call issuer',
'description' => 'The card was declined for an unknown reason.',
'next_steps' => 'The customer needs to contact their card issuer for more information.',
];
}
private function cardNotSupportedDetails(): array
{
return [
'name' => 'Card Not Supported',
'description' => 'The card was declined for an unknown reason.',
'next_steps' => 'The customer needs to contact their card issuer for more information.',
];
}
private function doNotHonorDetails(): array
{
return [
'name' => 'Do Not Honor',
'description' => 'The card was declined for an unknown reason.',
'next_steps' => 'The customer needs to contact their card issuer for more information.',
];
}
private function expiredCardDetails(): array
{
return [
'name' => 'Expired Card',
'description' => 'The card was declined for an unknown reason.',
'next_steps' => 'The customer needs to contact their card issuer for more information.',
];
}
private function genericDeclineDetails(): array
{
return [
'name' => 'Generic Decline',
'description' => 'The card was declined for an unknown reason.',
'next_steps' => 'The customer needs to contact their card issuer for more information.',
];
}
DeclineCode::EXPIRED_CARD->getDetails('description');
// result
// The card was declined for an unknown reason.
DeclineCode::toSelect();
[
"default" => "Call issuer",
"card_not_supported" => "Card Not Supported",
"do_not_honor" => "Do Not Honor",
"expired_card" => "Expired Card",
"generic_decline" => "Generic Decline",
]
// the toSelect() method is based on the details() array so you can specify a custom label for the select
// in order the package searches for a 'select' key then 'label' and 'name'
// so you can have a different value for 'name' and 'select'
public static function toSelect(): array
{
return collect(self::cases())
->mapWithKeys(function (self $case) {
$caseDetails = $case->getDetails();
$selectLabel = $caseDetails['select']
?? $caseDetails['label']
?? $caseDetails['name'];
return [
$case->value => $selectLabel,
];
})
->toArray();
}
DeclineCode::toJson();
// "{"default":"Call issuer","card_not_supported":"Card Not Supported","do_not_honor":"Do Not Honor","expired_card":"Expired Card","generic_decline":"Generic Decline"}"