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


PHP Type::forName方法代码示例

本文整理汇总了PHP中Type::forName方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::forName方法的具体用法?PHP Type::forName怎么用?PHP Type::forName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type::forName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleStatus

 /**
  * Handle status
  *
  * @param   int code
  * @throws  webservices.rest.RestException
  */
 protected function handleStatus($code)
 {
     if ($code > 399) {
         // TODO: $type= this($this->response->header('Content-Type'), 0);
         $e = $this->deserializer->deserialize($this->input, Type::forName('[:var]'));
         throw new CustomRestException($e, new RestException($code . ': ' . $this->response->message()));
     }
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:14,代码来源:CustomRestResponse.class.php

示例2: getType

 /**
  * Gets field type
  *
  * @return  lang.Type
  */
 public function getType()
 {
     if ($details = XPClass::detailsForField($this->_reflect->getDeclaringClass()->getName(), $this->_reflect->getName())) {
         if (isset($details[DETAIL_ANNOTATIONS]['type'])) {
             return Type::forName($details[DETAIL_ANNOTATIONS]['type']);
         }
     }
     return Type::$VAR;
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:14,代码来源:Field.class.php

示例3: getType

 /**
  * Get parameter's type.
  *
  * @return  lang.Type
  */
 public function getType()
 {
     if ($c = $this->_reflect->getClass()) {
         return new XPClass($c);
     }
     if (!($details = XPClass::detailsForMethod($this->_details[0], $this->_details[1])) || !isset($details[DETAIL_ARGUMENTS][$this->_details[2]])) {
         // Unknown or unparseable, return ANYTYPE
         return Type::$VAR;
     }
     if ('self' === ($t = ltrim($details[DETAIL_ARGUMENTS][$this->_details[2]], '&'))) {
         return new XPClass($this->_details[0]);
     } else {
         return Type::forName($t);
     }
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:20,代码来源:Parameter.class.php

示例4: addMarshaller

 /**
  * Adds a type marshaller
  *
  * @param  var type either a full qualified type name or a type instance
  * @param  webservices.rest.TypeMarshaller m
  */
 public function addMarshaller($type, TypeMarshaller $m)
 {
     $keys = $this->marshallers->keys();
     // Add marshaller
     $t = $type instanceof Type ? $type : Type::forName($type);
     $this->marshallers[$t] = $m;
     // Iterate over map keys before having altered the map, checking for
     // any marshallers less specific than the added marshaller, and move
     // them to the end. E.g. if a marshaller for Dates is added, it needs
     // to be in the map *before* the one for for Objects!
     foreach ($keys as $type) {
         if ($type->isAssignableFrom($t)) {
             $this->marshallers->put($type, $this->marshallers->remove($type));
         }
     }
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:22,代码来源:RestContext.class.php

示例5: createMock

 /**
  * Builds a stub instance for the specified type.
  *
  * @param   string typeName
  * @param   boolean overrideAll
  * @return  lang.Object
  */
 public function createMock($typeName, $overrideAll = TRUE)
 {
     $type = Type::forName($typeName);
     if (!$type instanceof XPClass) {
         throw new IllegalArgumentException('Cannot mock other types than XPClass types.');
     }
     $parentClass = NULL;
     $interfaces = array(XPClass::forName('unittest.mock.IMock'));
     if ($type->isInterface()) {
         $interfaces[] = $type;
     } else {
         $parentClass = $type;
     }
     $proxy = new MockProxyBuilder();
     $proxy->setOverwriteExisting($overrideAll);
     $proxyClass = $proxy->createProxyClass(ClassLoader::getDefault(), $interfaces, $parentClass);
     $mock = $proxyClass->newInstance(new MockProxy());
     $this->mocks[] = $mock;
     return $mock;
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:27,代码来源:MockRepository.class.php

示例6: wildcard_types_cannot_be_instantiated

 public function wildcard_types_cannot_be_instantiated()
 {
     Type::forName('net.xp_framework.unittest.core.generics.Nullable<?>')->newInstance();
 }
开发者ID:xp-framework,项目名称:core,代码行数:4,代码来源:WildcardTypeTest.class.php

示例7: getMarshaller

 /**
  * Adds a type marshaller
  *
  * @param  var type either a full qualified type name or a type instance
  * @return webservices.rest.TypeMarshaller The added marshaller
  */
 public function getMarshaller($type)
 {
     return $this->marshallers[$type instanceof Type ? $type : Type::forName($type)];
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:10,代码来源:RestMarshalling.class.php

示例8: newType0


//.........这里部分代码省略.........
                         $src .= $tokens[$i][1] . ' ';
                     } else {
                         if (T_CLASS === $tokens[$i][0] || T_INTERFACE === $tokens[$i][0]) {
                             $meta['class'][DETAIL_GENERIC] = [$base->name, $arguments];
                             $src .= $tokens[$i][1] . ' ' . $decl;
                             array_unshift($state, $tokens[$i][0]);
                         } else {
                             if (T_USE === $tokens[$i][0]) {
                                 $i += 2;
                                 $use = '';
                                 while ((T_STRING === $tokens[$i][0] || T_NS_SEPARATOR === $tokens[$i][0]) && $i < $s) {
                                     $use .= $tokens[$i][1];
                                     $i++;
                                 }
                                 $imports[substr($use, strrpos($use, '\\') + 1)] = $use;
                                 $src .= 'use ' . $use . ';';
                             }
                         }
                     }
                     continue;
                 } else {
                     if (T_CLASS === $state[0]) {
                         if (T_EXTENDS === $tokens[$i][0]) {
                             $i += 2;
                             $parent = '';
                             while ((T_STRING === $tokens[$i][0] || T_NS_SEPARATOR === $tokens[$i][0]) && $i < $s) {
                                 $parent .= $tokens[$i][1];
                                 $i++;
                             }
                             $i--;
                             if (isset($annotations['generic']['parent'])) {
                                 $xargs = [];
                                 foreach (explode(',', $annotations['generic']['parent']) as $j => $placeholder) {
                                     $xargs[] = Type::forName(strtr(ltrim($placeholder), $placeholders));
                                 }
                                 $src .= ' extends \\' . $this->newType0($base->getParentClass(), $xargs);
                             } else {
                                 $src .= ' extends ' . $parent;
                             }
                         } else {
                             if (T_IMPLEMENTS === $tokens[$i][0]) {
                                 $src .= ' implements';
                                 $counter = 0;
                                 $annotation = @$annotations['generic']['implements'];
                                 array_unshift($state, T_CLASS);
                                 array_unshift($state, 5);
                             } else {
                                 if ('{' === $tokens[$i][0]) {
                                     array_shift($state);
                                     array_unshift($state, 1);
                                     $src .= ' { public static $__generic= [];';
                                     $initialize = true;
                                 }
                             }
                         }
                         continue;
                     } else {
                         if (T_INTERFACE === $state[0]) {
                             if (T_EXTENDS === $tokens[$i][0]) {
                                 $src .= ' extends';
                                 $counter = 0;
                                 $annotation = @$annotations['generic']['extends'];
                                 array_unshift($state, T_INTERFACE);
                                 array_unshift($state, 5);
                             } else {
                                 if ('{' === $tokens[$i][0]) {
开发者ID:xp-framework,项目名称:core,代码行数:67,代码来源:GenericTypes.class.php

示例9: isAssignableFrom

 /**
  * Tests whether this type is assignable from another type
  *
  * @param   var $type
  * @return  bool
  */
 public function isAssignableFrom($type)
 {
     $t = $type instanceof Type ? $type : Type::forName($type);
     return $t instanceof XPClass && $this->assignableFromClass($t);
 }
开发者ID:johannes85,项目名称:core,代码行数:11,代码来源:WildcardType.class.php

示例10: two_keyvalue_pairs

 public function two_keyvalue_pairs()
 {
     $this->assertEquals(array('name' => 'Timm', 'id' => '1549'), $this->fixture->deserialize($this->input('{ "name" : "Timm", "id" : "1549" }'), Type::forName('[:string]')));
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:4,代码来源:RestJsonDeserializerTest.class.php

示例11: isAssignableFrom

 /**
  * Tests whether this type is assignable from another type
  *
  * ```php
  * $union= TypeUnion::forName('int|string|lang.Throwable');
  *
  * // It's assignable to each of its components
  * $union->isAssignableFrom('int')                          // TRUE
  * $union->isAssignableFrom('string')                       // TRUE
  * $union->isAssignableFrom('lang.XPException')             // TRUE
  * $union->isAssignableFrom('bool')                         // FALSE
  *
  * // It's assignable to unions if the union consists completely
  * // of types assignable to types in this union.
  * $union->isAssignableFrom('int|string')                   // TRUE
  * $union->isAssignableFrom('int|lang.XPException')         // TRUE
  * $union->isAssignableFrom('int|string|lang.XPException')  // TRUE
  * $union->isAssignableFrom('int|bool')                     // FALSE
  * $union->isAssignableFrom('int|string|bool')              // FALSE
  * $union->isAssignableFrom('int|string|util.Date')         // FALSE
  * ```
  *
  * @param   var $from Either a type or a type name
  * @return  bool
  */
 public function isAssignableFrom($from)
 {
     $t = $from instanceof Type ? $from : Type::forName($from);
     if ($t instanceof self) {
         foreach ($t->types as $type) {
             if (!$this->isAssignableFrom($type)) {
                 return false;
             }
         }
         return true;
     } else {
         foreach ($this->types as $type) {
             if ($type->isAssignableFrom($t)) {
                 return true;
             }
         }
         return false;
     }
 }
开发者ID:johannes85,项目名称:core,代码行数:44,代码来源:TypeUnion.class.php

示例12: typeForName

 public function typeForName()
 {
     $this->assertInstanceOf(MapType::class, Type::forName('[:string]'));
 }
开发者ID:xp-framework,项目名称:core,代码行数:4,代码来源:MapTypeTest.class.php

示例13: isAssignableFrom

 /** Tests whether this type is assignable from another type */
 public function isAssignableFrom($type) : bool
 {
     return $this === ($type instanceof Type ? $type : Type::forName($type));
 }
开发者ID:xp-framework,项目名称:core,代码行数:5,代码来源:Primitive.class.php

示例14: nullable_type

 public function nullable_type()
 {
     $this->assertEquals(XPClass::forName('lang.Object'), Type::forName('?lang\\Object'));
 }
开发者ID:xp-framework,项目名称:core,代码行数:4,代码来源:HackLanguageSupportTest.class.php

示例15: customContent

 public function customContent()
 {
     $fixture = $this->fixtureWith(HttpConstants::STATUS_NO_CONTENT, '', array('Content-Type' => 'application/json'));
     $class = Type::forName('net.xp_framework.unittest.webservices.rest.CustomRestResponse');
     $response = $fixture->execute($class, new RestRequest());
     $this->assertInstanceOf($class, $response);
     $this->assertNull($response->data());
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:8,代码来源:RestClientExecutionTest.class.php


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