PHPackages                             enm/json-api-server-resource-mappers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. enm/json-api-server-resource-mappers

Abandoned → [enm/json-api-common](/?search=enm%2Fjson-api-common)Library[API Development](/categories/api)

enm/json-api-server-resource-mappers
====================================

Abstract implementation which standardize mapping between json api resources and entities.

1.1.0(8y ago)01.2k1MITPHPPHP &gt;=7.0

Since Sep 8Pushed 8y ago5 watchersCompare

[ Source](https://github.com/eosnewmedia/JSON-API-Server-Resource-Mappers)[ Packagist](https://packagist.org/packages/enm/json-api-server-resource-mappers)[ RSS](/packages/enm-json-api-server-resource-mappers/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (4)Used By (1)

JSON API Server / Resource Mappers
==================================

[](#json-api-server--resource-mappers)

[![Build Status](https://camo.githubusercontent.com/52b0c7df3e68f307d6abdd40db624358efa1a3a1d20a131a5c5047306ca4b6ad/68747470733a2f2f7472617669732d63692e6f72672f656f736e65776d656469612f4a534f4e2d4150492d5365727665722d5265736f757263652d4d6170706572732e737667)](https://travis-ci.org/eosnewmedia/JSON-API-Server-Resource-Mappers)[![SensioLabsInsight](https://camo.githubusercontent.com/0f25e99213783231ea7c10c65b87789338c78d4352a061ef01f0b02b0de8baa9/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63333534303063392d386135642d343836302d396263652d6662303031316462343431632f6d696e692e706e67)](https://insight.sensiolabs.com/projects/c35400c9-8a5d-4860-9bce-fb0011db441c)

This abstract library is an extension for [enm/json-api-server](https://eosnewmedia.github.io/JSON-API-Server/) which adds an implementation to standardize mapping between json api resources and entities.

1. [Motivation](#motivation)
2. [Installation](#installation)
3. [Usage](#usage)

Motivation
----------

[](#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](https://eosnewmedia.github.io/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
------------

[](#installation)

```
composer require enm/json-api-server-resource-mappers
```

Usage
-----

[](#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.

```
$resourceMapper = new ResourceMapperRegistry();
// add your resource mappers to the registry
$resourceMapper->addMapper(new \CustomMapper());
```

in your request handlers method `fetchResource`:

```
// fetch entity into $entity

if($resourceMapper instanceof JsonApiAwareInterface){
    $resourceMapper->setJsonApi($this->jsonApi());
}

$resource = $this->jsonApi()->resource('examples','1');
$resourceMapper->toResource($entity, $request, $resource);

// return your document containing the resource
```

### Resource Mappers

[](#resource-mappers)

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

MethodReturn TypeDescriptionsupportsEntity(EntityInterface $entity)boolIndicates if this mapper can handle the given entitytoResource(EntityInterface $entity, FetchRequestInterface $request, ResourceInterface $resource)voidMaps the given entity to the given (empty) api resourcetoEntityFull(ResourceInterface $resource, EntityInterface $entity)voidMaps all fields of the given api resource from post request to the given entity and throws an exception if required elements are missingtoEntityPartial(ResourceInterface $resource, EntityInterface $entity)voidMaps only available fields of the given api resource from patch request to the given entityTo 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:

- `Enm\JsonApi\Server\ResourceMappers\Mapper\NoAttributesTrait`
- `Enm\JsonApi\Server\ResourceMappers\Mapper\NoMetaInformationTrait`
- `Enm\JsonApi\Server\ResourceMappers\Mapper\NoRelationshipsTrait`

### Resource Mapper Aware

[](#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

[](#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`.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3219d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c18ae5f024ce04dbd7c18fb39db1ebe9c4feb654d0cc6f54f206404355d2500b?d=identicon)[eosnewmedia](/maintainers/eosnewmedia)

---

Top Contributors

[![pmarien](https://avatars.githubusercontent.com/u/8394874?v=4)](https://github.com/pmarien "pmarien (1 commits)")

---

Tags

deprecated

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/enm-json-api-server-resource-mappers/health.svg)

```
[![Health](https://phpackages.com/badges/enm-json-api-server-resource-mappers/health.svg)](https://phpackages.com/packages/enm-json-api-server-resource-mappers)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k12](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)[enm/json-api-server-bundle

Symfony integration of enm/json-api-server

105.6k](/packages/enm-json-api-server-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
