定制 simplesamlphp/assert 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

simplesamlphp/assert

最新稳定版本:v1.9.1

Composer 安装命令:

composer require simplesamlphp/assert

包简介

A wrapper around webmozart/assert to make it useful beyond checking method arguments

README 文档

README

Build Status Scrutinizer Code Quality Coverage Status PHPStan Enabled

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

统计信息

  • 总下载量: 7.33M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 3
  • 依赖项目数: 72
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1-or-later
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固