Download the PHP package beeyev/value-objects-php without Composer
On this page you can find all versions of the php package beeyev/value-objects-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beeyev/value-objects-php
More information about beeyev/value-objects-php
Files in beeyev/value-objects-php
Package value-objects-php
Short Description Immutable value objects for PHP, designed for Domain-Driven Design (DDD). Enhance your applications with expressive, reliable, and maintainable code.
License MIT
Homepage https://github.com/beeyev/value-objects-php
Informations about the package value-objects-php
ValueObjects PHP Package ๐ซ
โน๏ธ Introduction
This package provides a collection of immutable value objects that you can use in your PHP applications.
Value objects are a key concept in Domain-Driven Design (DDD).
They are simple objects whose equality is based on their value rather than their identity.
Using value objects can help you write more expressive, reliable, and maintainable code.
๐งพ Benefits of using value objects
- Immutability: Ensures objects remain consistent throughout their lifecycle.
- Expressiveness: Represents domain concepts naturally.
- Validation: Encapsulates validation logic, reducing errors.
- Reusability: Promotes DRY principles.
- Ease of Testing: Self-contained and simple to test.
๐ Why use value objects over primitives
- Validation: โ Guarantees valid data.
- Self-Documenting Code: Enhances readability.
- Encapsulation: Contains logic related to the value.
- Consistency: Ensures uniform handling of data.
- Ease of Refactoring: Centralizes changes to logic or validation rules.
๐ฆ Installation
Use Composer to install this package. Run the following command:
โถ๏ธ Usage
Here are examples of how to use the value objects provided by this package:
URL
UUID
IPv4 Address
IPv6 Address
Coordinates
Represents a geographic coordinate (latitude and longitude).
Json
Represents a JSON string.
Percentage
Represents a percentage integer value from 0 to 100.
RangeInteger
Represents a range of integer values.
Resolution
Represents resolution (width and height).
Semantic Version
Represents a semantic version number (SemVer).
Timestamp
Represents a unix timestamp.
Class string
Represents a PHP class string.
๐ Primitive Value Objects
Text
Represents a non-empty text string.
Boolean
Integer
Positive Integer
Represents a positive integer greater than zero. Useful for storing values that must always be positive. For example, a database row ID.
Non-Negative Integer
Represents a non-negative integer, greater than or equal to zero.
Double (float)
Represents a double-precision floating-point number.
Common functionality
Every value object has the following functionality:
๐ Creating your own value objects
It is possible to create your own value objects by extending the AbstractValueObject
class.
๐ Extending functionality
Feel free to extend the functionality of the value objects by creating your own classes that inherit from the provided value objects.
๐ Contributions
If you have suggestions for improvements or wish to create your own custom value object to be included as a built-in feature, please submit a Pull Request.
Additionally, bug reports and feature requests can be submitted via the GitHub Issue Tracker.
ยฉ License
The MIT License (MIT). Please see License File for more information.
If you love this project, please consider giving me a โญ