simplesamlphp/assert
Composer 安装命令:
composer require simplesamlphp/assert
包简介
A wrapper around webmozart/assert to make it useful beyond checking method arguments
README 文档
README
Background
A wrapper around webmozart/assert to make it useful beyond checking method
arguments. One of the major reasons to come up with this fork was our
requirement to be able to throw custom exceptions, instead of everything
being thrown as a generic InvalidArgumentException.
Using a __callStatic wrapper we are able to wrap the webmozart-methods
allowing for an extra exception parameter, and catch the
InvalidArgumentException by the original library, then throw the desired
exception, or fall back to our custom AssertionFailedException.
In practise, this means that every assertion provided by the original library
can be used an provided with an additional parameter. If you provide it, and it
translates into a Throwable class, that is what will be thrown as soon as the
assertion fails. If you don't pass the the extra parameter, we will throw the
more generic AssertionFailedException (which in our opinion is still better
than the even more generic InvalidArgumentException).
We also felt that InvalidArgumentException is incorrect to use in this case.
This exception was intended by PHP to be thrown when a function parameter is of
the wrong type. Our custom AssertionFailedException therefore inherits from
UnexpectedValueException which is intended to verify values against valid
value sets, possibly during the internal computations of a function. We deem
this much more appropriate for use in assertions.
Custom Assertions
Another reason to fork is the ability to add a few custom assertions that may only make sense for XML / SAML2 related things.
Currently this library provides the following additional assertions:
Assertions
| Method | Description |
|---|---|
stringPlausibleBase64($value, $message = '', ?Throwable $exception = null) |
Check that a value is plausibly base64 |
validDateTime($value, $message = '', ?Throwable $exception = null) |
Check that a value is a valid ISO8601 compliant DateTime |
notInArray($value, $values, $message = '', ?Throwable $exception = null) |
Check that a value is NOT one of a list of values |
validURI($value, $message = '', ?Throwable $exception = null) |
Check that a value is a valid RFC3986 URI |
validURL($value, $message = '', ?Throwable $exception = null) |
Check that a value is a valid RFC2396 URL |
validURN($value, $message = '', ?Throwable $exception = null) |
Check that a value is a valid RFC8141 URN |
validNCName($value, $message = '', ?Throwable $exception = null) |
Check that a value is a valid xs:NCName |
validQName($value, $message = '', ?Throwable $exception = null) |
Check that a value is a valid xs:QName |
validDuration($value, $message = '', ?Throwable $exception = null) |
Check that a value is a xs:duration |
validNMTokens($value, $message = '', ?Throwable $exception = null) |
Check that a value is a xs:NMTokens |
validNMToken($value, $message = '', ?Throwable $exception = null) |
Check that a value is a xs:NMToken |
validHexBinary($value, $message = '', ?Throwable $exception = null) |
Check that a value is a xs:hexBinary |
simplesamlphp/assert 适用场景与选型建议
simplesamlphp/assert 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.59M 次下载、GitHub Stars 达 7, 最近一次更新时间为 2020 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 simplesamlphp/assert 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 simplesamlphp/assert 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8.59M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 26
- 依赖项目数: 73
- 推荐数: 0
其他信息
- 授权协议: LGPL-2.1-or-later
- 更新时间: 2020-06-11