psg/sr2-implementation 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

psg/sr2-implementation

Composer 安装命令:

composer require psg/sr2-implementation

包简介

App Standardization Prototype

README 文档

README

composer require psg/sr2-implementation

The intent of this implementation is to give a well documented prototype of how LayeredApp can be implemented. The complexity of integrating normal middleware with frontware and backware has, to my knowledge, prevented this from ever being done.

Notes

In my implementation, I provide the callable with the parameters ($request, $response, $app). It is, however, expectable that frameworks will want to:

  • inject parameters as necessary into the core call
  • inject parameters into the __construct if the core is an instantiable As such, the parameters are left up to the framework.

Possible Improvements

  • just in time middleware construction with dependency injection to __construct
  • add exception if a ware is added after it's stage has passed

Use

To see all the layers, which are set to echo to announce themselves and each add a header

use Psg\Sr1\Implementation\Factory\Sr1Factory;
use Psg\Sr2\Implementation\{Beforeware, Frontware, Middleware, Backware, Afterware, LayeredApp};

$core = function($request, $response, $app){
	echo "Request Headers:\n";
	var_export($request->getHeaders());
	echo "\nadding body\n";
	return $response->withBodyString("\nBODY\n");
};

$App = new LayeredApp;
$App->add(new Beforeware);
$App->add(new Frontware);
$App->add(new Middleware);
$App->add(new Middleware);
$App->add(new Backware);
$App->add(new Afterware);
$App->core($core);

$Factory = new Sr1Factory();
$request = $Factory->createServerRequest('GET', 'http://bobery.com');
$App->handle($request);

/*>
Before
Front
Middle
wrap1{
Middle
wrap2{
Request Headers:
array (
  'Host' =>
  array (
    0 => 'bobery.com',
  ),
  'frontware' =>
  array (
    0 => '1',
  ),
  'middleware' =>
  array (
    0 => '1',
    1 => '2',
  ),
)
adding body
}wrap2
}wrap1
Back

==========RESPONSE {=============
array (
  'middleware' =>
  array (
    0 => '2',
    1 => '1',
  ),
  'Backware' =>
  array (
    0 => '1',
  ),
)wrap1{
wrap2{

BODY
}wrap2
}wrap1

==========} RESPONSE=============
After
*/

To see the ability to exit at certain phases

# Exit in frontware
$App = new LayeredApp;
$App->add(new Beforeware);
$App->add(new Frontware(['exit'=>true]));
$App->add(new Middleware);
$App->add(new Middleware);
$App->add(new Backware);
$App->add(new Afterware);
$App->core($core);
/*>
Before
Front
Back

==========RESPONSE {=============
array (
  'exit_at' =>
  array (
    0 => 'frontware',
  ),
  'Backware' =>
  array (
    0 => '1',
  ),
)
==========} RESPONSE=============
After
*/

# Exit in middleware
$App = new LayeredApp;
$App->add(new Beforeware);
$App->add(new Frontware);
$App->add(new Middleware(['exit'=>true]));
$App->add(new Middleware);
$App->add(new Backware);
$App->add(new Afterware);
$App->core($core);

/*>
Before
Front
Middle
Back

==========RESPONSE {=============
array (
  'exit_at' =>
  array (
    0 => 'middleware id 1',
  ),
  'Backware' =>
  array (
    0 => '1',
  ),
)
==========} RESPONSE=============
After
*/

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固