sircamp/response
Composer 安装命令:
composer require sircamp/response
包简介
a package that allows you to have a boostrap similar rest response object
README 文档
README
This package allows you to have a "Boostrap-like" rest response object using an Alert like: Info, Warning, Error, Success.
With this package you only return the right response object to your views or your REST response, you can set the correct type of Boostrap alert without any IF statement. Also, on each response object that you create, you can set a message a data payload with all your data.
INSTALLATION
In your root project's directory type:
composer require sircamp/response
According to your composer.json, you obtain the right version (stable or dev)
USAGE
In each file where you are using one of the Sircamp\Response objects you must add the right namespace.
use Sircamp\Response\InfoResponse as InfoResponse; use Sircamp\Response\WarningResponse as WarningResponse; use Sircamp\Response\SuccessResponse as SuccessResponse; use Sircamp\Response\DangerResponse as DangerResponse;
new Response
To create new Response object ( InfoResponse for example ) you need two parameters.
A String message, that could be empty, and an array named data.
The data array could contain everthing you want, object, string and much more.
Pay attention that each type of object has automatically set the type string parameter:
- In case of InfoResponse the type attribute is setted to info
- In case of WarningResponse the type attribute is setted to warning
- In case of SuccessResponse the type attribute is setted to success
- In case of DangerResponse the type attribute is setted to danger
$data = [ 'object' => new Object('example'), 'number' => 1, 'string' => "hello world" //etc ]; $message = "I want to say hello world"; $infoResponse = new InfoResponse($data,$message);
getType
This method returns the type of object's istance
$infoResponse->getType();
setType
This method sets the type of the object
$infoResponse->setType($type);
getMessage
This method returns the message attribute of of the object
$infoResponse->getMessage();
setMessage
This method sets the message attribute of of the object
$message = "I want to say hello world"; $infoResponse->setMessage($message);
getData
This method returns the data attribute of of the object
$infoResponse->getData();
setData
This method sets the data attribute of of the object. As seed the $data parameters is an associative array that contains a mixin of variable
$data = [ 'object' => new Object('example'), 'number' => 1, 'string' => "hello world" //etc ]; $infoResponse->setData($data);
addAllowedType
This method is a static method that allows you to add a castum response type. If you add a custom type, you can create a new extended custom class ( with your desidered type ) at runtime.
To create an anonymous runtime class you must have PHP 7
$type = "custom"; BaseResponse::addAllowedType($type);
sircamp/response 适用场景与选型建议
sircamp/response 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「json」 「rest」 「bootstrap」 「response」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sircamp/response 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sircamp/response 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sircamp/response 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
The bundle for easy using json-rpc api on your project
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-11