jojo1981/php-types
Composer 安装命令:
composer require jojo1981/php-types
包简介
PHP types library which contains value classes which represent the php types
关键字:
README 文档
README
Author: Joost Nijhuis <jnijhuis81@gmail.com>
This library has some value classes which represent a PHP type.
These value classes can be constructed based on the PHP type name or based on a value.
There are 2 pseudo type classes: Jojo1981\PhpTypes\MixedType and Jojo1981\PhpTypes\MultiType which will function as composite.
Also, an abstract factory class is included: Jojo1981\PhpTypes\AbstractType.
The following types are supported, with their aliases:
- array
- bool (boolean)
- callable (callback)
- class
- float (number, real, double)
- int (integer)
- iterable
- null
- object
- resource
- string (text)
- void
Pseudo types:
- mixed
- multi
Installation
Library
git clone https://github.com/jojo1981/php-types.git
Composer
composer require jojo1981/php-types
Basic usage
<?php require 'vendor/autoload.php'; $integerType = \Jojo1981\PhpTypes\AbstractType::createFromTypeName('int'); $integerType->isAssignableValue('text'); // will return false $integerType->isAssignableValue(28); // will return true $floatType1 = \Jojo1981\PhpTypes\AbstractType::createFromValue(5.0); $floatType1->isAssignableValue(true); // will return false $floatType1->isAssignableValue('text'); // will return false $floatType1->isAssignableValue(10); // will return false $floatType1->isAssignableValue(10.0); // will return true $floatType2 = \Jojo1981\PhpTypes\AbstractType::createFromTypeName('number'); $floatType2->isAssignableValue(true); // will return false $floatType2->isAssignableValue('text'); // will return false $floatType2->isAssignableValue(1); // will return false $floatType2->isAssignableValue(1.0); // will return true $stringType = \Jojo1981\PhpTypes\AbstractType::createFromValue('string'); $stringType->isAssignableValue(true); // will return false $stringType->isAssignableValue('text'); // will return true // Other types: array, bool, callable, iterable, null, resource, void // Object | Class types $objectType = \Jojo1981\PhpTypes\AbstractType::createFromTypeName('object'); $objectType->isAssignableValue(true); // will return false $objectType->isAssignableValue(new \stdClass()); // will return true $objectType->isAssignableValue(new \Jojo1981\PhpTypes\TestSuite\Fixture\TestEntity()); // will return true (for all object types) $classType1 = \Jojo1981\PhpTypes\AbstractType::createFromValue(new \Jojo1981\PhpTypes\TestSuite\Fixture\TestEntity()); $classType1->isAssignableValue(new \stdClass()); // will return false $classType1->isAssignableValue(new \Jojo1981\PhpTypes\TestSuite\Fixture\TestEntity()); // will return true $classType2 = \Jojo1981\PhpTypes\AbstractType::createFromTypeName(\Jojo1981\PhpTypes\TestSuite\Fixture\TestEntity::class); $classType2->isAssignableValue(new \stdClass()); // will return false $classType2->isAssignableValue(new \Jojo1981\PhpTypes\TestSuite\Fixture\TestEntityBase); // will return false $classType2->isAssignableValue(new \Jojo1981\PhpTypes\TestSuite\Fixture\TestEntity()); // will return true $classType3 = \Jojo1981\PhpTypes\AbstractType::createFromTypeName(\Jojo1981\PhpTypes\TestSuite\Fixture\InterfaceTestEntity::class); $classType3->isAssignableValue(new \stdClass()); // will return false $classType3->isAssignableValue(new \Jojo1981\PhpTypes\TestSuite\Fixture\TestEntityBase); // will return true $classType3->isAssignableValue(new \Jojo1981\PhpTypes\TestSuite\Fixture\TestEntity()); // will return true // Pseudo types $mixedType = \Jojo1981\PhpTypes\AbstractType::createFromTypeName('mixed'); $mixedType->isAssignableValue(null); // will return true (always) $mixedType->isPseudoType(); // will return true $multiType = \Jojo1981\PhpTypes\AbstractType::createFromTypes([$stringType, $integerType]); $multiType->isAssignableValue(true); // will return false $multiType->isAssignableValue('text'); // will return true $multiType->isAssignableValue(28); // will return true $multiType->isPseudoType(); // will return true
jojo1981/php-types 适用场景与选型建议
jojo1981/php-types 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.32k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「validation」 「type」 「types」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jojo1981/php-types 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jojo1981/php-types 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jojo1981/php-types 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A bundle providing fields for image upload with jquery upload and image cropping with jcrop for symfony2
A simple Symfony bundle that adds boolean form field type.
Data type classes for PHP
Easily switch between entry types in entries section
A PHP Abstract Enum Class
This package provides type-safe extension of the laravel collection, forcing a single type of object.
统计信息
- 总下载量: 19.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-07