예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function exportClassMetadata(ClassMetadataInfo $metadata)
 {
     if (!$this->_entityGenerator) {
         throw new \RuntimeException('For the AnnotationExporter you must set an EntityGenerator instance with the setEntityGenerator() method.');
     }
     $this->_entityGenerator->setGenerateAnnotations(true);
     $this->_entityGenerator->setGenerateStubMethods(false);
     $this->_entityGenerator->setRegenerateEntityIfExists(false);
     $this->_entityGenerator->setUpdateEntityIfExists(false);
     return $this->_entityGenerator->generateEntityClass($metadata);
 }
 public function generateEntityClass(ClassMetadataInfo $metadata)
 {
     static::swap();
     $result = parent::generateEntityClass($metadata);
     static::swap();
     return $result;
 }
예제 #3
0
 public function generate($jsonSchema)
 {
     $schema = json_decode($jsonSchema, true);
     if (!isset($schema['type']) && $schema['type'] !== 'object') {
         throw new \RuntimeException("Unable to process the schema");
     }
     if (!isset($schema['title'])) {
         throw new \RuntimeException("title property must be defined");
     }
     // TODO investigate implementation via ClassMetadataBuilder
     $className = $schema['title'];
     $medatadata = new ClassMetadata($this->getNamespace() . '\\' . $className);
     if (isset($schema['properties'])) {
         foreach ($schema['properties'] as $name => $definition) {
             $type = $definition['type'];
             $nullable = isset($schema['required']) ? !in_array($name, $schema['required']) : true;
             $medatadata->mapField(['fieldName' => $name, 'type' => $type, 'nullable' => $nullable, 'options' => []]);
         }
     }
     $filename = sprintf("%s/%s/%s.php", $this->getPath(), join('/', explode('\\', $this->getNamespace())), $className);
     mkdir(dirname($filename), 0777, true);
     $generator = new EntityGenerator();
     $generator->setGenerateAnnotations(true);
     file_put_contents($filename, $generator->generateEntityClass($medatadata));
 }
예제 #4
0
 /**
  * @return bool
  * @throws \Exception
  */
 public function generateClass()
 {
     $metadata = $this->getMetaData();
     $this->setClassName($metadata->name);
     // setting the namespace
     $metadata->name = $this->getNamespace() . '\\' . $metadata->name;
     //generate the basic class-code
     if (!($this->generatedCode = $this->entityGenerator->generateEntityClass($metadata))) {
         throw new \Exception('Entity class could not be created');
     }
     // TableAnnotation-Update if a Database is given
     if (isset($this->database)) {
         $this->updateTableAnnotation();
     }
     $this->generateUseStatements();
     $this->generateMethods();
     $this->writeFile();
     return true;
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function generateEntityClass(ClassMetadataInfo $metadata)
 {
     $code = parent::generateEntityClass($metadata);
     $class = new \ReflectionClass('Doctrine\\ORM\\Tools\\EntityGenerator');
     $spacesProperty = $class->getProperty('spaces');
     $spacesProperty->setAccessible(true);
     $prefixCodeWithSpacesMethod = $class->getMethod('prefixCodeWithSpaces');
     $prefixCodeWithSpacesMethod->setAccessible(true);
     $code = str_replace(array('<constants>'), array($prefixCodeWithSpacesMethod->invoke($this, $this->generateConstant($metadata))), $code);
     return str_replace('<spaces>', $spacesProperty->getValue($this), $code);
 }