public function map_of_issues() { $issue1 = new net·xp_framework·unittest·webservices·rest·IssueWithField(1, 'test1'); $issue2 = new net·xp_framework·unittest·webservices·rest·IssueWithField(2, 'test2'); $this->assertEquals(array('one' => $issue1, 'two' => $issue2), $this->fixture->convert(MapType::forName('[:' . $issue1->getClassName() . ']'), array('one' => array('issue_id' => 1, 'title' => 'test1'), 'two' => array('issue_id' => 2, 'title' => 'test2')))); }
public function form_deserialize() { $req = new MemoryInputStream('name=Timm'); $v = RestFormat::$FORM->read($req, MapType::forName('[:string]')); $this->assertEquals(array('name' => 'Timm'), $v); }
public function genericReturnValue() { $this->assertEquals('[:lang.Object]', $this->fixture->getMethod('getMap')->getReturnTypeName()); $this->assertEquals(MapType::forName('[:lang.Object]'), $this->fixture->getMethod('getMap')->getReturnType()); }
public function mapOfString() { $this->assertEquals(MapType::forName('[:string]'), Type::forName('[:string]')); }
public function intMap() { $this->assertEquals(MapType::forName('[:var]'), typeof(array('one' => 1, 'two' => 2, 'three' => 3))); }
/** * @return string the Type text display for the current account */ public function getTypeText() { $accountTypeRecord = MapType::model()->findByAttributes(array('id' => $this->type_id)); return $accountTypeRecord->name; }
public function varMapAssignableFromIntMap() { $this->assertFalse(MapType::forName('[:var]')->isAssignableFrom('[:int]')); }
public function cast_raises_exceptions_for_non_arrays($value) { MapType::forName('[:var]')->cast($value); }
function typeof($arg) { if ($arg instanceof Generic) { return $arg->getClass(); } else { if (NULL === $arg) { return Type::$VOID; } else { if (is_array($arg)) { return 0 === key($arg) ? ArrayType::forName('var[]') : MapType::forName('[:var]'); } else { return Type::forName(gettype($arg)); } } } }
public function mapOfStringDeprecatedSyntax() { $this->assertEquals(MapType::forName('[:string]'), Type::forName('array<string, string>')); }
/** * Gets a type for a given name * * Checks for: * <ul> * <li>Primitive types (string, integer, double, boolean, array)</li> * <li>Array notations (string[] or string*)</li> * <li>Resources</li> * <li>Any type (var or *)</li> * <li>Generic notations (util.collections.HashTable<lang.types.String, lang.Generic>)</li> * <li>Anything else will be passed to XPClass::forName()</li> * </ul> * * @param string name * @return lang.Type */ public static function forName($name) { static $deprecated = array('char' => 'string', 'integer' => 'int', 'boolean' => 'bool', 'float' => 'double', 'mixed' => 'var', '*' => 'var', 'array' => 'var[]', 'resource' => 'var'); static $primitives = array('string' => TRUE, 'int' => TRUE, 'double' => TRUE, 'bool' => TRUE); // Map deprecated type names $type = isset($deprecated[$name]) ? $deprecated[$name] : $name; // Map well-known primitives, var and void, handle rest syntactically: // * T[] is an array // * [:T] is a map // * T* is a vararg // * T<K, V> is a generic // * Anything else is a qualified or unqualified class name if (isset($primitives[$type])) { return Primitive::forName($type); } else { if ('var' === $type) { return self::$VAR; } else { if ('void' === $type) { return self::$VOID; return $type; } else { if ('[]' === substr($type, -2)) { return ArrayType::forName($type); } else { if ('[:' === substr($type, 0, 2)) { return MapType::forName($type); } else { if ('*' === substr($type, -1)) { return ArrayType::forName(substr($type, 0, -1) . '[]'); } else { if (FALSE === ($p = strpos($type, '<'))) { return strstr($type, '.') ? XPClass::forName($type) : new XPClass($type); } } } } } } } // Generics // * D<K, V> is a generic type definition D with K and V componenty // * Deprecated: array<T> is T[], array<K, V> is [:T] $base = substr($type, 0, $p); $components = self::forNames(substr($type, $p + 1, -1)); if ('array' !== $base) { return cast(self::forName($base), 'lang.XPClass')->newGenericType($components); } $s = sizeof($components); if (2 === $s) { return MapType::forName('[:' . $components[1]->name . ']'); } else { if (1 === $s) { return ArrayType::forName($components[0]->name . '[]'); } } throw new IllegalArgumentException('Unparseable name ' . $name); }