定制 tdn/php-types 二次开发

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

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

tdn/php-types

最新稳定版本:2.0.1

Composer 安装命令:

composer require tdn/php-types

包简介

Php primitive wrappers lib.

README 文档

README

Dependency Status GitHub issues Total Downloads License Latest Stable Version Scrutinizer Code Quality Travis Coverage Status SensioLabsInsight

PhpTypes

Types

  • StringType
  • BooleanType
  • IntType*
  • FloatType*
  • DateTime
  • Collection

* Smart use of bcmath or gmp if they are installed.

Wait, what is this?

Primitive wrappers for PHP with boxing/unboxing. (strong types even on reassignment like SPL_Types).

Uses the most popular* libs available in the PHP landscape and neatly wraps them in a single repo, providing decorators with extra features.

This is an attempt to create something close to Java core libs for PHP, unfortunately no context casting or even primitive type casting magic methods** but damn close.

* Based on opinion but backed by packagist downloads =)

** RFCs for boxing and type casting methods that never got accepted [1, 2]

Type Credits
Doctrine Collections & Doctrine Inflector Doctrine Stringy
LOL! why?!

Many reasons!

  • Lack of core primitive wrappers: The underlying libraries (carbon, stringy, doctrine collections & inflector) are all extremely popular. It would be cool to have a core library built into the language with an interface like these.
  • Fluent/Consistent interfaces: Our beloved PHP is infamous for flipping arguments in array and string functions.
  • Because why not? Seemed fun to code.

The library is fully functional, but this is mainly a CONCEPT. Primitives will always yield higher performance than objects.

Examples/Explanation

More examples located at example.php

/** @var StringType $string */
StringType::box($string, 'foo');
echo $string; // foo
$string = 'bar is fun'; //Remains boxed as instance of StringType.
echo $string->dasherize(); // bar-is-fun

try {
    //Throws "TypeError" exception.
    $string = false;
} catch (\TypeError $e) {
    ....
}

Documentation

Requirements

PHP 7.0 or above.

Installation

Using CLI:

php composer.phar require tdn/php-types:*@stable

In the composer.json file:

{
    "require": {
        "tdn/php-types": "*@stable"
    }
}
API

Please checkout the online API or clone repo and run vendor/bin/robo documentation:build to build local documentation.

Contributing

If you want to contribute, please read the CONTRIBUTING.

License

This library is released under the MIT license. See the complete license in the LICENSE file.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-21