예제 #1
0
 public function function_with_class_hint()
 {
     $this->assertEquals(FunctionType::forName('function(lang.Type): var'), typeof(function (Type $t) {
     }));
 }
예제 #2
0
 static function __static()
 {
     self::$MAP = FunctionType::forName('function(var): var');
     self::$HANDLE = FunctionType::forName('function(?): var');
 }
예제 #3
0
function is($type, $object)
{
    if (null === $type) {
        return $object instanceof __null;
    } else {
        if ('int' === $type) {
            return is_int($object);
        } else {
            if ('double' === $type) {
                return is_double($object);
            } else {
                if ('string' === $type) {
                    return is_string($object);
                } else {
                    if ('bool' === $type) {
                        return is_bool($object);
                    } else {
                        if ('var' === $type) {
                            return true;
                        } else {
                            if (0 === strncmp($type, 'function(', 9)) {
                                return \lang\FunctionType::forName($type)->isInstance($object);
                            } else {
                                if (0 === substr_compare($type, '[]', -2)) {
                                    return (new \lang\ArrayType(substr($type, 0, -2)))->isInstance($object);
                                } else {
                                    if (0 === substr_compare($type, '[:', 0, 2)) {
                                        return (new \lang\MapType(substr($type, 2, -1)))->isInstance($object);
                                    } else {
                                        if (0 === strncmp($type, '(function(', 10)) {
                                            return \lang\FunctionType::forName(substr($type, 1, -1))->isInstance($object);
                                        } else {
                                            if (strstr($type, '|')) {
                                                return \lang\TypeUnion::forName($type)->isInstance($object);
                                            } else {
                                                if (strstr($type, '?')) {
                                                    return \lang\WildcardType::forName($type)->isInstance($object);
                                                } else {
                                                    $literal = literal($type);
                                                    return $object instanceof $literal;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
예제 #4
0
 public function new_instance_of_invokeable()
 {
     $type = new FunctionType([Type::$VAR], Type::$VAR);
     $inv = new FunctionTypeInvokeable();
     $this->assertInstanceOf('Closure', $type->newInstance($inv));
 }