本文整理汇总了PHP中PhutilTypeSpec::getTypeOf方法的典型用法代码示例。如果您正苦于以下问题:PHP PhutilTypeSpec::getTypeOf方法的具体用法?PHP PhutilTypeSpec::getTypeOf怎么用?PHP PhutilTypeSpec::getTypeOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhutilTypeSpec
的用法示例。
在下文中一共展示了PhutilTypeSpec::getTypeOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetTypeOf
public function testGetTypeOf()
{
$map = array('int' => 1, 'string' => 'asdf', 'float' => 1.5, 'bool' => true, 'null' => null, 'map<wild, wild>' => array(), 'list<string>' => array('a', 'b'), 'list<int>' => array(1, 2, 3), 'map<string, int>' => array('x' => 3), 'map<int, list<string>>' => array(1 => array('x', 'y')), 'stdClass' => new stdClass(), 'list<Exception>' => array(new Exception(), new LogicException(), new RuntimeException()), 'map<string, stdClass>' => array('x' => new stdClass()));
foreach ($map as $expect => $input) {
$this->assertEqual($expect, PhutilTypeSpec::getTypeOf($input), print_r($input, true));
PhutilTypeSpec::newFromString($expect)->check($input);
}
}
示例2: __construct
public function __construct(PhutilTypeSpec $type, $value, $name = null, $err = null)
{
if ($name !== null) {
$invalid = pht("Parameter '%s' has invalid type.", $name);
} else {
$invalid = pht("Parameter has invalid type.");
}
if ($type->getType() == 'regex') {
if (is_string($value)) {
$message = pht("Expected a regular expression, but '%s' is not valid: %s", $value, $err);
} else {
$message = pht("Expected a regular expression, but value is not valid: %s", $err);
}
} else {
$message = pht("Expected type '%s', got type '%s'.", $type->toString(), PhutilTypeSpec::getTypeOf($value));
}
parent::__construct($invalid . ' ' . $message);
}