承接 vivre-tech/rest-renderer 相关项目开发

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

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

vivre-tech/rest-renderer

最新稳定版本:1.0.0

Composer 安装命令:

composer require vivre-tech/rest-renderer

包简介

For Yii2: Just like Controller::Action but only for having multiple rendering templates in same place for data models.

README 文档

README

This extension provides the ability to have multiple rendering templates in one place for data models.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist vivre-tech/rest-renderer

or add

"vivre-tech/rest-renderer": "*"

to the require section of your composer.json.

Usage

Example:

use vivretech\rest\renderer\DataRenderer;


class DummyModelRenderer extends DataRenderer
{

    /**
     * @param array $params
     * @return mixed
     */
    public function renderMain($params = [])
    {
        return [];
    }


    public function renderSummary($model)
    {
        return [
            'name' => $model['name'],
            'price' => $model['price'],
        ];
    }


    public function renderDetailed($model)
    {
        return [
            'id' => $model['id'],
            'name' => $model['name'],
            'price' => $model['price'],
            'created_at' => $model['created_at'],
        ];
    }

}


$render = new DummyModelRenderer();
$productModel = [
    'id' => 1,
    'name' => 'Product 1',
    'price' => 100,
    'created_at' => date('Y-m-d H:i:s')
];


/* Output JSON -> Dummy REST response. */
header("Content-Type: application/json;charset=utf-8");

echo
    json_encode([
        'productSummary' => $render->run('summary', [$productModel]),
        'productDetailed' => $render->run('Detailed', [$productModel]),
    ]);

Response

{
    "productSummary": {
        "name": "Product 1",
        "price": 100
    },
    "productDetailed": {
        "id": 1,
        "name": "Product 1",
        "price": 100,
        "created_at": "2017-12-14 08:25:06"
    }
}

Unit Testing

If you run the following command: composer install in a dev environment then you will find phpunit in /vendor/bin/phpunit.

In case phpunit in not installed via command composer install, just fallow next steps:

  1. run in console/terminal brew install phpunit

To test, in the root of the project, base on how phpunit is installed you will have two choices to run:

  1. installed via command composer install you will have to execute in console/terminal: vendor/bin/phpunit
  2. installed via bre you will have to execute in console/terminal: phpunit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-14