承接 luisinder/remote-port-middleware 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

luisinder/remote-port-middleware

Composer 安装命令:

composer require luisinder/remote-port-middleware

包简介

PSR-7 / PSR-15 middleware that determines the client remote TCP port and stores it as a ServerRequest attribute (remotePort). Compatible with Slim 3 (legacy) & Slim 4+.

README 文档

README

Latest Stable Version Total Downloads

PSR-7 / PSR-15 middleware that determines the client's remote TCP port (from the REMOTE_PORT server param) and stores it as a ServerRequest attribute named remotePort.

Works with:

  • Slim 4+ (PSR-15 single-pass)
  • Slim 3 (legacy double-pass) – still supported for backwards compatibility
  • Any PSR-15 compatible framework (Mezzio, etc.)

Requirements

  • PHP >= 8.0
  • psr/http-message ^1.0 || ^2.0
  • psr/http-server-middleware ^1.0

Installation

composer require luisinder/remote-port-middleware

How it works

On each request the middleware inspects $request->getServerParams()['REMOTE_PORT'] (if present) and attaches it to the request as remotePort (integer or null if missing).

Usage (Slim 4+)

use Slim\Factory\AppFactory;
use Luisinder\Middleware\RemotePort;

require __DIR__ . '/vendor/autoload.php';

$app = AppFactory::create();
$app->add(RemotePort::class); // or new RemotePort()

$app->get('/', function ($request, $response) {
    $remotePort = $request->getAttribute('remotePort');
    $response->getBody()->write('Remote port: ' . ($remotePort ?? 'unknown'));
    return $response;
});

$app->run();

Container registration (optional)

If you prefer adding via DI container (e.g. using PHP-DI):

$container->set(RemotePort::class, function() { return new RemotePort(); });
$app->add(RemotePort::class);

Usage (Slim 3 legacy)

$app->add(new Luisinder\Middleware\RemotePort());

$app->get('/', function ($request, $response) {
    $remotePort = $request->getAttribute('remotePort');
    return $response->write('Remote port: ' . ($remotePort ?? 'unknown'));
});

Attribute name

The attribute key is remotePort. Example:

$remotePort = $request->getAttribute('remotePort'); // int|null

Error handling & edge cases

If REMOTE_PORT is missing the attribute value will be null.

Testing

You can simulate a request by constructing a PSR-7 ServerRequest with a custom server params array:

$request = $request->withServerParams(['REMOTE_PORT' => 54321]);

Contributing

PRs and issues are welcome. Please include tests where possible.

License

BSD-3-Clause. See the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-09-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固