PHPackages                             compono-kit/maps - 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. compono-kit/maps

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

compono-kit/maps
================

Implementations of compono-kit/maps-interfaces

1.0.0(6mo ago)001proprietaryPHPPHP &gt;=8.0

Since Dec 7Pushed todayCompare

[ Source](https://github.com/compono-kit/maps)[ Packagist](https://packagist.org/packages/compono-kit/maps)[ RSS](/packages/compono-kit-maps/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (1)

ComponoKit / Maps
=================

[](#componokit--maps)

**Strongly typed map objects for PHP 8+**

This package provides a lightweight foundation for building *domain-driven*, *immutable*, and *type-safe* map objects in PHP.

Overview
--------

[](#overview)

This package provides full implementations for all interfaces defined in `compono-kit/maps-interfaces`.
For every scalar type, the package includes: - **Map interfaces** (typed and native) - **Mutable/Immutable extensions** - **Traits** implementing core behavior - **Abstract classes** for validation &amp; JSON processing - **Concrete map classes** such as `FloatMap`, `IntMap`, `BooleanMap`, etc.

All maps are: - Iterable - JSON serializable - Comparable (`equals()` &amp; `equalsValues()`) - Fully unit tested (100% coverage)

---

Requirements/Dependencies
-------------------------

[](#requirementsdependencies)

- PHP 8+
- compono-kit/types-interfaces
- compono-kit/maps-interfaces

---

🚀 Installation
--------------

[](#-installation)

```
composer require compono-kit/maps
```

---

Usage
-----

[](#usage)

### Immutables

[](#immutables)

```
$map = new FloatMap( [ 'test-key-1' => new FloatType( 1.1 ) ] );
$map = $map->set( 'test-key-2', new FloatType( 1.5 ) );
$map->get( 'test-key-2' ); //FloatType( 1.5 )
$newMap = $map->remove( 'test-key-2' );
$map->exists( 'test-key-2'); //true
$newMap->exists( 'test-key-2'); //false
```

### Mutables

[](#mutables)

```
$map = new FloatMap( [ 'test-key-1' => new FloatType( 1.1 ) ] );
$map['test-key-2'] = new FloatType( 1.5 );
$map['test-key-2']; //FloatType( 1.5 )
unset( $map['test-key-2'] );
isset( $map['test-key-2'] ); //false
```

---

Architecture
------------

[](#architecture)

### 1. Interfaces (Float example)

[](#1-interfaces-float-example)

#### RepresentsFloatMap

[](#representsfloatmap)

Provides: - typed values (`RepresentsFloat`) - native array conversion - iterators for values and key/value pairs

#### RepresentsImmutableFloatMap

[](#representsimmutablefloatmap)

- immutable variant\\
- `set()` &amp; `remove()` always return a **new instance**

#### RepresentsMutableFloatMap

[](#representsmutablefloatmap)

- mutable variant\\
- supports `ArrayAccess`

### Native Variants

[](#native-variants)

Identical structure, but values are native primitives (`float`, `int`, etc.)

### Mixed Type Variants

[](#mixed-type-variants)

These maps support values of type: - float - int - string - bool - array
or their `RepresentsType` wrappers.

---

2. Traits
---------

[](#2-traits)

Each map system is powered by three traits:

### RepresentingFloatMap

[](#representingfloatmap)

Contains the shared core implementation: - iteration logic - JSON serialization - `equals()` and `equalsValues()` - `keys()` and `values()` - `toNativeType()` and `toNativeArray()`

### RepresentingImmutableFloatMap

[](#representingimmutablefloatmap)

- uses `RepresentingFloatMap`
- all modifying operations (`set`, `remove`, `mergeMap`, `addMissing`) return a **new instance**

### RepresentingMutableFloatMap

[](#representingmutablefloatmap)

- directly mutates the internal array
- implements ArrayAccess

---

3. Abstract Classes
-------------------

[](#3-abstract-classes)

### AbstractFloatMap (immutable)

[](#abstractfloatmap-immutable)

Contains: - `RepresentingImmutableFloatMap` - validation of all values using `validate()` - `fromJson()` - abstract `isValueValid()`

### AbstractFloatMap (mutable)

[](#abstractfloatmap-mutable)

- same behavior as immutable version
- but uses `RepresentingMutableFloatMap`

### BooleanMap (special case)

[](#booleanmap-special-case)

Boolean maps **do not use an abstract class**
Validation only checks `instanceof RepresentsBoolean`.

---

4. Concrete Map Classes
-----------------------

[](#4-concrete-map-classes)

Example:

```
class FloatMap extends AbstractFloatMap {
    public static function isValueValid( RepresentsFloat $type ): bool {
        return true;
    }
}
```

All map types follow this pattern.

---

JSON Handling
-------------

[](#json-handling)

### fromJson()

[](#fromjson)

- accepts JSON key/value objects
- converts each value via `Builds*Types` factory
- ensures strict type validation (float, int, etc.)

The `fromJson()` static method allows you to create a fully typed Map instance directly from JSON.
It is particularly useful for:

- **Loading configuration data** from external sources
- **Deserializing complex nested structures**
- **Maintaining strict type safety** while working with native JSON values

`fromJson()` accepts a JSON string and a factory instance that implements the appropriate interface, such as:

- `BuildsFloatTypes`
- `BuildsIntegerTypes`
- `BuildsStringTypes`
- `BuildsBooleanTypes`
- `BuildsMixedTypes`

### Example

[](#example)

Consider the following example:

```
MixedTypeMap::fromJson(
    json_encode(
        [
            'test-key-1' => 1.1,
            'test-key-2' => 'test-value-2',
            'test-key-3' => 3,
            'test-key-4' => true,
            'test-key-5' => [
                'test-key-1' => 1.1,
                'test-key-2' => [ 'test-key-1' => 'test-value-2' ],
            ],
        ]
    ),
    new MixedTypeFactory()
);
```

becomes with corresponding factory:

```
new MixedTypeMap(
    [
        'test-key-1' => new FloatType( 1.1 ),
        'test-key-2' => new StringType( 'test-value-2' ),
        'test-key-3' => new IntegerType( 3 ),
        'test-key-4' => new BooleanType( true ),
        'test-key-5' => new MixedTypeMap(
            [
                'test-key-1' => new FloatType( 1.1 ),
                'test-key-2' => new MixedTypeMap(
                    [ 'test-key-1' => new StringType( 'test-value-2' ) ]
                ),
            ]
        ),
    ]
);
```

---

Testing
-------

[](#testing)

- The package provides **100% test coverage**
- All combinations (typed/native, mutable/immutable) are fully tested

---

Purpose
-------

[](#purpose)

This package serves as the **reference implementation** for all map interfaces from `compono-kit/maps-interfaces`

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance86

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

195d ago

### Community

Maintainers

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/compono-kit-maps/health.svg)

```
[![Health](https://phpackages.com/badges/compono-kit-maps/health.svg)](https://phpackages.com/packages/compono-kit-maps)
```

###  Alternatives

[elhebert/laravel-sri

Subresource Integrity hash generator for laravel

39241.9k](/packages/elhebert-laravel-sri)[mtdowling/burgomaster

Packages up PHP packages into zips and phars

2780.9k12](/packages/mtdowling-burgomaster)[francescomalatesta/laravel-circuit-breaker

A circuit breaker pattern implementation for the Laravel framework

2919.2k2](/packages/francescomalatesta-laravel-circuit-breaker)

PHPackages © 2026

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