Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/teodoroleckie/value-object

⚡ Library to implement value-object / nullable-value-object in PHP
https://github.com/teodoroleckie/value-object

nullable-value-object nullable-valueobject php php-8 php8 value-object valueobject

Last synced: about 1 month ago
JSON representation

⚡ Library to implement value-object / nullable-value-object in PHP

Awesome Lists containing this project

README

        

# Library to implement value-object / nullable-value-object in PHP

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/teodoroleckie/value-object/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/value-object/?branch=main)
[![Build Status](https://scrutinizer-ci.com/g/teodoroleckie/value-object/badges/build.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/value-object/build-status/main)
[![Total Downloads](https://img.shields.io/packagist/dt/tleckie/value-object.svg?style=flat-square)](https://packagist.org/packages/tleckie/value-object)
[![Code Intelligence Status](https://scrutinizer-ci.com/g/teodoroleckie/value-object/badges/code-intelligence.svg?b=main)](https://scrutinizer-ci.com/code-intelligence)

### Create your own value-object type:
You should only extend from the ValueObject class
```php
equals($mario); // true

$john->equals($raquel); // false

$john->equals(new FirstName('Mario')); // false

$raquel->value(); // "34"
```

### Force primitive type:
Override value() method to indicate the return primitive type.
```php
value(); // int 34

$mario->equals($raquel); // true

(string)$mario; // string "34"

```

### Nullable value-object
If your object can contain null value you can extend of NullableValueObject class

```php