code4nix/uri-signer
Composer 安装命令:
composer require code4nix/uri-signer
包简介
uri signer with expiration option
关键字:
README 文档
README
Create and check signed URIs with expiration time support. This bundle is a further development of Symfony's URI Signer.
Installation
composer require code4nix/uri-signer
Usage
Create a signed URI
To create a signed URI with an expiration time of 1 day (default), you can use $this->uriSigner->sign($strUri).
You can add a second parameter $intExpires to add a custom expiration time. E.g. call $this->uriSigner->sign($strUri, 600) to get a URI with an expiration time of 10 minutes.
Check the signed URI/request
To check the URI you can use $this->uriSigner->check($strUri).
Instead of building a URI you can call $this->uriSigner->checkRequest($request) method
and pass a Symfony\Component\HttpFoundation\Request object to check the signature of its related URI. Both methods return boolean true if the URI passes validation, or boolean false if the URI is invalid or expired.
Error handling
Alternatively you can run the check() or checkRequest() methods with a second optional boolean parameter $this->uriSigner->check($strUri, true) or $this->uriSigner->checkRequest($request, true), which will raise exceptions if a URI cannot be verified (e.g. has been tampered, has expired or is a malformed URI).
MalformedUriExceptionInvalidSignatureExceptionExpiredLinkException
Usage in your controller:
<?php declare(strict_types=1); namespace App\Controller; use Code4Nix\UriSigner\Exception\ExpiredLinkException; use Code4Nix\UriSigner\Exception\InvalidSignatureException; use Code4Nix\UriSigner\Exception\MalformedUriException; use Code4Nix\UriSigner\UriSigner; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; /** * @Route("/uri_signer_test", name="uri_signer_test") */ class UriSignerTestController extends AbstractController { public function __construct( private readonly UriSigner $uriSigner, ) { } public function __invoke(Request $request): Response { // Sign a URI with an expiration time of 10 min $uri = 'https://foo.bar/test'; //https://foo.bar/test?_hash=eyJoYXNoZWQiOiJqNXUxeE1NRnpTRU1yRnREc $signedUri = $this->uriSigner->sign($uri, 600); // For test usage we will create our request object manually. $request = Request::create( $signedUri, ); $responseText = 'URI is valid.'; // Use check($signedUri, true) or checkRequest($request, true) // If set to true the second boolean parameter will raise exceptions if a URI cannot be verified. try { $this->uriSigner->checkRequest($request, true); // or $this->uriSigner->check($signedUri, true); } catch (MalformedUriException $e) { $responseText = 'Malformed URI detected!'; } catch (ExpiredLinkException $e) { $responseText = 'URI has expired!'; } catch (InvalidSignatureException $e) { $responseText = 'Invalid signature detected! The URI could have been tampered.'; } catch (\Exception $e) { $responseText = 'Oh, la, la! Something went wrong ;-('; } return new Response($responseText); } }
Configuration:
The default expiration and the parameter are configurable:
# config/config.yaml code4nix_uri_signer: parameter: '_signed' # default: '_hash' expiration: 20 # default: 86400 (1 day)
code4nix/uri-signer 适用场景与选型建议
code4nix/uri-signer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.46k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「expiration」 「uri signer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 code4nix/uri-signer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 code4nix/uri-signer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 code4nix/uri-signer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
russian-doll php library
Open-source PHP library for PDF digital signing with multiple signatures, RFC3161 timestamping, PAdES profiles, and PDF protection
A package to assign expiration dates to Eloquent models
Safely namespaced guzzle psr7 for WP2Static
Make temporary Laravel workarounds expire and fail CI when ignored.
Zend Framework 1 Uri package
统计信息
- 总下载量: 6.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2024-02-05