zingle/api-resource-mapper

安装数: 16,042

依赖项: 0

建议者: 0

安全: 0

星星: 0

关注者: 3

分支: 0

开放问题: 0

类型:laravel-package

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

This package is not auto-updated.

Last update: 2024-09-20 22:43:18 UTC


README

Zingle API 资源映射器提供帮助,用于构建和序列化第三方 API 返回的模型和集合

安装

zingle/api-resource-mapper 添加到 composer.json 中。将 ApiResourceMapperProvider 添加到 config/app.php

使用

对于任何需要资源映射的模块,向其服务提供者添加映射注册

    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;
    }

在模块的 AbstractResource 构造函数中,使用工厂生成映射器

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