コード例 #1
0
 private function initialize()
 {
     $this->initialized = true;
     $parseResult = DocBlockParser::parsePropertyDocBlock($this->reflector);
     $this->description = $parseResult->description;
     $resolver = new Helper\ParserClassNameResolver($this->getDeclaringType()->getName());
     $this->type = Type::of($parseResult->type, $resolver);
 }
コード例 #2
0
 public function testUnionType()
 {
     $fooInterface = Type::of("Hediet\\Types\\Test\\FooInterface");
     $foo = Type::of("Hediet\\Types\\Test\\Foo");
     $fooOrFooInterface = Type::ofUnion(array($fooInterface, $foo));
     $this->assertTrue($fooOrFooInterface->equals($fooInterface));
     $this->assertTrue(Type::ofUnion(array($fooInterface, Type::ofBoolean()))->isAssignableFrom($foo));
     $this->assertTrue(Type::ofUnion(array($fooInterface, Type::ofBoolean()))->isAssignableFrom(Type::ofBoolean()));
     $this->assertFalse(Type::ofUnion(array($foo, Type::ofBoolean()))->isAssignableFrom($fooInterface));
     $this->assertFalse(Type::ofUnion(array($foo, Type::ofBoolean()))->isAssignableFrom(Type::ofUnion(array($foo, Type::ofBoolean(), Type::ofNull()))));
     $this->assertTrue(Type::ofUnion(array($foo, Type::ofBoolean(), Type::ofNull()))->isAssignableFrom(Type::ofUnion(array(Type::ofBoolean(), $foo))));
 }
コード例 #3
0
 /**
  * @param ReflectionParameter $parameter
  * @return Type
  */
 function __internal_getParameterType(ReflectionParameter $parameter)
 {
     if (!isset($this->parameterTypeCache[$parameter->name])) {
         if (!$this->initialized) {
             $this->initialize();
         }
         if (isset($this->parseResult->parameter[$parameter->getName()])) {
             $typeStr = $this->parseResult->parameter[$parameter->getName()]->type;
             $type = Type::of($typeStr, $this->resolver);
         } else {
             $typeHintedClass = $parameter->getClass();
             if ($typeHintedClass !== null) {
                 $type = Type::byReflectionClass($typeHintedClass);
             } else {
                 $type = Type::ofMixed();
             }
             if ($parameter->allowsNull()) {
                 $type = Type::ofNullable($type);
             }
         }
         $this->parameterTypeCache[$parameter->name] = $type;
     }
     return $this->parameterTypeCache[$parameter->name];
 }