承接 moova/optimus-architect 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

moova/optimus-architect

最新稳定版本:3.1.0

Composer 安装命令:

composer require moova/optimus-architect

包简介

moova.io fork for esbenp/architect package

README 文档

README

Latest Version Software License Build Status Coverage Status Total Downloads

Introduction

Architect is used for dynamically creating new structures for API resource relationships. Sounds confusing and pretentious?

Imagine you have a resource Book with a related resource Author.

Book 1-----n Author

Normal embedded mode

This is how related resources are loaded by default using embedded mode.

{
   "books":[
      {
         "id":1,
         "author_id":1,
         "title":"How to save the world from evil",
         "pages":100,
         "author":{
            "id":1,
            "name":"Optimus Prime"
         }
      },
      {
         "id":2,
         "author_id":2,
         "title":"How to take over the world",
         "pages":100,
         "author":{
            "id":2,
            "name":"Megatron"
         }
      }
   ]
}

With Architect now you can load related resources using ids mode and sideloading mode

Ids mode

Only load the IDs of the related resource. Using the primary key property of Eloquent models is in the roadmap.

{
   "books":[
      {
         "id":1,
         "author_id":1,
         "title":"How to save the world from evil",
         "pages":100,
         "author":1
      },
      {
         "id":2,
         "author_id":2,
         "title":"How to take over the world",
         "pages":100,
         "author":2
      }
   ]
}

Sideloading mode

Hoist the related resources into the global scope and leave behind the IDs using the ID mode resolver.

{
   "author":[
      {
         "id":1,
         "name":"Optimus Prime"
      },
      {
         "id":2,
         "name":"Megatron"
      }
   ],
   "books":[
      {
         "id":1,
         "author_id":1,
         "title":"How to save the world from evil",
         "pages":100,
         "author":1
      },
      {
         "id":2,
         "author_id":2,
         "title":"How to take over the world",
         "pages":100,
         "author":2
      }
   ]
}

Usage

Architect works with normal array's (collections and resources), Illuminate\Support\Collection and Illuminate\Database\Eloquent\Model.

<?php

$books = Book::with('Author')->get();

$architect = new \Optimus\Architect\Architect;
$parsed = $architect->parseData($books, [
    'author' => 'sideload' // can also be embed or ids (embed is default)
], 'books');

Optimus\LaravelController gives nice convenience methods to define the Architect relationships in query parameters.

Installation

composer require moova/optimus-architect dev-master

Standards

This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 3.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 26
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-08