thinframe / foundation
一组类,构成了所有 ThinFrame 组件的基础
v0.3.0
2014-05-26 16:26 UTC
Requires
- php: >=5.4.0
- danielstjules/stringy: 1.4.0
- phpcollection/phpcollection: 0.3.1
Requires (Dev)
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2024-09-24 00:39:57 UTC
README
#ThinFrame Foundation
是一个类集合,构成了所有 ThinFrame 组件的基础。
##索引
类型检查
主要类型的使用类型提示
示例用法
<?php
use ThinFrame\Foundation\Constant\DataType;
use ThinFrame\Foundation\Helper\TypeCheck;
function myAwesomeFunction($stringVariable, \Exception $exception, $boolVariable)
{
//if any of the above arguments doesn't respect the type an invalid argument exception will be thrown
TypeCheck::doCheck(DataType::STRING, DataType::SKIP, DataType::BOOLEAN);
}
如果任何函数参数与给定类型不匹配,将抛出 InvalidArgumentException
。参数类型按声明顺序指定(检查 ThinFrame\Foundation\Constants\DataType
以获取可能的数据类型。使用 DataType::SKIP
跳过参数的验证。
抽象枚举
PHP 的枚举实现。枚举使用常量定义,并且也可以实例化。
<?php
use ThinFrame\Foundation\DataType\AbstractEnum;
class WeekDay extends AbstractEnum
{
const MONDAY = 1;
const TUESDAY = 2;
const WEDNESDAY = 3;
const THURSDAY = 4;
const FRIDAY = 5;
const SATURDAY = 6;
const SUNDAY = 7;
}
//constructor will accept only valid enum values
$weekDay = new WeekDay(WeekDay::SUNDAY);
$weekDay->equals(WeekDay::SUNDAY); // true
$weekDay->equals(WeekDay::MONDAY); // false (captain obvious)
WeekDay::getMap(); //Map with enum key=>value pairs
WeekDay::isValid(5); //true
WeekDay::isValid(9); //false
WeekDay::type(); //callback that will validate a given enum value. Used for TypeCheck
###安装
- 通过 Composer:
"thinframe/foundation":"0.3.*"
###贡献者
- Sorin Badea sorin.badea91@gmail.com
###许可证
- MIT