Download the PHP package thesalegroup/restorm without Composer
On this page you can find all versions of the php package thesalegroup/restorm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package restorm
RESTORM
A REST ORM library for persisting data via an HTTP REST API. Inspired by Doctrine, RESTORM provides an entity manager to take care of persisting and loading your entities to and from a REST API.
Feature Overview
- :floppy_disk: Load and save entities from a RESTful API
- :busts_in_silhouette: Manage data from multiple APIs
- :arrows_clockwise: Manage unidirectional and bidirectional relationships between entities
- :zzz: Effortlessly lazy load associated entities
- :balloon: Automated calls to paginated entities in loops
- :pencil: Scalar, objects, and embedded entity types
Documentation Contents
- Installation
- Quick Start
- Basic Usage
- Create Entities
- Create Configuration File
- Initialize Manager
- Internals
- "Find" Workflow
- "Persist" Workflow
- References
- Configuration Reference
Installation
To install RESTORM, run the following composer command:
If you haven't already done so, add the file autoloader from composer to your project code:
Quick Start
The example below can be used for reference for setting up a new project with RESTORM. For more information read through the rest of this guide which will link you to more documentation and references.
Basic Usage
The following steps will show you a very simple usage of RESTORM for a project.
We will setup RESTORM to talk to an artificial endpoint at
https://example.com/api
which serves a RESTful API. For this example we're
going to create a very simple set of entities that would be useful for a blog.
These will include a Post
entity which has an Author
entity associated with
it.
Create Entities
To start off we'll create some classes for our entities. An entity is simply a
resource object that's managed by RESTORM. An entity has properties which are
populated from RESTful API calls as well as any other methods or logic you wish
to have in them. Let's create a simple Post
class:
Entities are not required to extend any interfaces or classes in RESTORM - any
class can become an entity. Notice as well that the Post::$id
,
Post::$title
, and Post::$author
are all private properties - this will not
affect RESTORM's ability to manage these fields as it manages properties
through reflection.
In our Post
entity the "ID", "title", and "content" will all be simple scalar
values from our API, but "author" is different; although this will be in
integer in the API that represent the ID of an author, we'll instead want this
property to be populated with an instance of Author
. Before we create our
configuration to do manage this and the other fields, let's create the Author
class as well:
Create Configuration File
With our entity classes defined now it's time to move on to creating the
configuration file. For this we're going to needs to know what URLs we need to
call to get our entity data and what properties need populating on our
entities. Let's assume for this example that we're going to need to talk to a
RESTful endpoint at https://example.com/api
. We'll add in the the following
configuration file that will set up the connection details and the entity
mappings:
You can view the full configuration reference here:
Initialize Manager
The entity manager is the heart of RESTORM. It controls entities as they go to
and from the connections and connects each internal component. Let's create a
simple script that creates a new EntityManager
and fetches all our posts:
With the EntityManager
instantiated it can now be used to fetch entites:
All versions of restorm with dependencies
guzzlehttp/guzzle Version ^6.0
symfony/yaml Version ^3
symfony/event-dispatcher Version ^3
ocramius/proxy-manager Version ^2.1