/**
  * {@inheritDoc}
  */
 public function generate($name)
 {
     if (!$this->isAbleToGenerate($name)) {
         throw new UnableToGenerateTypeOutlineException('Class type "' . $name . '" does not exist');
     }
     if (isset($this->loadedClasses[$name])) {
         return $this->loadedClasses[$name];
     }
     $classMeta = $this->classesConfig[$name];
     $parentClass = null;
     if (isset($classMeta['extend'])) {
         $parentClass = $this->schemaOutline->getTypeOutline($classMeta['extend']);
         if (!$parentClass instanceof ClassOutline) {
             $msg = 'Parent class "' . $classMeta['extend'] . '" must be a class outline instance';
             throw new UnableToGenerateTypeOutlineException($msg);
         }
     }
     $classOutline = new ClassOutline($name, array(), $parentClass);
     $this->loadedClasses[$name] = $classOutline;
     if (isset($classMeta['properties'])) {
         foreach ($classMeta['properties'] as $propertyName => $property) {
             $propertyOutline = new PropertyOutline($propertyName, $this->schemaOutline->getTypeOutline($property['type']));
             if (isset($property['default'])) {
                 $propertyOutline->setDefaultValue($property['default']);
             }
             if (isset($property['nullable'])) {
                 $propertyOutline->setIsNullable($property['nullable']);
             }
             $classOutline->addProperty($propertyOutline);
         }
     }
     unset($this->loadedClasses[$name]);
     return $classOutline;
 }
Ejemplo n.º 2
0
 public function testAddProperty()
 {
     $property = new PropertyOutline('property', $this->type);
     $this->assertMethodChaining($this->object->addProperty($property), 'addProperty');
     $this->assertEquals(array('property' => $property), $this->object->getProperties());
 }
 public function testProperHandlingOfCircularReferences()
 {
     $user = new ClassOutline('User');
     $admin = new ClassOutline('Admin');
     $user->addProperty(new PropertyOutline('admin', $admin));
     $admin->addProperty(new PropertyOutline('user', $user));
     $this->classMap->registerClass('User', 'User')->registerClass('Admin', 'Admin');
     $userType = $this->object->generate($user, $this->implementation);
     $properties = $userType->getProperties();
     $adminType = $properties['admin']->getType();
     $properties = $adminType->getProperties();
     $this->assertSame($userType, $properties['user']->getType());
 }