1. Go to this page and download the library: Download jac/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/ */
jac / enums example snippets
use Jac\Enum\AbstractEnum;
/**
* SendingStatus Enum
* @method SendingStatus PROCESSING()
* @method SendingStatus SENT()
*/
final class SendingStatus extends AbstractEnum
{
private const PROCESSING = '1 - Processing';
private const SENT = '2 - Sent';
}
function notifyUser(SendingStatus $status) {
if ($status == SendingStatus::SENT()) {
// your package have been sent
}
}
$key = 'PROCESSING';
// Validate first the enum by inEnum
if (SendingStatus::inEnum($key)) {
notifyUser(SendingStatus::$key());
}
namespace App\Enums;
use Jac\Enum\AbstractEnum;
final class Devise extends AbstractEnum
{
/**
* @default
*/
private const RMB = 'RMB'; // will be used due to the default tag
private const CNY = 'RMB';
private const EUR = 'EUR'; // will be used as the other key is deprecated
/**
* @deprecated
*/
private const FRA = 'EUR';
private const US_DOLLAR = 'USD'; // will be used because of the __DEFAULT__ configuration
private const USD = 'USD';
private const __DEFAULT__ = array(
'USD' => 'US_DOLLAR'
);
}
use Jac\Enum\EnumJsonFormat;
echo json_decode(EnumJsonFormat::asKeyValue()->format(Devise::USD_DOLLAR()));
use Jac\Enum\EnumJsonFormat;
echo json_decode(EnumJsonFormat::keyAndValueAsValues()->format(Devise::USD_DOLLAR()));
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.