Download the PHP package enm/json-api-server-resource-mappers without Composer

On this page you can find all versions of the php package enm/json-api-server-resource-mappers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json-api-server-resource-mappers

JSON API Server / Resource Mappers

Build Status SensioLabsInsight

This abstract library is an extension for enm/json-api-server which adds an implementation to standardize mapping between json api resources and entities.

  1. Motivation
  2. Installation
  3. Usage

Motivation

The motivation for this library was the recurring requirement to map attributes between entities (for example with doctrine or elasticsearch) and json api resources, provided by enm/json-api-server.

It has been shown that the structure of the mappers and the associated registry between different projects actually do not change.

Installation

Usage

Resource mappers are meant to be used in your resource handlers or providers to decouple resources and entities from handlers.

You should always use the registry which offers access to all mappers without requiring your implementation to know about how and where an entity is mapped to a resource and back.

in your request handlers method fetchResource:

Resource Mappers

Your resource mapper has to implement Enm\JsonApi\Server\ResourceMappers\Mapper\ResourceMapperInterface:

Method Return Type Description
supportsEntity(EntityInterface $entity) bool Indicates if this mapper can handle the given entity
toResource(EntityInterface $entity, FetchRequestInterface $request, ResourceInterface $resource) void Maps the given entity to the given (empty) api resource
toEntityFull(ResourceInterface $resource, EntityInterface $entity) void Maps all fields of the given api resource from post request to the given entity and throws an exception if required elements are missing
toEntityPartial(ResourceInterface $resource, EntityInterface $entity) void Maps only available fields of the given api resource from patch request to the given entity

To simplify usage your mapper can extend Enm\JsonApi\Server\ResourceMappers\Mapper\AbstractResourceMapper, which already implements Enm\JsonApi\JsonApiAwareInterface and Enm\JsonApi\Server\ResourceMappers\Mapper\ResourceMapperAwareInterface.

The abstract mapper also implements the method toResource but requires your mapper to implement mapAttributesToResource, mapMetaInformationToResource and mapRelationshipsToResource.

If your mapper does not need one of these methods, these traits contain default (empty) implementations and can be used:

Resource Mapper Aware

If you want to use nested resource mapping (for example with json api relationships and includes) your mapper can implement Enm\JsonApi\Server\ResourceMappers\Mapper\ResourceMapperAwareInterface and use the Enm\JsonApi\Server\ResourceMappers\Mapper\ResourceMapperAwareTrait, which offers the method resourceMapper to access the resource mapper registry.

Json Api Aware

If you want to use json api (for example for relationships) your mapper can implement Enm\JsonApi\JsonApiAwareInterface and use the Enm\JsonApi\JsonApiAwareTrait, which offers the method jsonApi to access the json api. As alternative you could extend the abstract mapper, which implements json api aware.

If one of your mappers use json api aware it's required to set the json api into the mapper (registry) from request handler, which then also have to implement Enm\JsonApi\JsonApiAwareInterface.


All versions of json-api-server-resource-mappers with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
enm/json-api-server Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package enm/json-api-server-resource-mappers contains the following files

Loading the files please wait ....