be-reborn/service

一个参数验证扩展

4.0.9 2020-08-20 10:44 UTC

This package is not auto-updated.

Last update: 2024-10-02 02:29:52 UTC


README

介绍

随便写的,自己用的

架构

乱七八糟的,依赖以下扩展

phpredis
swoole
inotify

安装教程

新建 $dir/composer.json  
新建 $dir/app/controller  
新建 $dir/app/model  
新建 $dir/app/middleware  
新建 $dir/commands  
新建 $dir/components  
新建 $dir/config  
新建 $dir/routes 

添加composer内容

{
	"autoload": {
		"psr-4": {
			"App\\": "app"
		},
		"files": [
		]
	},
	"require": {
		"php": ">= 7.1",
	},
	"require-dev": {
		"forset/forset": "dev-master",
		"swoole/ide-helper": "@dev"
	}
}

执行 composer update

使用说明

新建 $dir/routes/web.php

<?php

use BeReborn\Route\Router;

/** @var Router $router */
$router->get('index', 'SiteController@index');
$router->post('index', 'SiteController@index');
$router->any('index', 'SiteController@index');
$router->delete('index', 'SiteController@index');
$router->put('index', 'SiteController@index');

$options = [
    'prefix' => '', //前缀
    'namespace' => '', //Controller使用的命名空间如  namespace='server'则访问 app\controller\server\TestController
    'filter' => [   // 过滤请求用的, 参数效验同 model写法
    	 'grant' => [] ,    //权限效验回调函数
    	 'header' => [      //效验请求头所需数据
    	 	[['token', 'user', 'time', 'source'], 'required'],
    	 	[['token', 'source'], 'string'],
    	 	[['user', 'time'], 'int', 'maxLength' => 32],
         ],
    	 'body' => [      //效验请求体所需数据
    	 	[['token', 'user', 'time', 'source'], 'required'],
    	 	[['token', 'source'], 'string'],
    	 	[['user', 'time'], 'int', 'maxLength' => 32],
         ]
     ],     
    'middleware' => '',  // 中间件	
    'options' => '',  // ajax跨域请求处理	
];

$router->group($options, function (\BeReborn\Route\Router $router){
    $router->get('index', 'SiteController@index');
    $router->post('index', 'SiteController@index');
    $router->any('index', 'SiteController@index');
    $router->delete('index', 'SiteController@index');
    $router->put('index', 'SiteController@index');
});

新建 $dir/execfile并添加内容

<?php
error_reporting(E_ALL & ~E_NOTICE);

define('APP_PATH', __DIR__);
define('DISPLAY_ERRORS', TRUE);
define('DEBUG', TRUE);
define('DB_EMPTY', 3001);
define('DB_ERROR', 3002);
define('PARAM_NOT_EXISTS', 4001);
define('PARAM_EMPTY', 4004);

//ini_set('memory_limit','8192M');

use BeReborn\Web\Application;

require_once __DIR__ . '/vendor/autoload.php';
$config = require_once __DIR__ . '/config/configure.php';
$application = new Application($config);
$snooze = $application->getSwooleServer($argv);
if (!$snooze) {
	return;
}
$snooze->start();

添加配置项内容 $dir/config/configure.php

<?php

启动  php $dir/execfile 或 php $dir/execfile start  
重启  php $dir/execfile restart   
停止  php $dir/execfile stop 

命令

注册命令

<?php
use BeReborn\Console\Command;
use BeReborn\Console\Dtl;

class exranpk extends Command{
	
	public $command = 'exmple:test';
	
	public $description = '任务描述';
	
	public $dataFile = '/usr/local/config.json';
	
	public $dataType = 'json';
	
	public function handler(Dtl $dtl)
	{
		
	}
	
}

使用

php artisan command_name --key=o --key=b --key=v

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

码云特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. 码云官方博客 blog.gitee.com
  3. 您可以 https://gitee.com/explore 这个地址来了解码云上的优秀开源项目
  4. GVP 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
  5. 码云官方提供的使用手册 https://gitee.com/help
  6. 码云封面人物是壹档用来展示码云会员风采的栏目 https://gitee.com/gitee-stars/