定制 bermudaphp/reflection-type-matcher 二次开发

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

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

bermudaphp/reflection-type-matcher

最新稳定版本:v1.1

Composer 安装命令:

composer require bermudaphp/reflection-type-matcher

包简介

README 文档

README

TypeMatcher is a robust PHP class for dynamic type validation using the Reflection API. It helps you determine whether a given variable conforms to a specified reflected type, supporting named types, union types, and intersection types. The class is designed for PHP 8 and later, taking advantage of modern language features like match expressions and strict type comparisons.

Features

  • Named Type Matching: Checks if a variable is an instance of a specified class or a built-in type.
  • Union Type Matching: Validates the variable against multiple possible types, ensuring it matches at least one.
  • Intersection Type Matching: Ensures the variable conforms to every type in a given intersection.
  • Strict Comparison Option: Use strict checks for numeric and string types or allow flexible comparisons when needed.
  • Lightweight & Standalone: Easily integrate this class into your projects without the overhead of a larger framework.

Install

composer require bermudaphp/reflection-type-matcher

Usage

    $reflector = new ReflectionFunction(static fn(int $a, int $b) => $a + $b);
    $param = $reflector->getParameters()[0];
        
    TypeMatcher::match($param->getType(), '22'); // true
    TypeMatcher::match($param->getType(), 22); // true
    TypeMatcher::match($param->getType(), '22', true); // false
    
    $reflector = new ReflectionFunction(static fn(A&B $arg) => $arg);
    $param = $reflector->getParameters()[0];
    
    TypeMatcher::match($param->getType(), new class implements A, B {}) // true
    TypeMatcher::match($param->getType(), new StdClass) // false
   

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固