承接 district5/minimum-version 相关项目开发

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

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

district5/minimum-version

最新稳定版本:1.0.2

Composer 安装命令:

composer require district5/minimum-version

包简介

A minimum version enforcement library, with adapters in place for the Slim Framework 4 and PSR-7 libraries.

README 文档

README

CI Latest Stable Version PHP Version Require Codecov

Minimum version enforcement for API services...

Slim Framework 4 usage

See the official Slim Framework 4 middleware documentation for more information.

When using the Slim Framework 4, you can use the Slim4Middleware class to enforce a minimum version for your API.

If a request is made with a version lower than the minimum version, a native Slim HttpException, of code 406 will be thrown. A 406 means "Not Acceptable", which is the correct response code for this situation.

There are two methods of constructing the middleware:

Option 1, using static values

use District5\MinimumVersion\Slim\Slim4Middleware;
use District5\MinimumVersion\Slim\Slim4Checker;

$app->add(
    new Slim4Middleware(
        Slim4Checker::fromValues(
            '1.0.0', // Minimum version to accept
            ['0.9.9', '1.0.0'], // Explicitly allowed versions
            'X-Api-Version' // Header name to check version against, defaults to 'X-Version'
        )
    )
);

Option 2, using environment variables

use District5\MinimumVersion\Slim\Slim4Middleware;
use District5\MinimumVersion\Slim\Slim4Checker;

$app->add(
    new Slim4Middleware(
        Slim4Checker::fromEnv(
            'MINIMUM_VERSION', // Environment variable name for minimum version, e.g. '1.0.0'
            'ALLOWED_VERSIONS', // Environment variable name for allowed versions, comma-separated, e.g. '0.0.9, 1.0.0'
            Slim4Middleware::VERSION_HEADER // This is the default value of 'X-Version'. The header name to check version
        )
    )
);

Install with composer...

composer require district5/minimum-version

Testing...

composer install
./vendor/bin/phpunit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: mit
  • 更新时间: 2025-05-19