Download the PHP package phpgears/immutability without Composer

On this page you can find all versions of the php package phpgears/immutability. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package immutability

PHP version Latest Version License

Build Status Style Check Code Quality Code Coverage

Total Downloads Monthly Downloads

Object immutability guard for PHP

Truly object immutability in PHP is an impossible task by the nature of the language itself, carefully checking and protecting properties and methods visibility is the closest we can get at this moment in time

Crafting an object to make it as immutable as can be requires expertise, dedication and focus so no mutating mechanism slips through developer's hands into the object, that is the reason behind this library, provide a way to help with the tedious task of ensuring object immutability

Installation

Composer

Usage

Require composer autoload file

Gears\Immutability\ImmutabilityBehaviour trait enforces you to avoid public properties and mutable methods in your class by calling assertImmutable method on object construction, __wakeup method and unserialize methods if Serializable interface is implemented

This mentioned behaviour let alone would run your objects completely useless, you must provide an implementation of the abstract method getAllowedInterfaces, returning a list of interfaces whose public methods will be allowed in your class. Although you can also provide class names, as it can prove useful in some special cases, it is highly discouraged and should be used sparsely

Few PHP magic methods are allowed to be defined as public, namely __construct, __destruct, __get, __isset, __sleep, __wakeup, __serialize, __unserialize, __toString, __set_state, __clone, __debugInfo

As a general rule, your immutable classes should be declared final. In case you really need inheritance, at least your implementation of getAllowedInterfaces method has to be declared final for every instantiable class

Although not mandatory it is advised to make your constructors protected and force developers to create static named constructors

From now on you can focus on those methods defined in your interfaces and make sure they do not mutate your object, with the confidence no other developer would mutate your object by accident or intentionally

Example

If you want to have a look at a working example implementations of immutable objects have a look at phpgears/identity, phpgears/dto or phpgears/cqrs

Contributing

Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before.

See file CONTRIBUTING.md

License

See file LICENSE included with the source code for a copy of the license terms.


All versions of immutability with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phpgears/immutability contains the following files

Loading the files please wait ....