2017 © Pedro Peláez
 

library contain

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

image

akandels/contain

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

  • Thursday, June 18, 2015
  • by akandels
  • Repository
  • 4 Watchers
  • 16 Stars
  • 663 Installations
  • PHP
  • 4 Dependents
  • 1 Suggesters
  • 7 Forks
  • 7 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

Contain PHP Entity Models

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

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:, (*2)

$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., (*3)

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 -> first_name) or possibly even non-string values for its first or last name indexes., (*4)

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., (*5)

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., (*6)

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:, (*7)

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:, (*8)

  • 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" -> new DateTime(strtotime('2014-01-01'))

View the complete Project Documentation at http://www.contain-php.org., (*9)

The Versions

18/06 2015

dev-master

9999999-dev http://contain-project.org

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

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.3.3

 

The Development Requires

by Andrew Kandels

zf2 entity hydrator contain

05/12 2014

dev-1.0.0.rc1

dev-1.0.0.rc1 http://contain-project.org

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

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.3.3

 

The Development Requires

by Andrew Kandels

zf2 entity hydrator contain

04/04 2013

dev-feature-property-spindle

dev-feature-property-spindle http://contain-project.org

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

  Sources   Download

BSD

The Requires

 

The Development Requires

by Andrew Kandels

zf2 entity hydrator contain