/**
  * @param string $info
  *
  * @return Type|null
  */
 public function parseSimpleTypes($info)
 {
     $type = new Type();
     if (isset(static::$types[$info])) {
         $type->setType(static::$types[$info]);
         $type->setCollection('array' === $info);
         return $type;
     }
     if (class_exists($info, true)) {
         $class = new \ReflectionClass($info);
         $collection = $class->implementsInterface('HH\\Collection');
         $type->setType('object');
         $type->setClass($info);
         $type->setCollection($collection);
         return $type;
     }
 }
Example #2
0
 public function testConstruct()
 {
     $type = new Type('object', true, 'ArrayObject', true, new Type('int'), new Type('string'));
     $this->assertEquals(Type::BUILTIN_TYPE_OBJECT, $type->getBuiltinType());
     $this->assertTrue($type->isNullable());
     $this->assertEquals('ArrayObject', $type->getClassName());
     $this->assertTrue($type->isCollection());
     $collectionKeyType = $type->getCollectionKeyType();
     $this->assertInstanceOf('PropertyInfo\\Type', $collectionKeyType);
     $this->assertEquals(Type::BUILTIN_TYPE_INT, $collectionKeyType->getBuiltinType());
     $collectionValueType = $type->getCollectionValueType();
     $this->assertInstanceOf('PropertyInfo\\Type', $collectionValueType);
     $this->assertEquals(Type::BUILTIN_TYPE_STRING, $collectionValueType->getBuiltinType());
 }
 /**
  * @param string $info
  *
  * @return array|Type[]|null
  */
 public function parse($info)
 {
     $type = new Type();
     if ('double' === $info) {
         $type->setType('float');
         return [$type];
     }
     if ('array' === $info) {
         $type->setType('array');
         $type->setCollection(true);
         return [$type];
     }
     if (class_exists($info)) {
         $type->setType('object');
         $type->setClass($info);
         $type->setCollection(true);
         return [$type];
     }
     if (null !== $info) {
         $type->setType($info);
         return [$type];
     }
 }
 public function extractTypes(\ReflectionProperty $reflectionProperty)
 {
     $className = $reflectionProperty->getDeclaringClass()->getName();
     try {
         $metadata = $this->classMetadataFactory->getMetadataFor($className);
     } catch (MappingException $exception) {
         return;
     }
     $type = new Type();
     $propertyName = $reflectionProperty->getName();
     if ($metadata->hasAssociation($propertyName)) {
         $class = $metadata->getAssociationTargetClass($propertyName);
         if ($metadata->isSingleValuedAssociation($propertyName)) {
             $type->setCollection(false);
             $type->setType('object');
             $type->setClass($class);
         } else {
             $type->setCollection(true);
             $type->setType('object');
             $type->setClass('Doctrine\\Common\\Collections\\Collection');
             $collectionType = new Type();
             $collectionType->setCollection(false);
             $collectionType->setType('object');
             $collectionType->setClass($class);
             $type->setCollectionType($collectionType);
         }
         return [$type];
     }
     if ($metadata->hasField($propertyName)) {
         $typeOfField = $metadata->getTypeOfField($propertyName);
         switch ($typeOfField) {
             case 'date':
                 // No break
             // No break
             case 'datetime':
                 // No break
             // No break
             case 'datetimetz':
                 // No break
             // No break
             case 'time':
                 $type->setType('object');
                 $type->setClass('DateTime');
                 $type->setCollection(false);
                 return [$type];
             case 'array':
                 // No break
             // No break
             case 'simple_array':
                 // No break
             // No break
             case 'json_array':
                 $type->setType('array');
                 $type->setCollection(true);
                 return [$type];
             default:
                 $type->setType($this->getPhpType($typeOfField));
                 $type->setCollection(false);
                 return [$type];
         }
     }
 }
 /**
  * Populates type.
  *
  * @param Type   $type
  * @param string $docType
  */
 private function populateType(Type $type, $docType)
 {
     if (isset(self::$nativeTypes[$docType])) {
         $type->setType($docType);
         return;
     }
     $type->setType('object');
     $type->setClass(substr($docType, 1));
 }
 /**
  * Returns the resource associated with the given type or null.
  *
  * @param Type $type
  *
  * @return ResourceInterface|null
  */
 public function getResourceFromType(Type $type)
 {
     if ('object' === $type->getType() && ($class = $type->getClass()) && ($resource = $this->resourceCollection->getResourceForEntity($class))) {
         return $resource;
     }
 }