koomai/constants

This package is abandoned and no longer maintained. No replacement package was suggested.

An easy and clean way to manage application-level global constants

v1.2.0 2019-03-17 03:12 UTC

This package is auto-updated.

Last update: 2020-02-13 02:48:11 UTC


README

This package has been deprecated. Check out the following packages:

Constants

Constants is a helper package for validating and retrieving application-level global constants/enums.

Build Status StyleCI

Contents

Installation

composer require koomai/constants:^1.0

Usage

  1. 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';
}

  1. For internal use in your code, you just reference the constant name directly as usual:

LeadStatus::CONTACTED

  1. 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.

  1. If you don't want an exception thrown, you can check if the value exists first:

LeadStatus::has($status)

  1. To retrieve an array of all the constants in a class:

LeadStatus::all()

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.