Skip to content

rockancun/php_value_objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Value Objects

Table of Contents

Introduction

This repository contains value objects implementations for PHP basic types:

By definition these classes are immutable, will always be valid, don't have an identity (id) and describe a concept. In accordance with these ideas the value object classes have:

  • __construct($value) to initialize its value and a value() function to get it.
  • validation() function. Basic validations like string length validation, min/max validations or json and uuid format validations. When a validation fails throws an
  • InvalidValueObjectException.
  • abstract definition. You most describe your domain concepts.
  • and equals() and toString() functions implementations.

How to use

To use this repository you copy and paste the folder "Src" into your project. The reason it's simple: you have to control this code. This code belongs to your inner logic. I recommend you copy "Tests" folder into your project too just in case you need to modify the src code.

Remember to configure the namespace "Src" classes according to your project.

Examples

The Order class it's a Domain Model example where are used value objects. Take a look at Example/Order/Order.php class and its test class Tests/Example/OrderTest.php.

To watch each value object example take a look at Test/Src folder.

Testing

To test this repository you most install composer dependency management tool. If you have installed composer download the repository and execute next command at root folder

composer tests

About

Implementations of Value objects for PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages