Skip to content
Greg Bowler edited this page Jun 20, 2023 · 5 revisions

Throughout PHP.Gt repositories, a consistent way to transfer object data was required that could take advantage of immutable type safety. This library was introduced to allow individual repositories to depend on and extend the DataObject class.

Data Transfer Objects (DTOs) are a design pattern that facilitates transfer of data between different layers of an application. This library introduces the DataObject class which can be built from an existing associative array or standard object, using the DataObjectBuilder class.

A DataObject has the following features:

  • It is immutable, meaning that code can't modify the data it represents
  • It provides type-safe getters to the contained data
  • It can be nested within other DataObjects
  • It can be converted to and from associative arrays and standard objects

The best example of how this library fits in with other PHP.Gt repositories is within PHP.Gt/Fetch: a remote JSON API can be fetched, and the returned object is an extension of DataObject, allowing for type safe JSON manipulation.


Take a look at some simple examples.

Clone this wiki locally