DEPRECATED!
This package has been deprecated. Check out the following packages:, (*1)
- https://github.com/myclabs/php-enum
- https://github.com/BenSampo/laravel-enum
Constants
Constants is a helper package for validating and retrieving application-level global constants/enums., (*2)
, (*3)
Contents
Installation
composer require koomai/constants:^1.0
, (*4)
Usage
- 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
, (*5)
- When doing look-ups, e.g. via user input or as a parameter in a method, use the static
get()
method:
LeadStatus::get($status)
, (*6)
It will return $status
if it's a valid constant value or throw an InvalidConstantException
., (*7)
- If you don't want an exception thrown, you can check if the value exists first:
LeadStatus::has($status)
, (*8)
- To retrieve an array of all the constants in a class:
LeadStatus::all()
, (*9)
Changelog
Please see CHANGELOG for more information what has changed recently., (*10)
Testing
bash
$ composer test
, (*11)
Contributing
Please see CONTRIBUTING for details., (*12)
Credits
License
The MIT License (MIT). Please see License File for more information., (*13)