Download the PHP package frankvanhest/value-objects without Composer

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

Value Objects

This package provides abstracts classes and interface to create Value Objects based on the four scalar type supported by PHP.

Installation

What is a Value Object

A Value Object is a wrapper for primitive types such as a string. It usually has specific domain knowledge, and it will make sure that the value is asserted accordingly to that domain knowledge. The characteristics of a Value Object are:

Whenever an instance of a Value Object is passed around your application, you can be sure that the value inside is what you expect it to be. For example, if you have a Value Object Email, you can be sure that the value is a correctly formatted string according to what an e-mail address should be.

Purpose

The purpose of this package is to provide a set of interfaces, abstracts and factories to get you started with value objects. It should not be considered as a silver bullet. You should always be use the best tools for your application. That being said, what could be reasons to use this package. Like stated before, if you are new to value objects this package will get you started and provide a learning opportunity to get a better understanding of value objects. Another reason is that you'll don't need to write the same basic code for your value objects, but again do not use it as a silver bullet. When you encounter a value object that cannot or cannot easily be created by using this package, do not try to do so. Write the complete implementation yourself. When you are more experienced with value objects and programming in general, this package is probably not for you. That is of course that is entirely up to you.

Installation

A most of the packages for PHP, the installation is done by using Composer.

Usage

This package only provided the means to create your own Value Objects. The four main primitives types string, integer, float and boolean are included. Each one has its own interface, abstract and factory (except for boolean) available. With each factory you can add a corresponding value modifier. For instance, you want to create a Value Object for Money. You can use the interface FloatValueObject and implement according to your own need. To simplify things, you can also use the abstract class FloatValueObject. See the following example.

As you can see, you only have to implement the assertion for your Value Object according to your domain knowledge. In this case the only constraint is that the value should be greater than zero.

We got convenient methods like fromFloat, toFloat and equals available.

What if I want to be able to initialize Money from a string. Just implement the interface StringValueObject and we get:

If you want to modify the value before the value object is created you can provide a value modified when using the factory to create the Money object.

As stated before when it comes to comparing two instances of Value Objects it only compares the value itself, not if the Value Objects are the same instance. To clarify this, look at the following examples based the Money class.

Contribution

Feel free to submit an issue of pull request. When it comes to a pull request I'm curious of how it improves this packages of which problem it may solve.

There are some requirements:

License

See LICENCE


All versions of value-objects with dependencies

PHP Build Version
Package Version
Requires php Version ~8.2.0 || ~8.3.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 frankvanhest/value-objects contains the following files

Loading the files please wait ....