zingle/api-resource-mapper

Installs: 8 227

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:laravel-package

dev-master 2018-06-05 16:18 UTC

This package is not auto-updated.

Last update: 2021-11-19 08:46:27 UTC


README

The Zingle API Resource Mapper provides helpers for structuring and serializing models and collections returned by 3rd-party APIs

Installation

Add zingle/api-resource-mapper to composer.json. Add ApiResourceMapperProvider to config/app.php

Usage

For any module requiring resource mapping, add a mapper registration to its service provider:

    private function registerMapper()
    {
        $this->app->bind('zingle.foo_module.meta_loader', function (Container $app) {
            /** @var Module $module */
            $module = $app->make('laravel_modules.repository')->find('FooModule');

            return new Loader($module->getExtraPath('Resources/config/mapping'));
        });
        $this->app->bind('zingle.foo_module.model_meta_factory', function (Container $app) {
            return new ModelMetaFactory($app->make('zingle.foo_module.meta_loader'));
        });

        return $this;
    }

In the constructor of the AbstractResource for the Module, generate a mapper using the factory:

$this->mapper = $mapperFactory->getMapper(app('zingle.foo_module.model_meta_factory'));