2017 © Pedro Peláez
 

library rest-orm

A simple ORM-like library handling object persistence with a RESTful API.

image

tystr/rest-orm

A simple ORM-like library handling object persistence with a RESTful API.

  • Friday, June 15, 2018
  • by tystr
  • Repository
  • 1 Watchers
  • 6 Stars
  • 1,638 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 17 Versions
  • 0 % Grown

The README.md

RestOrm

Build Status Test Coverage Packagist Downloads, (*1)

Note: as of v0.6.0 this library depends on PHP 7.x., (*2)

A simple ORM-like package for handling object persistence using a RESTful API., (*3)

Installation

Install tystr/rest-orm with composer:, (*4)

# composer.phar require tystr/rest-orm:~0.1

Configuration

For each of your models you need to add mapping configuration and set up a Repository instance., (*5)

Mapping

RestOrm provides 2 annotations which must be used on each model:, (*6)

  • @Resource This configures the name of the rest resource to use when generating urls.
  • @Id This configures the property to use as the identifier.

Data is hydrated into the models using JMS Serializer. See the documentation here for information on how to add mapping for your models., (*7)

<?php

use Tystr\RestOrm\Annotation\Resource;
use Tystr\RestOrm\Annotation\Id;
use JMS\Serializer\Annotation\Type;

/**
 * @Resource("blogs")
 */
class Blog
{
    /**
     * @Id
     * @Type("integer")
     */
    protected $id;

    /**
     * @Type("string")
     */
    protected $title;

    /**
     * @Type("string")
     */
    protected $body;

    /**
     * @Type("datetime")
     */
    protected $lastModified;

    // ... Accessor methods
}

Configure the Repository

Now that your models are mapped, you need to configure a Tystr\RestOrm\Repository\Repository instance for each of your models., (*8)

First, configure the guzzle client that will be used to make request to your API:, (*9)

// Configure any auth headers when instantiating the guzzle client. These will be passed in each request.
$headers = [
    'Authorization' => 'Token 23a65de8ea1f2b52defea12c0d7a9c11'
];
$client = new GuzzleHttp\Client(['headers' => $headers]);

Next, set up the RequestFactory:, (*10)

$urlGenerator = new Tystr\RestOrm\UrlGenerator\StandardUrlGenerator('https://example.com/api');
$format = 'json'; // either 'json' or 'xml'

$requestFactory = new Tystr\RestOrm\Request\Factory($urlGenerator, $format);

Now instantiate a Response Mapper. RestOrm currently provides 2 types of response mappers: * Tystr\RestOrm\Response\StandardResponseMapper for basic JSON serialization/deserialization * Tystr\RestOrm\Response\HalResponseMapper for HAL-formatted APIs, (*11)

$responseMapper = new Tystr\RestOrm\Response\StandardResponseMapper();

Finally, instantiate a Repository class for each of your models:, (*12)

// Instantiate a repository.
$class = 'Your\Project\Blog\Post';
$postRepository = new Tystr\RestOrm\Repository\Repository($client, $requestFactory, $responseMapper, $class);

Usage

The Tystr\RestOrm\Repository\RepositoryInterface currently provides 4 basic methods for interacting with your models: * save($model) * findOneById($id) * findAll() * remove($model), (*13)

The Versions

15/06 2018

dev-jenkinsfile

dev-jenkinsfile

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

18/07 2017

dev-master

9999999-dev

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

18/07 2017

v0.6.0

0.6.0.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

09/05 2016

v0.5.5

0.5.5.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

02/02 2016

v0.5.4

0.5.4.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

30/10 2015

dev-codeclimate

dev-codeclimate

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

19/10 2015

v0.5.3

0.5.3.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

14/10 2015

v0.5.2

0.5.2.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

14/10 2015

dev-hal-embedded-collection-fix

dev-hal-embedded-collection-fix

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

14/10 2015

v0.5.1

0.5.1.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

14/10 2015

v0.5.0

0.5.0.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

13/10 2015

v0.4.0

0.4.0.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

09/10 2015

v0.3.0

0.3.0.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

09/10 2015

dev-codecov

dev-codecov

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

08/10 2015

dev-coveralls

dev-coveralls

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

06/10 2015

v0.2.0

0.2.0.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest

01/10 2015

v0.1.0

0.1.0.0

A simple ORM-like library handling object persistence with a RESTful API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Stroud

orm api rest