PHPackages                             gnbit/alabra-entity - 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. gnbit/alabra-entity

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

gnbit/alabra-entity
===================

entity class

0.1(4y ago)02.6kMITPHPPHP ^7 || ^8

Since Dec 30Pushed 2y ago2 watchersCompare

[ Source](https://github.com/gnbitdev/alabra-entity)[ Packagist](https://packagist.org/packages/gnbit/alabra-entity)[ Docs](https://github.com/gnbit/alabra-entity)[ RSS](/packages/gnbit-alabra-entity/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Alabra Entity
=============

[](#alabra-entity)

**Alabra Entity** is a PHP package that provides a flexible and extensible way to work with object collections. It includes an `EntityCollection` class that implements common array interfaces such as `ArrayAccess`, `IteratorAggregate`, and `Countable`. This allows for easy manipulation and traversal of collections of objects.

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

[](#installation)

You can install this package via [Composer](https://getcomposer.org/):

```
composer require alabra/alabra-entity
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Creating Entity

```
class UserProfile implements EntityInterface
{
    use EntityTrait;

    private string $username;
    private PersonalInfo $personalInfo;

    public function __construct(
        private string $firstName,
        private string $lastName,
        private string $email,
        private int $age,
        private bool $isSubscribed
    )
    {

    }

    public function setUsername(string $username): void
    {
        $this->username = $username;
    }

    public function setPersonalInfo(PersonalInfo $personalInfo): void
    {
        $this->personalInfo = $personalInfo;
    }
}
```

```
        $personalInfo = new PersonalInfo('123 Main St', '555-1234');
        $this->userProfile = new UserProfile('Jhon', 'Smith', 'test@example.com', 40, true);
        $this->userProfile->setUsername('other');
        $this->userProfile->setPersonalInfo($personalInfo);

        //Methods
        $this->userProfile->toArray();
        $this->userProfile->toJson();
        $this->userProfile->getIterator();
```

### Create Collections

[](#create-collections)

```
use Alabra\Entity\EntityCollection;

// Create an instance of EntityCollection
$collection = new EntityCollection();

// Add objects to the collection
$object1 = new YourEntityClass();
$object2 = new YourEntityClass();

$collection[] = $object1;
$collection[] = $object2;

// Access objects by key or iterate through the collection
foreach ($collection as $key => $object) {
    // Do something with each object
}

// Check if an offset exists
if (isset($collection['some_key'])) {
    // Object with key 'some_key' exists
}

// Remove an object by key
unset($collection['some_key']);

// Get the number of objects in the collection
$count = count($collection);
```

### Advanced Usage

[](#advanced-usage)

#### Using a Key Property

[](#using-a-key-property)

If your objects have a specific property that should be used as the key in the collection, you can set it using the setKeyPropertyName method:

```
use Alabra\Entity\EntityCollection;

// Create an instance of EntityCollection
$collection = new EntityCollection();

// Set the key property name
$collection->setKeyPropertyName('id');

// Add objects to the collection
$object1 = new YourEntityClass('A', 'B', 1, true, 1.5, 'key1');
$object2 = new YourEntityClass('C', 'D', 2, false, 2.5, 'key2');

$collection[] = $object1;
$collection[] = $object2;

// Access objects by their key property
$objectByKey = $collection['key1']; // Returns $object1
```

#### Merging Collections

[](#merging-collections)

You can merge two collections, either using a key property or by a simple merge:

```
use Alabra\Entity\EntityCollection;

// Create two instances of EntityCollection
$collection1 = new EntityCollection();
$collection2 = new EntityCollection();

// Merge collections
$collection1->merge($collection2->toArray());
```

#### Transforming Collections to Arrays

[](#transforming-collections-to-arrays)

You can easily convert the collection and its objects to an associative array:

```
use Alabra\Entity\EntityCollection;

// Create an instance of EntityCollection
$collection = new EntityCollection();

// Add objects to the collection
$object1 = new YourEntityClass('A', 'B', 1, true, 1.5);
$object2 = new YourEntityClass('C', 'D', 2, false, 2.5);

$collection[] = $object1;
$collection[] = $object2;

// Convert the collection to an array
$arrayRepresentation = $collection->toArray();
```

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% 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

Unknown

Total

1

Last Release

1646d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/523f5103721721e8b4108959e2362c2096c9f7e6aa6c0fae8019f70265ff2353?d=identicon)[benjamin741](/maintainers/benjamin741)

---

Top Contributors

[![benjamingb](https://avatars.githubusercontent.com/u/249177?v=4)](https://github.com/benjamingb "benjamingb (6 commits)")[![gnbitdev](https://avatars.githubusercontent.com/u/69834726?v=4)](https://github.com/gnbitdev "gnbitdev (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gnbit-alabra-entity/health.svg)

```
[![Health](https://phpackages.com/badges/gnbit-alabra-entity/health.svg)](https://phpackages.com/packages/gnbit-alabra-entity)
```

###  Alternatives

[andegna/calender

If you ever want to convert Ethiopian Calender to any other calender system (like the Gregorian Calender) this is the right package for you. And by the way it also support Amharic date formatting and much much more.

7418.9k](/packages/andegna-calender)

PHPackages © 2026

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