-
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
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
DataObject
s - 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.
PHP.Gt/DataObject is a separately maintained component of PHP.Gt/WebEngine.