Download the PHP package funeralzone/valueobjects without Composer

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

valueobjects

Build Status Version

Requirements

Requires PHP >= 7.1

Installation

Through Composer, obviously:

Extensions

This library only deals with fundamental values (scalars). We've also released an extension library which provides a starting point for more complex values.

Our approach

We've written up our philosophy to PHP value objects in our A better way of writing value objects in PHP article.

Single value object

If your VO encapsulates a single value, it's most likely a scalar. We've provided some traits to deal with scalars under:

src/Scalars

Let's say you have a domain value called 'User Email'. You'd create a class which implements the ValueObject interface:

You now need to implement the interface. But because an email can essentially be considered a special kind of string (in this simple case) the StringTrait helper trait can implement most of the interface for you:

In our case, a user's email has other domain logic that we can encapsulate in our VO. User emails have to be a valid email:

You can see an example of how to implement single value objects in the examples directory.

Enums

Enums can be defined easily through use of the EnumTrait. Then, the enum values are simply listed as constants on the class.

When dealing with value object serialisation, the constant names are used. They are case-sensitive. So:

In code, the trait utilises magic methods to create objects based on constant name like so:

If your IDE supports code completion and you'd like to use named methods to create enums you can add the following PHPDoc block to your enum class:

Composite value objects

A composite value object is a more complex value which is made from other values.

A Location is made up of two VOs (latitude, longitude). We've provided a CompositeTrait to easily implement most of the ValueObject interface automatically. It handles toNative serialistation by using reflection to return an array of all the class properties.

The CompositeTrait does not implement fromNative. We leave the construction of your object up to you.

You can see an example of how to implement composite objects in the examples directory.

Nulls, NonNulls and Nullables

This package allows you to deal with nullable value objects.

First create a type of value object.

Implement a non-null version of the value object.

Implement a null version of the value object.

Implement a nullable version of the value object.

This 'nullable' handles automatic creation of either a null or a non-null version of the interface based on the native input. For example:

The $phoneNumber above will automatically use the NullPhoneNumber implementation specified above.

Or:

The $phoneNumber above will automatically use the NonNullPhoneNumber implementation specified above.

Sets of value objects

A set of value objects should implement the Set interface. It's just an extension of the ValueObject interface with a few simple additions.

The other interfaces that the Set interface extends from (\IteratorAggregate, \ArrayAccess, \Countable) are for accessing the set object as though it was an array.

Non-null sets

The library provides a default implementation of the interface.

There are two abstract methods that need to be implemented.

If the set is set to unique, if duplicate values are added to the set (at instantiation or through the add method) the duplicates are filtered out.

Null and nullable sets

Just like standard value objects there are some constructs to help with creating nullable and null sets. See the Nulls, NonNulls and Nullables section for more information.

Usage of sets

Iteration, access and counting

add

Merges another set.

remove

Removes values from a set by using another set as reference values.

contains

Checks whether a set contains a particular value object.


All versions of valueobjects with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1 || ^8.0
beberlei/assert Version ^2.7 || ^3.1
chrisharrison/php-array-of Version ^1.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 funeralzone/valueobjects contains the following files

Loading the files please wait ....