Download the PHP package immutablephp/immutable without Composer

On this page you can find all versions of the php package immutablephp/immutable. 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 immutable

immutablephp/immutable

Provides truly immutable value objects and an immutable value bag, along with base Immutable and ValueObject classes for your own objects. It helps to prevent against the oversights described by the article Avoiding Quasi-Immutable Objects in PHP.

Overview

The base Immutable class protects against common oversights in PHP regarding immutables:

Further, the base ValueObject class with() method checks the types of all incoming values to make sure they are themselves immutable. It does so via the static methods on the Type class.

The Type class recognizes scalars and nulls as immutable. All other non-object values (such are resources and arrays) are rejected as mutable.

When it comes to objects, the Type class recognizes anything descended from Immutable as immutable, as well as DateTimeImmutable. To allow Type to recognize other immutable classes, call Type::register() with a variadic list of fully-qualified class names that you want to treat as immutable.

Making Your Own Immutable Value Objects

Note:

This package can only do so much to keep you from accidentally overlooking mutability. For example, The Immutable and ValueObject classes cannot prevent you from deliberately adding your own mutable behaviors. Likewise, it is not possible to prevent against using reflection to mutate an object from the outside.

To create your own immutable value object, extend ValueObject with your own properties.

Then add a with*() method to allow changing of those values on a clone of the object, using the protected with() method on the base ValueObject.

Finally, use that method in the constructor to initialize the properties, and call parent::__construct() to finish initialization.

Warning:

If you do not call parent::__construct() then the Value Object will not know that it has been initialized, and it will be possible to call the constructor multiple time to re-initialize the object.

Now you have an immutable Value Object.

You may find it useful to add validation; do so in your with*() methods, either directly or by calling a validation mechanism.

Provided Immutable Value Objects

This package provides several Value Objects, both as examples and for common usage.

CreditCard

Email

Ip

Isbn

Uri\HttpUri

Uuid

Immutable Bag

The Bag is for an arbitrary collection of immutable values, and can be useful for immutable representations of JSON data.


All versions of immutable with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
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 immutablephp/immutable contains the following files

Loading the files please wait ....