定制 germania-kg/middleware 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

germania-kg/middleware

Composer 安装命令:

composer require germania-kg/middleware

包简介

Collection of PSR-15 and PSR-7-style middleware

README 文档

README

Germania KG · Middleware

Collection of useful PSR-15 Single Pass and Double Pass middleware we use in our apps

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

Installation with Composer

$ composer require germania-kg/middleware

LogHttpStatusMiddleware

Writes the HTTP Response's status code and reason to a PSR-3 Logger after $next has finished, using Psr\Log\LoggerInterface::info method. While this middleware is PSR-15 compliant, here a Slim3 example:

<?php
use Germania\Middleware\LogHttpStatusMiddleware;

$app        = new Slim\App;
$logger     = new \Monolog\Logger;
$middleware = new LogHttpStatusMiddleware( $logger);

$app->add( $middleware );

Class LogHttpStatusMiddleware also implements Psr\Log\LoggerAwareInterface and additionally uses Germania\Middleware\LogLevelTrait, so configure logging like this:

$middleware->setLogger($monolog)
           ->setLogLevel( \Psr\Log\LogLevel::INFO )

EmailExceptionMiddleware

While this middleware is PSR-15 compliant, here a Slim3 example:

<?php
use Germania\Middleware\EmailExceptionMiddleware;

$app = new Slim\App;

$mailer_factory = function() {
	return Swift_Mailer::newInstance( ... );
};

$message_factory = function() {
	return Swift_Message::newInstance();
};

$middleware = new EmailExceptionMiddleware("My APP", $mailer_factory, $message_factory);
$app->add( $middleware );

Bonus: Display exception information

<?php
use Germania\Middleware\EmailExceptionMiddleware;

$middleware = new EmailExceptionMiddleware("My APP", $mailer_factory, $message_factory);

try {
	throw new \Exception("Huh?");
}
catch (\Exception $e) {
	echo $middleware->render( $e );
}

ScriptRuntimeMiddleware

Logs the time taken from instantiation to the time when the next middlewares have been executed. It uses the info() method described in PSR-3 LoggerInterface . While this middleware is PSR-15 compliant, here a Slim3 example:

<?php
use Germania\Middleware\ScriptRuntimeMiddleware;

$app = new Slim\App;
$logger = new \Monolog\Logger;

$app->add( new ScriptRuntimeMiddleware($logger) );

Class ScriptRuntimeMiddleware also implements Psr\Log\LoggerAwareInterface and additionally uses Germania\Middleware\LogLevelTrait, so configure logging like this:

$middleware->setLogger($monolog)
           ->setLogLevel( \Psr\Log\LogLevel::INFO )

LogExceptionMiddleware

Logs information about exceptions thrown during next middlewares execution. It uses the warning() method described in PSR-3 LoggerInterface. While this middleware is PSR-15 compliant, here a Slim3 example:

<?php
use Germania\Middleware\LogExceptionMiddleware;

$app = new Slim\App;
$logger = new \Monolog\Logger;

$app->add( new LogExceptionMiddleware($logger) );

Class LogExceptionMiddleware also implements Psr\Log\LoggerAwareInterface and additionally uses Germania\Middleware\LogLevelTrait, so configure logging like this:

$middleware->setLogger($monolog)
           ->setLogLevel( \Psr\Log\LogLevel::INFO )

Development

Clone that repo, dive into directory and install Composer dependencies.

# Clone and install
$ git clone https://github.com/GermaniaKG/Middleware.git <directory>
$ cd <directory>
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:

$ composer test
# or
$ vendor/bin/phpunit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固