예제 #1
0
 /**
  * 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]'));
 }
예제 #2
0
 public function intArray()
 {
     $this->assertEquals(ArrayType::forName('var[]'), typeof([1, 2, 3]));
 }
예제 #3
0
 public function arrayComponentType()
 {
     $this->assertEquals(ArrayType::forName('int[]'), MapType::forName('[:int[]]')->componentType());
 }
예제 #4
0
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));
                }
            }
        }
    }
}
예제 #5
0
 public function intArray()
 {
     $this->assertEquals(\lang\ArrayType::forName('var[]'), typeof(array(1, 2, 3)));
 }
 public function varArrayAssignableFromIntArray()
 {
     $this->assertFalse(ArrayType::forName('var[]')->isAssignableFrom('int[]'));
 }
 public function varArgsArrayType()
 {
     $this->assertEquals(\lang\ArrayType::forName('string[]'), $this->methodParameter('printf', 1)->getType());
 }
예제 #8
0
 public function arrayOfString()
 {
     $this->assertEquals(ArrayType::forName('string[]'), Type::forName('string[]'));
 }
 public function unmarshal_array_of_money()
 {
     $this->fixture->addMarshaller('util.Money', self::$moneyMarshaller);
     $this->assertEquals([new Money(6.1, Currency::$USD)], $this->fixture->unmarshal(ArrayType::forName('util.Money[]'), ['6.10 USD']));
 }
예제 #10
0
 public function cast_raises_exceptions_for_non_arrays($value)
 {
     ArrayType::forName('var[]')->cast($value);
 }