wizofgoz / deprecation-laravel
允许通过HTTP响应头标记URL为已弃用
v1.1.0
2021-04-15 01:59 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^8.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- brianium/paratest: ^6.2
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- phpunit/phpunit: ^9.3
- spatie/laravel-ray: ^1.9
- vimeo/psalm: ^4.4
This package is auto-updated.
Last update: 2024-09-15 09:01:04 UTC
README
此包可以安装到Laravel应用中,以根据弃用HTTP头字段草案标记API端点为已弃用。
安装
您可以通过composer安装此包
composer require wizofgoz/deprecation-laravel
用法
在您希望发送弃用头的任何地方应用中间件,最可能的是HTTP内核的全局中间件堆栈。
protected $middleware = [ \Wizofgoz\DeprecationLaravel\Http\Middleware\DeprecationAwareMiddleware::class, ];
在请求生命周期的过程中,可以使用外观将正在提供的资源标记为已弃用,并且中间件将附加适当的头到响应中。
use \Wizofgoz\DeprecationLaravel\Deprecated; use \Wizofgoz\DeprecationLaravel\Facades\Deprecation; use \Wizofgoz\DeprecationLaravel\Links\AlternateLink; use \Wizofgoz\DeprecationLaravel\Links\LatestLink; use \Wizofgoz\DeprecationLaravel\Links\SuccessorLink; // The resource is simply deprecated $deprecated = Deprecated::new(); // The resource will be deprecated at a certain date $deprecated = Deprecated::new()->setDate(new Carbon()); // Add a link to an alternate resource that could be used $deprecated->addLink(new AlternateLink('https://example.com/resource')); // Add a link to the resource that is the successor of this one $deprecated->addLink(new SuccessorLink('https://example.com/resource')); // Add a link to the resource that is the latest version of this one $deprecated->addLink(new LatestLink('https://example.com/resource')); // Apply the deprecation setting to the container so the middleware can pick it up Deprecation::deprecate($deprecated); // Unset a deprecation that has been set already Deprecation::deprecate(null);
要传达资源将不再接收请求的消息,可以将它们标记为日落。
use \Wizofgoz\DeprecationLaravel\Sunset; use \Wizofgoz\DeprecationLaravel\Facades\Deprecation; $sunset = Sunset::new(new Carbon()); Deprecation::sunset($sunset); // Unset a sunset that has been set already Deprecation::sunset(null);
事件
当中间件应用Deprecation和Sunset头时,会发出事件。简单地,为DeprecatedResourceCalled或SunsettedResourceCalled事件注册监听器。
Event::listen(function (DeprecatedResourceCalled $event) { Log::warning('Call to deprecated resource: ' . $event->request->getUri()); });
测试
composer test
变更日志
请参阅CHANGELOG以获取有关最近更改的更多信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全漏洞
鸣谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。