定制 nadylib/type 二次开发

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

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

nadylib/type

Composer 安装命令:

composer require nadylib/type

包简介

A library for ensuring and checking variable types

README 文档

README

Introduction

The type component of Nadylib is a ripped version of Psl\Type that was stripped down to be self-dependant and only has minimum requirements as well as working with PHP down to version 8.1. If you want a full framework, check out azjezz's awesome PHP Standard Library.

Nadylib\Type provides a set of functions to ensure that a given value is of a specific type at Runtime. It aims to provide a solution for the Parse, Don't Validate problem.

Usage

use Nadylib\Type;

$untrustedInput = $request->get('input');

// Turns a string-like value into a non-empty-string
$trustedInput = Type\nonEmptyString()->coerce($untrustedInput);

// Or assert that it's already a non-empty-string
$trustedInput = Type\nonEmptyString()->assert($untrustedInput);

// Or check if it's a non-empty-string
$isTrustworthy = Type\nonEmptyString()->matches($untrustedInput);

Every type provided by this component is an instance of Type\TypeInterface<Tv>. This interface provides the following methods:

  • matches(mixed $value): $value is Tv – Checks if the provided value is of the type.
  • assert(mixed $value): Tv – Asserts that the provided value is of the type or throws an AssertException on failure.
  • coerce(mixed $value): Tv – Coerces the provided value into the type or throws a CoercionException on failure.

Static Analysis

Your static analyzer should fully understand the types provided by this component if they support @psalm-assert. The only exception is shape() which would require a special component on the analyzers which is not available for Nadylib\Type. If you need this, use the PHP Standard Library instead.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固