當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。