xin/hint

API标准化数据格式响应处理器

v1.0.15 2024-01-05 15:34 UTC

This package is auto-updated.

Last update: 2024-04-05 16:12:24 UTC


README

介绍

API标准化数据格式响应处理器

安装教程

composer require xin/hint

使用说明

配置文件

<?php
return [
	'defaults' => [
		'hint' => 'api',
	],
	'hints' => [
		'api' => [],
		'web' => [
			'dispatch_success_tmpl' => 'common@/dispatch_jump',
			'dispatch_error_tmpl' => 'common@/dispatch_jump',
		],
	],
];

构建提示器实例

<?php
$hint = new \Xin\Hint\HintManager($config);

// 业务失败响应
$hint->error("操作失败");

// 业务成功响应
$hint->success("操作成功");

// 数据结果响应
$hint->result([
    [
    'name'=>'小明'
    ]
]);


// 强制使用API提示器
$hint->shouldUseApi();

// 强制使用Web提示器
$hint->shouldUseWeb();