PHPackages                             fsmdev/constants-collection - 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. fsmdev/constants-collection

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

fsmdev/constants-collection
===========================

Constants collection class

1.0.3(4y ago)0861MITPHPPHP ^7.1.0

Since Jan 26Pushed 4y agoCompare

[ Source](https://github.com/fsmdev/constants-collection)[ Packagist](https://packagist.org/packages/fsmdev/constants-collection)[ RSS](/packages/fsmdev-constants-collection/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)DependenciesVersions (5)Used By (1)

Constants Collection
====================

[](#constants-collection)

[English](https://github.com/fsmdev/constants-collection/blob/master/README.md) | [Русский](https://github.com/fsmdev/constants-collection/blob/master/README.RU.md)

A simple PHP class that allows you to create collections of constants, assign them properties, get arrays of properties and constants.

### Installation

[](#installation)

```
composer require fsmdev/constants-collection

```

### Usage

[](#usage)

#### Constants collection

[](#constants-collection-1)

Inherit your class from **Fsmdev\\ConstantsCollection\\ConstantsCollection** and define constants.

```
use Fsmdev\ConstantsCollection\ConstantsCollection;

class PostStatus extends ConstantsCollection
{
    const EDITED = 1;
    const PUBLISHED = 2;
    const DELETED = 3;
}
```

Examples:

```
$post = new Post();
$post->status = PostStatus::PUBLISHED;
```

```
class Post
{
    public function isPublished()
    {
        return $this->status == PostStatus::PUBLISHED;
    }
}
```

To get an array of constants use the method **valuesArray**

```
valuesArray () : array

```

#### Properties

[](#properties)

Named properties can be set for each constant. To do this, it is necessary to define a function in the class that is built according to the mask: **properties + PropertyName (camel case)**. The method must return an array whose keys are the values of the constants, and the values are the values of the properties.

```
# class PostStatus

protected static function propertiesName()
{
    return [
        self::EDITED => 'Edited',
        self::PUBLISHED => 'Published',
        self::DELETED => 'Deleted',
    ];
}

protected static function propertiesIndicatorClass()
{
    return [
        self::EDITED => 'text-warning',
        self::PUBLISHED => 'text-success',
        self::DELETED => 'text-danger',
    ];
}
```

Properties can be obtained using the static method **property**

```
property ( mixed $value [, string $property = 'name' ] ) : mixed

```

Example (Blade):

```
Status:

    {{ PostStatus::property($post->status) }}

```

You can get an array of properties using the static method **propertiesArray**

```
propertiesArray ( [ string $property = 'name' ] ) : array

```

#### Getting value by property

[](#getting-value-by-property)

```
value ( mixed $value [, string $property = 'name' ] ) : mixed

```

```
$status = PostStatus::value('Edited');
```

### Packagist.org

[](#packagistorg)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

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 ~289 days

Total

4

Last Release

1795d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b3f0b661b62e3ca4f33d78685ad68d7fca9b93061653df5be63cb06d62ed7bf?d=identicon)[fsmdev](/maintainers/fsmdev)

---

Top Contributors

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

---

Tags

constants

### Embed Badge

![Health badge](/badges/fsmdev-constants-collection/health.svg)

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

###  Alternatives

[rexlabs/enum

Enumeration (enum) implementation for PHP

48482.2k2](/packages/rexlabs-enum)[php-stubs/wordpress-globals

Global variables and global constants from WordPress core.

13799.0k17](/packages/php-stubs-wordpress-globals)

PHPackages © 2026

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