PHPackages                             damacisaac/zf2-osd-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. [Database &amp; ORM](/categories/database)
4. /
5. damacisaac/zf2-osd-entity

ActiveLibrary[Database &amp; ORM](/categories/database)

damacisaac/zf2-osd-entity
=========================

v0.1.3(11y ago)41051PHP

Since Feb 21Pushed 11y ago11 watchersCompare

[ Source](https://github.com/Osedea/zf2-osd-entity)[ Packagist](https://packagist.org/packages/damacisaac/zf2-osd-entity)[ RSS](/packages/damacisaac-zf2-osd-entity/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

zf2-osd-entity
==============

[](#zf2-osd-entity)

This module provides some default functions for Zend Framework 2 entities. There is a single class included in this module:

- OsdEntity/BasicEntity

### Version

[](#version)

0.1.1

### Installation and Setup

[](#installation-and-setup)

This package can be installed using composer. Add the following to your composer.json file:

```
{
    "require": {
        "damacisaac/zf2-osd-entity": "0.1.1"
    }
}
```

Run composer:

```
php composer.phar update
```

Extend BasicEntity with your entity:

```
use OsdEntity\BasicEntity;

class MyEntity extends BasicEntity { ... }
```

### Usage

[](#usage)

##### Fill

[](#fill)

An easy way to assign values to your entity. Accepts either an object or an array of key values and an optional list of attributes to exclude:

```
$myEntity->fill(
    array(
        'firstName' => 'Angus',
        'lastName' => 'MacIsaac',
        'excludedAttributeOne' => 'wontBeSet',
    ),
    array(
        'excludedAttributeOne',
    ));
```

##### Create

[](#create)

Creates an instance of the entity. Accepts either an object or an array of key values and an optional list of attributes to exclude. Uses `fill` internally:

```
MyEntity::create(
    array(
        'firstName' => 'Angus',
        'lastName' => 'MacIsaac',
        'excludedAttributeOne' => 'wontBeSet',
    ),
    array(
        'excludedAttributeOne',
    ));
```

##### Update

[](#update)

Updates the entity. Accepts either an object or an array of key values and an optional list of attributes to exclude. Uses `fill` internally:

```
$myEntity->update(
    array(
        'firstName' => 'Angus',
        'lastName' => 'MacIsaac',
        'excludedAttributeOne' => 'wontBeSet',
    ),
    array(
        'excludedAttributeOne',
    ));
```

##### toArray

[](#toarray)

Converts an entity to an array of key/value pairs. Also accepts an optional list of relations that should be converted to an array and added to the result. Relations can be nested.

To know which attributes to use when converting to an array, we must define them on our model:

```
protected $this->attributes = array(
    'firstName',
    'lastName'
);
```

In order to convert relationships to an array, we must also define them on the model, specifying the type of relation:

```
protected $this->relations = array(
    'friends' => self::RELATION_MANY,
    'profile' => self::RELATION_ONE
);
```

Consider a user entity that has many friends, and each friend has a job and a car. We could get a full nested array with the following:

```
$myUser->toArray(array('friends.job', 'friends.car'))
```

If we only wanted to join friends, we could use:

```
$myUser->toArray(array('friends'));
```

##### Customizing toArray

[](#customizing-toarray)

To override the return values of the toArray function, we can define a getter on the model. Consider a model that has date attribute that we would like to return as a formatted date string. We would add the following to our entity:

```
public function getDate()
{
    return $this->date()->format(\DateTime::W3C);
}
```

Of course, if we wanted a greater degree of customization, we can always override the `toArray()` method:

```
public function toArray(array $with = array())
{
    $result = parent::toArray($with);

    /* Add custom attributes */

    return $result;
}
```

### License

[](#license)

The MIT License (MIT)

Copyright (c) 2015 damacisaac

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

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

Total

4

Last Release

4085d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3926111d69f82fe808782610a232884e784e0f4fba36f77abc5ba50c44263fbe?d=identicon)[damacisaac](/maintainers/damacisaac)

---

Top Contributors

[![damacisaac](https://avatars.githubusercontent.com/u/3689921?v=4)](https://github.com/damacisaac "damacisaac (15 commits)")

### Embed Badge

![Health badge](/badges/damacisaac-zf2-osd-entity/health.svg)

```
[![Health](https://phpackages.com/badges/damacisaac-zf2-osd-entity/health.svg)](https://phpackages.com/packages/damacisaac-zf2-osd-entity)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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