Valinor • PHP object mapper with strong type support¶
Valinor is a PHP library that helps to map any input into a strongly-typed value object structure.
The conversion can handle native PHP types as well as other well-known advanced type annotations like array shapes, generics and more.
There are many benefits of using value objects instead of plain arrays and scalar values in a modern codebase, among which:
- Data and behaviour encapsulation — locks an object's behaviour inside its class, preventing it from being scattered across the codebase.
- Data validation — guarantees the valid state of an object.
- Immutability — ensures the state of an object cannot be changed during runtime.
When mapping any source to an object structure, this library will ensure that all input values are properly converted to match the types of the nodes — class properties or method parameters. Any value that cannot be converted to the correct type will trigger an error and prevent the mapping from completing.
These checks guarantee that if the mapping succeeds, the object structure is perfectly valid, hence there is no need for further validation nor type conversion: the objects are ready to be used.
Moreover, static analysis can help during a refactoring of a codebase with tools like an IDE or Rector.