/** * Returns all types * * @return var[] */ public function types() { return array($this->getClass(), Type::$VAR, Type::$VOID, \lang\Primitive::$BOOLEAN, \lang\Primitive::$STRING, \lang\Primitive::$INT, \lang\Primitive::$DOUBLE, \lang\ArrayType::forName('var[]'), \lang\MapType::forName('[:var]')); }
public function form_deserialize() { $req = new MemoryInputStream('name=Timm'); $v = RestFormat::$FORM->read($req, \lang\MapType::forName('[:string]')); $this->assertEquals(array('name' => 'Timm'), $v); }
public function cast_raises_exceptions_for_non_arrays($value) { MapType::forName('[:var]')->cast($value); }
public function genericReturnValue() { $this->assertEquals('[:lang.Object]', $this->fixture->getMethod('getMap')->getReturnTypeName()); $this->assertEquals(\lang\MapType::forName('[:lang.Object]'), $this->fixture->getMethod('getMap')->getReturnType()); }
public function varMapAssignableFromIntMap() { $this->assertFalse(MapType::forName('[:var]')->isAssignableFrom('[:int]')); }
public function mapFieldType() { $this->assertEquals(MapType::forName('[:lang.Object]'), $this->fixture->getField('map')->getType()); }
public function intMap() { $this->assertEquals(MapType::forName('[:var]'), typeof(['one' => 1, 'two' => 2, 'three' => 3])); }
public function intMap() { $this->assertEquals(\lang\MapType::forName('[:var]'), typeof(array('one' => 1, 'two' => 2, 'three' => 3))); }
function typeof($arg) { if ($arg instanceof \lang\Generic) { return new \lang\XPClass($arg); } else { if (null === $arg) { return \lang\Type::$VOID; } else { if ($arg instanceof \Closure) { $r = new \ReflectionFunction($arg); $signature = []; foreach ($r->getParameters() as $param) { if ($param->isArray()) { $signature[] = \lang\Primitive::$ARRAY; } else { if ($param->isCallable()) { $signature[] = \lang\Primitive::$CALLABLE; } else { if (null === ($class = $param->getClass())) { $signature[] = \lang\Type::$VAR; } else { $signature[] = new \lang\XPClass($class); } } } } return new \lang\FunctionType($signature, \lang\Type::$VAR); } else { if (is_array($arg)) { return 0 === key($arg) ? \lang\ArrayType::forName('var[]') : \lang\MapType::forName('[:var]'); } else { return \lang\Type::forName(gettype($arg)); } } } } }
public function mapOfString() { $this->assertEquals(MapType::forName('[:string]'), Type::forName('[:string]')); }
public function unmarshal_map_of_issues() { $issue1 = new IssueWithField(1, 'test1'); $issue2 = new IssueWithField(2, 'test2'); $this->assertEquals(['one' => $issue1, 'two' => $issue2], $this->fixture->unmarshal(MapType::forName('[:' . nameof($issue1) . ']'), ['one' => ['issue_id' => 1, 'title' => 'test1'], 'two' => ['issue_id' => 2, 'title' => 'test2']])); }