当前位置: 首页>>代码示例>>PHP>>正文


PHP Type::isSubtypeOf方法代码示例

本文整理汇总了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);
 }
开发者ID:Kaemmelot,项目名称:php-type-reflection,代码行数:16,代码来源:ClassType.php

示例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;
 }
开发者ID:Kaemmelot,项目名称:php-type-reflection,代码行数:21,代码来源:InterfaceType.php

示例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>"));
 }
开发者ID:dsopiarz,项目名称:wp-advanced-search,代码行数:15,代码来源:TestType.php

示例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);
                 }
             }
         }
     }
 }
开发者ID:dsopiarz,项目名称:wp-advanced-search,代码行数:19,代码来源:TestValidator.php


注:本文中的Type::isSubtypeOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。