PHPackages                             akandels/contain - 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. akandels/contain

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

akandels/contain
================

Zend Framework 2 library for the passing and handling of rich data entities.

151.3k6[5 issues](https://github.com/andrew-kandels/contain/issues)PHPCI failing

Since Apr 4Pushed 10y ago3 watchersCompare

[ Source](https://github.com/andrew-kandels/contain)[ Packagist](https://packagist.org/packages/akandels/contain)[ RSS](/packages/akandels-contain/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (3)Used By (0)

Contain PHP Entity Models
=========================

[](#contain-php-entity-models)

Compiled lightweight entity models for PHP. Type validation, data encapsulation, filtering and validation without the ORM.

Entity Models
-------------

[](#entity-models)

An entity model is a container for one or more pieces of data that describe something in your application. For example, a **User** model might be described as:

```
$user = array(
    'firstName' => 'Andrew',
    'lastName'  => 'Kandels',
);

```

Say you develop a service to create a user. There are two common ways to pass your model to that service.

Passing Arrays
--------------

[](#passing-arrays)

```
class Service {
    public function addUser(array $data) {
        ...
    }
}

$service->addUser($user);

```

The problem with this approach is that the **addUser** method is only guaranteed to receive an array of data. It could be passed an empty array, an array with typos for its data (firstName -&gt; first\_name) or possibly even non-string values for its first or last name indexes.

Placeholder Parameters
----------------------

[](#placeholder-parameters)

```
class Service {
    public function addUser($firstName, $lastName) {
        ...
    }
}

$service->addUser('Andrew', 'Kandels');

```

The first problem with this approach is when you start creating larger models the exact position of each parameter becomes difficult to remember. PHP also doesn't supported named parameters like other languages. Removing parameters later could also break backwards compatibility.

PHP can't do type-checking on scalar values like strings either, so the service is still responsible for validating that **$firstName** is a string and not an object or something unusable.

Meet Contain
============

[](#meet-contain)

Contain aims to solve this problem by creating lightweight entity models that you pass between services, controllers, views and just about anywhere else in your application:

```
class Service {
    public function addUser(User $user) {
        ...
    }
}

$user = new User(array(
    'firstName' => 'Andrew',
    'lastName' => 'Kandels'
));

$service->addUser($user);

```

Contain takes care of these things for you with the entity model:

- It encapsulates properties into a simple object (no isset() checks)
- It creates simple setters and getters
- It validates the types of properties
    - Strings are strings
    - Numbers are numbers
- It converts properties to expected types
    - "2014-01-01" -&gt; new DateTime(strtotime('2014-01-01'))

View the complete [Project Documentation](http://www.contain-php.org) at .

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/0daff19ce6f910c802faad4de62afb0454a2de89c4248414ccb43ac67b7913aa?d=identicon)[akandels](/maintainers/akandels)

---

Top Contributors

[![akandels](https://avatars.githubusercontent.com/u/142410?v=4)](https://github.com/akandels "akandels (124 commits)")[![Ocramius](https://avatars.githubusercontent.com/u/154256?v=4)](https://github.com/Ocramius "Ocramius (29 commits)")

### Embed Badge

![Health badge](/badges/akandels-contain/health.svg)

```
[![Health](https://phpackages.com/badges/akandels-contain/health.svg)](https://phpackages.com/packages/akandels-contain)
```

###  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)
