Encapsulation
v2.0
v2.0
  • dustin/encapsulation
  • Getting started
    • Basics
      • Container
    • Advanced
      • Object maps
      • Immutable encapsulations
    • Objects with properties
    • Intersection calculation
Powered by GitBook
On this page
  • Installation
  • Introduction
  • ArrayEncapsulation
  • PropertyEncapsulation
  • Container

dustin/encapsulation

A simple way to accommodate, exchange and structorize data with objects

NextBasics

Last updated 1 year ago

dustin/encapsulation is a simple but powerful utility for working with objects and arrays. The main idea is to simplify data handling, structorizing, data exchange between objects, data accomodation and data extraction from objects.

Developing your data objects with encapsulations brings a lot of advantages:

  • Initialize an object with data in the constructor

  • Flexible setting and getting values with field name as string

  • Access multiple field values at once

  • Add items to arrays

  • List all fields of an object

  • Convert an object into an array

  • Using an object like an array

  • Iterate over all fields of an object

  • Calculate intersections and differences between objects

  • ...

Installation

dustin/encapsulation is freely available on packagist. If you do not know how to use composer read the guide at here:

Run the following command within your project directory to add the package as composer dependency. The command assumes you have composer installed globally.

composer require dustin/encapsulation

Now composer should have added the newest version of dustin/encapsulation to your composer.json file like this:

...

"require": {
    ...
    "dustin/encapsulation": "^2.0"
    ...
}
...

Introduction

An encapsulation is an object which holds key-based data. They consist of three different types which are able to exchange data among each other or to the outside.

ArrayEncapsulation

They hold their data in an array. You are able to deal with data in an object without declaring properties.

PropertyEncapsulation

Inheriting from PropertyEncapsulation allows creating normal objects and their properties with the ability to harness all advantages of an encapsulation.

Container

A container holds a list of elements and brings a lot of functions to access and modify these elements. A container does not take care of keys.

Watch the changelog here:

Or get started with using encapsulations:

Introduction - Composer
Logo
Changelog