本文整理汇总了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()));
}
}
示例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;
}
示例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);
}
}
示例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));
}
}
}
示例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;
}
示例6: wildcard_types_cannot_be_instantiated
public function wildcard_types_cannot_be_instantiated()
{
Type::forName('net.xp_framework.unittest.core.generics.Nullable<?>')->newInstance();
}
示例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)];
}
示例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]) {
示例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);
}
示例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]')));
}
示例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;
}
}
示例12: typeForName
public function typeForName()
{
$this->assertInstanceOf(MapType::class, Type::forName('[:string]'));
}
示例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));
}
示例14: nullable_type
public function nullable_type()
{
$this->assertEquals(XPClass::forName('lang.Object'), Type::forName('?lang\\Object'));
}
示例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());
}