florianwolters/component-core-immutable

The Immutable Object implementation pattern as a PHP component.

v0.2.0 2014-05-25 14:56 UTC

This package is not auto-updated.

Last update: 2024-04-13 11:40:07 UTC


README

FlorianWolters\Component\Core\Immutable is a simple-to-use PHP component that implements the Immutable Object implementation pattern.

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight Coverage Status

Latest Stable Version Total Downloads Monthly Downloads Daily Downloads Latest Unstable Version License

Stories in Ready Dependency Status Dependencies Status HHVM Status

Table of Contents (ToC)

Introduction

An object is considered immutable if its state cannot change after it is constructed. Maximum reliance on immutable objects is widely accepted as a sound strategy for creating simple, reliable code.

[...]

Programmers are often reluctant to employ immutable objects, because they worry about the cost of creating a new object as opposed to updating an object in place. The impact of object creation is often overestimated, and can be offset by some of the efficiencies associated with immutable objects. These include decreased overhead due to garbage collection, and the elimination of code needed to protect mutable objects from corruption.

-- Immutable Objects (The Java Tutorials)

Features

  • Artifacts tested with both static and dynamic test procedures:
  • Provides a Packagist package which can be installed using the dependency manager Composer. Click here for the package on Packagist.
  • Provides a complete Application Programming Interface (API) documentation generated with the documentation generator phpDocumentor. Click here for the API documentation.
  • Follows the following "standards" from the PHP Framework Interoperability Group (FIG). PSR stands for PHP Standards Recommendation:
    • PSR-0: Autoloading Standards

      Aims to provide a standard file, class and namespace convention to allow plug-and-play code.

    • PSR-1: Basic Coding Standard

      Aims to ensure a high level of technical interoperability between shared PHP code.

    • PSR-2: Coding Style Guide

      Provides a Coding Style Guide for projects looking to standardize their code.

    • PSR-4: Autoloader

      A more modern take on autoloading reflecting advances in the ecosystem.

  • Follows the Semantic Versioning (SemVer) specification version 2.0.0.

Requirements

Production

Development

Usage

The best documentation for FlorianWolters\Component\Core\Immutable are the unit tests, which are shipped in the package.

Installation

FlorianWolters\Component\Core\Immutable should be installed using the dependency manager Composer.

Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

The Composer installer can be downloaded with php.

php -r "readfile('https://getcomposer.org/installer');" | php

This will just check a few PHP settings and then download composer.phar to your working directory. This file is the Composer binary. It is a PHAR (PHP archive), which is an archive format for PHP which can be run on the command line, amongst other things.

To resolve and download dependencies, run the install command:

php composer.phar install

As A Dependency On Your Component

If you are creating a component that relies on FlorianWolters\Component\Core\Immutable, please make sure that you add FlorianWolters\Component\Core\Immutable to your component's composer.json file:

{
    "require": {
        "florianwolters/component-core-immutable": "0.2.*"
    }
}

Contributing

See CONTRIBUTING.md.

Credits

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://gnu.org/licenses/lgpl.txt.