Articulate is a simple, powerful and highly flexible ORM for Laravel. It is designed to be a drop in replacement for Eloquent, and uses the Data Mapper pattern instead of Active Record.
The Data Mapper Pattern
The Data Mapper pattern is an architectural design that allows for the separation of data persistence and data representation. In essence, this means that the class that represents the data from your database or data-source, is not the same class that you use to actually interact with the database or data-source.
How does it work?
The easiest way to look at Articulate, is that it's an abstraction of Eloquent.
Take Eloquent models, they have three core responsibilities:
They contain the actual data retrieved from the database or data-source.
Through the use of
$castsand the relationship definitions, they define how the database or data-source maps to the representation.
They also contain the persistence layer, meaning that you can just use a model to talk directly to the database.
Articulate works by abstracting these three core responsibilities out to their own parts:
This is handled by an Articulate entity. It serves the sole purpose of representing the data, without any knowledge or care for where it came from, or where it is going.
This is handled by Articulate mappers. These tell Articulate how the data maps between the database or data-source, to the entity. It also defines the data types, the relationships, and other data required by the data-source.
This is handled by Articulate repositories. They follow the repository design pattern, and allow you to encapsulate all of the persistence layer specific logic. If you're using the Illuminate source, you can use the Laravel query builder.
Database OR Data-Source?
Through this documentation you will see reference to the
database or data-source. While Articulate
was initially designed to communicate with databases, it is built in such a way that it can use any data-source.
An example of this is the Respite package that allows developers to create fluent query builders to communicate with external APIs. Articulate has a source for this, that lets you have entity, mappers and repositories that represent data from an API, third party or your own.
You can read more about sources here.