This package has been deprecated. Check out the following packages:
- https://github.com/myclabs/php-enum
- https://github.com/BenSampo/laravel-enum
Constants is a helper package for validating and retrieving application-level global constants/enums.
composer require koomai/constants:^1.0
- Simply extend your class from
Koomai\Constants\Constants
and define your constants. E.g.,
<?php
namespace App\Constants;
use Koomai\Constants\Constants as AbstractConstants;
class LeadStatus extends AbstractConstants
{
const ATTEMPTED = 'attempted';
const CONTACTED = 'contacted';
const OPPORTUNITY = 'opportunity';
const DISQUALIFIED = 'disqualified';
}
- For internal use in your code, you just reference the constant name directly as usual:
LeadStatus::CONTACTED
- When doing look-ups, e.g. via user input or as a parameter in a method, use the static
get()
method:
LeadStatus::get($status)
It will return $status
if it's a valid constant value or throw an InvalidConstantException
.
- If you don't want an exception thrown, you can check if the value exists first:
LeadStatus::has($status)
- To retrieve an array of all the constants in a class:
LeadStatus::all()
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.