PHPackages                             belca/support-constants - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. belca/support-constants

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

belca/support-constants
=======================

Helper PHP classes for working with constants and enumerations.

v1.0.2(6y ago)011MITPHPCI failing

Since Mar 1Pushed 6y ago1 watchersCompare

[ Source](https://github.com/belcacomponents/support-constants)[ Packagist](https://packagist.org/packages/belca/support-constants)[ RSS](/packages/belca-support-constants/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Helpers for constants and enumerations
======================================

[](#helpers-for-constants-and-enumerations)

> The documentation is actual for version 1.0.

Supporting classes for constants of PHP.

Named constants and enumerations are used for immutable values. The package classes contain functions for getting a list of constants and their values without thrown exceptions of PHP.

```
use Belca\Support\AbstractEnum;

class MyConstants extends AbstractEnum
{
    const DEFAULT = self::USER;

    const USER = 'user';
    const ADMIN = 'administrator';
    const CLIENT = 'client';
}

// ...

$constants = MyConstants::list();

// Output $constants: [
//    'USER' => 'user',
//    'ADMIN' => 'superuser',
//    'CLIENT' => 'client',
// ]

$default = MyConstants::getDefault(); // only using AbstractEnum
// or
$default = MyConstants::DEFAULT;

// Output $default: 'user'
```

Introduction
------------

[](#introduction)

Install the package using Composer or manually.

```
composer require belca/support-constants:1.*
```

Use one of the classes.

```
use Belca\Support\AbstractConstants;
// or
use Belca\Support\AbstractEnum;
```

Use their features!

[AbstractConstants](#abstract-constants) [AbstractEnum](#abstract-enum)

 AbstractConstants
----------------------------------------------------------------

[](#-abstractconstants)

AbstractConstants is the abstract class for implementing a list of named constants and getting their values.

FunctionDescription`getConstants()`Returns all constants of the class.`list()`The alias of the `getConstants()` function.`getLastConstants()`Returns an array of constants defined in the called class without constants of parrent classes.`getParentConstants()`Returns all constants of parent classes.`getConst($name)`*$name* - a name of constant.

 Returns a value of a given constant if it exists, else returns *null*.
 This is a safe method for calling constants, in otherwise when you calls undefined constants you will catch an error.`isDefined($name)`*$name* - a name of constant.

 Checks whether a given constant exists and is defined in the class.See the example below. Down there is implementing of the base (first) class of constants.

**Example #1 Implementing the first (parent) class with constants**

```
namespace AnyoneVendor\MyPackage\Enums;

use Belca\Support\AbstractConstants;

class Roles extends AbstractConstants
{
    const USER = 'user';
    const SUPERUSER = 'superuser';
    const CLIENT = 'client';
    const MODERATOR = 'moderator';
    const SUPERMODERATOR = 'superuser';
}
```

After implementing the class you can get a list of constants from this class. Use `list()` or `getConstants()` to do this.

**Example #2 Getting all constants from the parent class**

```
$constants = Roles::list();
// or
$constants = Roles::getConstants();

// Output $constants: [
//    'USER' => 'user',
//    'SUPERUSER' => 'superuser',
//    'CLIENT' => 'client',
//    'MODERATOR' => 'moderator',
//    'SUPERMODERATOR' => 'superuser',
// ]
```

If you want to get one value then use the `getConst()` function. The function gets a case-sensitive name of constant. By convention, constant identifiers are always uppercase.

**Example #3 Getting values of constants of the class**

```
$user = Roles::getConst('USER'); // Output: 'user'
$superuser = Roles::getConst('SUPERUSER'); // Output: 'superuser'
$root = Roles::getConst('ROOT'); // Output: null, because it is not defined
$user = Roles::getConst('user'); // Output: null, because the constant was defined in uppercase
```

The `Roles` class contains the constants for us. You will probably want some other constants. Extend the class to solve the problem. This need exists when you uses third-party classes.

**Example #4 Extending the parent class**

```
namespace App\Enums;

use AnyoneVendor\MyPackage\Enums\Roles as BaseRoles;

class Roles extends BaseRoles
{
    // Defines new constants
    const VIEWER = 'viewer';
    const CHECKER = 'checker';
    const TESTER = 'tester';

    // Replaces old values of constants
    const SUPERUSER = 'root';
    const SUPERMODERATOR = 'supermoderator';
}
```

See the examples of the new child class.

**Example #5 Checking of existing constants**

```
Roles::isDefined('SUPERUSER'); // true
Roles::isDefined('ROOT'); // false
```

**Example #6 Getting new constants**

```
$constants = Roles::list();

// Output $constants: [
//    'USER' => 'user',
//    'SUPERUSER' => 'root',
//    'CLIENT' => 'client',
//    'MODERATOR' => 'moderator',
//    'SUPERMODERATOR' => 'superuser',
//    'VIEWER' => 'viewer',
//    'CHECKER' => 'checker',
// ]
```

**Example #6 Getting a value of the replaced constant**

```
$superuser = Roles::getConst('SUPERUSER'); // 'root'
```

You can get some constant using the standard PHP syntax. If you try to take a undefined constant then you will catch an error. If you are not sure about an existing constant then use the `getConst()` function and you will not catch an error.

**Example 7 Getting values using the standard PHP function**

```
$superuser = Roles::SUPERUSER; // 'root'
$root = Roles::ROOT; // Error: Undefined class constant 'ROOT'
```

 AbstractEnum
------------------------------------------------------

[](#-abstractenum)

AbstractEnum is the abstract class for implementing a list of named constants and getting their values. It was extended from AbstractConstants.

In contract to the `Belca\Support\AbstractConstants` class, the `Belca\Support\AbstractEnum` uses a constant with default value.

FunctionDescription`getConstants()`Returns all constants of the class.`list()`The alias of the `getConstants()` function.`getLastConstants()`Returns an array of constants defined in the called class without constants of parrent classes.`getParentConstants()`Returns all constants of parent classes.`getConst($name)`*$name* - a name of constant.

 Returns a value of a given constant if it exists, else returns *null*.
 This is a safe method for calling constants, in otherwise when you calls undefined constants you will catch an error.`isDefined($name)`*$name* - a name of constant.

 Checks whether a given constant exists and is defined in the class.`getDefault()`Returns the last defined default constant.> The function that return a list of contains do not return the DEFAULT constant.

This class have a new function: the `getDefault()` function. The other functions are the same.

**Example #8 Implementing the first (parent) class with a default value**

```
namespace AnyoneVendor\MyPackage\Enums;

use Belca\Support\AbstractEnum;

class Roles extends AbstractEnum
{
    const DEFAULT = self::USER;

    const USER = 'user';
    const SUPERUSER = 'root';
    const CLIENT = 'client';
}
```

Get the default value using the `getDefault()` function.

**Example #9 Getting the default value**

```
$default = Roles::getDefault(); // 'user'
```

Also you can get the default value using the PHP syntax.

**Example #10 Getting the default value using the PHP syntax**

```
$default = Roles::DEFAULT; // 'user'
```

You can redefine the default constant by means of extending class.

**Example #11 Redefining the default constant**

```
namespace App\Enums;

use AnyoneVendor\MyPackage\Enums\Roles as BaseRoles;

class Roles extends BaseRoles
{
    const DEFAULT = self::UNREGISTRED;

    const UNREGISTERED = 'unregistered';
}
```

License
-------

[](#license)

The package and other [Belca components](https://github.com/belcacomponents) are open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

3

Last Release

2256d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1146772?v=4)[dios](/maintainers/dios)[@Dios](https://github.com/Dios)

---

Top Contributors

[![dmitrach](https://avatars.githubusercontent.com/u/19969187?v=4)](https://github.com/dmitrach "dmitrach (11 commits)")

---

Tags

laravelhelperenumenumerationconstantssupportabstractconstbelca

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/belca-support-constants/health.svg)

```
[![Health](https://phpackages.com/badges/belca-support-constants/health.svg)](https://phpackages.com/packages/belca-support-constants)
```

###  Alternatives

[cartalyst/support

Support helpers.

762.8M14](/packages/cartalyst-support)[rexlabs/enum

Enumeration (enum) implementation for PHP

48482.2k2](/packages/rexlabs-enum)[lazerg/laravel-enum-pro

A powerful PHP enum extension with collection support, random selection, and magic static calls

4319.0k](/packages/lazerg-laravel-enum-pro)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
