PHPackages                             arodygin/php-dictionary - 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. arodygin/php-dictionary

Abandoned → [webinarium/php-dictionary](/?search=webinarium%2Fphp-dictionary)Library[Utility &amp; Helpers](/categories/utility)

arodygin/php-dictionary
=======================

Static dictionary implementation for PHP

1.2.1(4y ago)10550MITPHPPHP &gt;=7.4CI failing

Since Apr 19Pushed 4y ago1 watchersCompare

[ Source](https://github.com/webinarium/php-dictionary)[ Packagist](https://packagist.org/packages/arodygin/php-dictionary)[ Docs](https://github.com/webinarium/php-dictionary)[ RSS](/packages/arodygin-php-dictionary/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (2)Versions (11)Used By (0)

[![PHP](https://camo.githubusercontent.com/b43c9d6cd8939c4868f963284928566c4c35dd2da0725c027f95a3d62f2f0329/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d626c75652e737667)](https://secure.php.net/migration74)[![Latest Stable Version](https://camo.githubusercontent.com/15c07e818e71809b1d476b3d1837030befc0b3c74119d242a45dd183d0a64dbc/68747470733a2f2f706f7365722e707567782e6f72672f776562696e617269756d2f7068702d64696374696f6e6172792f762f737461626c65)](https://packagist.org/packages/webinarium/php-dictionary)[![Build Status](https://camo.githubusercontent.com/a9a84e830b5c3b55825cb8a250d6af6bd9a81a6e70409000b5476697406cf1df/68747470733a2f2f7472617669732d63692e636f6d2f776562696e617269756d2f7068702d64696374696f6e6172792e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/webinarium/php-dictionary)[![Code Coverage](https://camo.githubusercontent.com/8cedb0f12321352b7075f0a736bbc2a64077208c1b072384f2fb90bffd8cd610/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776562696e617269756d2f7068702d64696374696f6e6172792f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/webinarium/php-dictionary/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f66a9af4fda5ea9c7387979a561d86868b987656598630c592b228d4def3160f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776562696e617269756d2f7068702d64696374696f6e6172792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/webinarium/php-dictionary/?branch=master)

Static dictionary implementation for PHP
========================================

[](#static-dictionary-implementation-for-php)

Requirements
------------

[](#requirements)

PHP needs to be a minimum version of PHP 7.4.

Installation
------------

[](#installation)

The recommended way to install is via Composer:

```
composer require webinarium/php-dictionary
```

Usage
-----

[](#usage)

To create custom dictionary you have to extend `StaticDictionary` class and override the `$dictionary` static array. After that you can use [`StaticDictionaryInterface`](https://github.com/webinarium/php-dictionary/blob/master/src/StaticDictionaryInterface.php) to work with your dictionary.

Example dictionary:

```
namespace Dictionary;

class Color extends StaticDictionary
{
    public const BLACK   = 'Black';
    public const BLUE    = 'Blue';
    public const GREEN   = 'Green';
    public const CYAN    = 'Cyan';
    public const RED     = 'Red';
    public const MAGENTA = 'Magenta';
    public const YELLOW  = 'Yellow';
    public const WHITE   = 'White';

    protected static array $dictionary = [
        self::BLACK   => '#000000',
        self::BLUE    => '#0000FF',
        self::GREEN   => '#00FF00',
        self::CYAN    => '#00FFFF',
        self::RED     => '#FF0000',
        self::MAGENTA => '#FF00FF',
        self::YELLOW  => '#FFFF00',
        self::WHITE   => '#FFFFFF',
    ];
}
```

Input sanitizing:

```
public function setColor($color)
{
    if (Dictionary\Color::has($color)) {
        $this->color = $color;
    }
}
```

Symfony validation:

```
use Symfony\Component\Validator\Constraints;

class Settings
{
    /**
     * @Constraints\NotNull()
     * @Constraints\Choice(callback = {"Dictionary\Color", "keys"})
     */
    public $color;
}
```

Symfony form:

```
class ColorType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('color', ChoiceType::class, [
            'label'   => 'color',
            'choices' => array_flip(Dictionary\Color::all()),
        ]);
    }
}
```

Please note, if you try to get a value from your dictionary using non-existing key, you will get `NULL` without any failures or warnings. Sometimes it's useful to have a default fallback value to be returned instead of `NULL`. This can be done by defining a `FALLBACK` constant in your dictionary class:

```
class Shell extends StaticDictionary
{
    public const FALLBACK = self::UNITY;

    public const XFCE  = 1;
    public const KDE   = 2;
    public const GNOME = 3;
    public const LXDE  = 4;
    public const UNITY = 5;
    public const MATE  = 6;

    protected static array $dictionary = [
        self::UNITY => 'Unity',
        self::GNOME => 'Gnome',
        self::KDE   => 'KDE',
        self::LXDE  => 'LXDE',
        self::XFCE  => 'Xfce',
        self::MATE  => 'MATE',
    ];
}

// This returns 'Gnome'
Shell::get(Shell::GNOME);

// This returns 'Unity'
Shell::get(Color::BLACK);
```

If your dictionary should be built in run-time, you may skip the `$dictionary` static array and overload `dictionary()` static function instead of that:

```
class Timezone extends StaticDictionary
{
    const FALLBACK = 'UTC';

    protected static function dictionary(): array
    {
        return timezone_identifiers_list();
    }
}
```

Development
-----------

[](#development)

```
./bin/php-cs-fixer fix
XDEBUG_MODE=coverage ./bin/phpunit --coverage-text
```

###  Health Score

32

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

Established project with proven stability

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

Recently: every ~450 days

Total

10

Last Release

1725d ago

PHP version history (4 changes)1.0.0PHP &gt;=5.4.0

1.0.2PHP &gt;=5.4

1.1.2PHP &gt;=5.6

1.2.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/e875e09c96006b56b5aa9d3b9d33c6da38a77ea8df59d24667a852a5fd1102f9?d=identicon)[webinarium](/maintainers/webinarium)

---

Top Contributors

[![webinarium](https://avatars.githubusercontent.com/u/741349?v=4)](https://github.com/webinarium "webinarium (34 commits)")

---

Tags

dictionaryphpdictionary

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/arodygin-php-dictionary/health.svg)

```
[![Health](https://phpackages.com/badges/arodygin-php-dictionary/health.svg)](https://phpackages.com/packages/arodygin-php-dictionary)
```

###  Alternatives

[equip/structure

Simple, immutable data structures

40201.9k2](/packages/equip-structure)[fisharebest/ext-calendar

Implementation of the Arabic (Hijri), French, Gregorian, Jewish, Julian and Persian (Jalali) calendars. Also provides a replacement for the PHP ext/calendar extension.

31464.0k8](/packages/fisharebest-ext-calendar)[sinergi/dictionary

PHP Dictionary library

1513.8k2](/packages/sinergi-dictionary)[webinarium/php-dictionary

Static dictionary implementation for PHP

1018.9k](/packages/webinarium-php-dictionary)

PHPackages © 2026

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