appserver-io/lang
Composer 安装命令:
composer require appserver-io/lang
包简介
Lang package implementation providing basic PHP datatypes.
README 文档
README
Introduction
This package provides implementation of basic PHP datatypes.
Issues
In order to bundle our efforts we would like to collect all issues regarding this package in the main project repository's issue tracker.
Please reference the originating repository as the first element of the issue title e.g.:
[appserver-io/<ORIGINATING_REPO>] A issue I am having
Usage
This package provides classes representing an object oriented implementation for some basic datatypes.
As there has been (and still are) many discussions about PHP and type safety i decided to implement a small, really basic library that will offer the most basic datatype needed in nearly every project. To be honest, I really like almost all of those nice possibilities languages like Java provides, but as PHP is not Java, you always have to find a neat way to implement similar things in a way that makes sense in a PHP environment.
The intention for implementing those classes was the possibility to make your critical functions and methods Type-Safe, by using them for type hinting on one hand and the possibility to have a quick and easy to use kind of data validation mechanism on the other hand.
As you may know, using type hints will probably slow down your code a bit, so take care when you use them and always have an eye on possible performance impacts by running performance tests regularly.
The data type implementations this library will provide, are
- Objct
- Boolean
- Integer
- Flt
- Strng
The following examples wil give you a short introduction about the functionality each class will provide and how you can use it in your code. Please be aware, that the examples are not intended to make any sense, they should only give you an idea what is possible.
Objct (Object before version 5.0)
The abstract class Objct implements a low level presentation of a class. All other classes of this library use it
as superclass.
Boolean
Using a Boolean instance to compare against another one or try to instantiate it with a not boolean value.
// initialize a new Integer instance $bool = new Boolean(true); $bool->equals(new Boolean(false)); // false // throws a ClassCastException $invalid = new Boolean('aValue');
Integer
Here are some examples how you can use the Integer class
// initialize a new Integer instance $int = new Integer(17); // get the float value of the Integer echo $int->floatValue() . PHP_EOL; // 17.0 echo $int->stringValue() . PHP_EOL; // '17' // check that the two Integer instances are equal $int->equals(Integer::valueOf(new String('17'))); // true
Flt (Float before version 3.0)
The example for using a Flt shows you how to add to instances
and print the float value
// initialize a new Float instance $float = new Flt(10.005); $float->add(new Flt(10.105)); // check the value echo $float->floatValue() . PHP_EOL; // 20.11
Strng (String before version 3.0)
To show you how you can use the Strng class we'll simple concatenate
to instances
// initialize a new String instance $string = new Strng('value to'); // check that String was successfully concatenated echo $string->concat(new Strng(' search')) . PHP_EOL; // 'value to search'
Yeah, this are really simple examples, and as i told you before in most cases i'll use that classes for simple things like type hints and so on.
If you like to use that stuff also, feel free to implement your own types and send me a pull request :)
External Links
- Documentation at appserver.io
appserver-io/lang 适用场景与选型建议
appserver-io/lang 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.43k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2014 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「basic datatypes objects boolean string float integer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 appserver-io/lang 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 appserver-io/lang 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 appserver-io/lang 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP library defining the DataTypes\DataType class of which instances represent a type of value, such as "positive integer" or "percentage".
ZN Framework Datatypes Package
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
Provides Symfony param converters for mediagone/types-common package.
This package provides all of CFX's public data objects.
redis log extension of yii2
统计信息
- 总下载量: 14.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 29
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: OSL-3.0
- 更新时间: 2014-11-21