GitHub
php-datatypes
DDD building blocks for PHP: one tested Trait per attribute, plus immutable Str/int/float, Slug, Url, EmailAddress, Money and datetime Value Objects. Framework-free, no 3rd party dependency.
PHP Datatypes
PHP Datatypes builds your Value Objects, Entities and Aggregates from predefined, tested Traits - one per attribute - leaving the class definition free for the business logic that belongs to it.
Getters return Value Objects rather than primitives wherever possible, so a value carries its own validation and normalization instead of every caller remembering it. There is no 3rd party dependency beyond PHP itself, so these values work without a framework, an HTTP request or a template engine.
AbstractValueObject- the base a Value Object, Entity or Aggregate extends, giving it construction from an array, full serialization andtoArray()out of the box.- Entity Traits - one Trait per attribute (
HasPositiveIntegerIDTrait,HasActiveTrait,HasNameTrait, ...), each carrying the type hints and normalization for that attribute. - Scalar datatypes - immutable
Str, integer and float wrappers, with a fluent API that returns a new instance on every operation rather than mutating the value in place. - Web datatypes -
Slug,UrlandEmailAddress, each validating and normalising itself. - Datetime datatypes - date and time values, without pulling in a datetime library.
- Exception vocabulary - a typed exception per datatype under
Exceptions\Datatypes\*, so a rejected value says what it rejected and why.
Scope
This package holds datatypes: values that validate and normalise themselves, and that any PHP application can use without a framework, an HTTP request or a template engine. The "No 3rd party dependency" rule is a scope rule as much as a dependency rule.
Behaviour that renders, parses documents, or exists to serve a web page is not a datatype, and lives in hradigital/php-markup instead. php-markup depends on this package - never the other way round.
- PHP
- JavaScript
- Datatypes
- Makefile
- Primitives