marcin-orlowski/type-asserts 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

marcin-orlowski/type-asserts

最新稳定版本:2.0.0

Composer 安装命令:

composer require marcin-orlowski/type-asserts

包简介

Data type assertions.

README 文档

README

Latest Stable Version License

PHP Data type assertions.

This package provides helper methods to validate variable data type. While there are handy native methods like is_string() or is_array(), you can have then check for single type at a time. This package allows to validate against type union (i.e. STRING|INT) or ensure that priovided string refers to existing class. Also, contrary to native methods, if there's no match and variable contains data of non-welcomed type, exception is thrown which lets you simplify your code flow.

Installation

composer require --dev marcin-orlowski/type-asserts

Usage example

The following code ensures $var is of either int or float type before math is done:

use MarcinOrlowski\TypeAsserts\Type;
use MarcinOrlowski\TypeAsserts\Validator;

$var = 'foo';

Validator::assertIsType($var, [Type::INT, Type::FLOAT]);
$result = $var * 5;

The following code ensures $var refers to existing class, before we try to instantiate it:

use MarcinOrlowski\TypeAsserts\Type;
use MarcinOrlowski\TypeAsserts\Validator;

$cls = 'non-existing';

Validator::assertIsType($cls, Type::EXISTING_CLASS);
$obj = new $cls;

License

  • Written and copyrighted ©2014-2022 by Marcin Orlowski
  • Open-sourced software licensed under the MIT license

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固