本文整理汇总了PHP中Type::isSubtypeOf方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::isSubtypeOf方法的具体用法?PHP Type::isSubtypeOf怎么用?PHP Type::isSubtypeOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type::isSubtypeOf方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isAssignableFrom
/**
* Checks whether the provided type equals this type or is a subtype of this type.
*
* @param Type $type
* @return boolean
*/
public function isAssignableFrom(Type $type)
{
if ($type->getName() === $this->getName()) {
return true;
}
if (!$type instanceof ClassType) {
return false;
}
return $type->isSubtypeOf($this);
}
示例2: isAssignableFrom
/**
* Checks whether the provided type is either an interface that is equal to or extends this interface
* or is a class that implements this interface.
*
* @param Type $type
* @return boolean
*/
public function isAssignableFrom(Type $type)
{
if ($type->getName() === $this->getName()) {
return true;
}
if ($type instanceof InterfaceType) {
return $type->isSubtypeOf($this);
} else {
if ($type instanceof ClassType) {
return $type->isImplementorOf($this);
}
}
return false;
}
示例3: testTypeSubsets
public function testTypeSubsets()
{
$this->assertTrue(Type::isSubtypeOf("string", "string"));
$this->assertTrue(Type::isSubtypeOf("string", "scalar"));
$this->assertTrue(Type::isSubtypeOf("numeric", "scalar"));
$this->assertTrue(Type::isSubtypeOf("bool", "scalar"));
$this->assertFalse(Type::isSubtypeOf("array", "scalar"));
$this->assertFalse(Type::isSubtypeOf("object", "scalar"));
$this->assertTrue(Type::isSubtypeOf("array<string>", "array"));
$this->assertTrue(Type::isSubtypeOf("array<scalar>", "array"));
$this->assertTrue(Type::isSubtypeOf("array<string>", "array<scalar>"));
$this->assertTrue(Type::isSubtypeOf("array<numeric>", "array<numeric>"));
$this->assertFalse(Type::isSubtypeOf("array<scalar>", "array<string>"));
$this->assertFalse(Type::isSubtypeOf("array<numeric>", "array<string>"));
}
示例4: testTypeChecking
public function testTypeChecking()
{
$types = array('string' => 'hello', 'numeric' => 3, 'bool' => true, 'array' => array(3, 'hello', false, array(1, 2, 3)), 'array<string>' => array('one', 'two'), 'array<scalar>' => array(3, 'hello', false));
foreach ($types as $expect => $expect_value) {
foreach ($types as $got => $got_value) {
$msg = sprintf("Testing expect=%s vs got=%s", $expect, $got);
$validation = new Validator(array('arg' => $expect), array('arg' => $got_value));
$msg .= " " . implode(" ", $validation->getErrors());
if (Type::isSubtypeOf($got, $expect)) {
$this->assertTrue($validation->passes(), $msg);
} else {
if ($validation->passes()) {
//echo sprintf("%s is NOT a subtype of %s", $got, $expect);
$this->assertTrue($validation->fails(), $msg);
}
}
}
}
}