protected function initGenerator()
 {
     $this->generator->setGenerateAnnotations(true);
     $this->generator->setBackupExisting(false);
     $this->generator->setGenerateStubMethods(true);
     $this->generator->setRegenerateEntityIfExists(true);
     $this->generator->setUpdateEntityIfExists(false);
     if ($this->parentClassName != null) {
         $this->generator->setClassToExtend($this->parentClassName);
     }
     return $this->generator;
 }
Exemplo n.º 2
0
 public function testRegenerateEntityClass()
 {
     $metadata = $this->generateBookEntityFixture();
     $this->loadEntityClass($metadata);
     $className = basename(str_replace('\\', '/', $metadata->name));
     $path = $this->_tmpDir . '/' . $this->_namespace . '/' . $className . '.php';
     $classTest = file_get_contents($path);
     $this->_generator->setRegenerateEntityIfExists(true);
     $this->_generator->setBackupExisting(false);
     $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
     $classNew = file_get_contents($path);
     $this->assertSame($classTest, $classNew);
 }
Exemplo n.º 3
0
 public function fire()
 {
     $this->info('Starting entities generation....');
     // flush all generated and cached entities, etc
     \D2Cache::flushAll();
     $cmf = new DisconnectedClassMetadataFactory();
     $cmf->setEntityManager($this->d2em);
     $metadata = $cmf->getAllMetadata();
     if (empty($metadata)) {
         $this->error('No metadata found to generate entities.');
         return -1;
     }
     $directory = Config::get('d2doctrine.paths.entities');
     if (!$directory) {
         $this->error('The entity directory has not been set.');
         return -1;
     }
     $entityGenerator = new EntityGenerator();
     $entityGenerator->setGenerateAnnotations($this->option('generate-annotations'));
     $entityGenerator->setGenerateStubMethods($this->option('generate-methods'));
     $entityGenerator->setRegenerateEntityIfExists($this->option('regenerate-entities'));
     $entityGenerator->setUpdateEntityIfExists($this->option('update-entities'));
     $entityGenerator->setNumSpaces($this->option('num-spaces'));
     $entityGenerator->setBackupExisting(!$this->option('no-backup'));
     $this->info('Processing entities:');
     foreach ($metadata as $item) {
         $this->line($item->name);
     }
     try {
         $entityGenerator->generate($metadata, $directory);
         $this->info('Entities have been created.');
     } catch (\ErrorException $e) {
         if ($this->option('verbose') == 3) {
             throw $e;
         }
         $this->error("Caught ErrorException: " . $e->getMessage());
         $this->info("Re-optimizing:");
         $this->call('optimize');
         $this->comment("*** You must now rerun this artisan command ***");
         exit(-1);
     }
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     $cmf = new DisconnectedClassMetadataFactory();
     $cmf->setEntityManager($em);
     $metadatas = $cmf->getAllMetadata();
     $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
     // Process destination directory
     $destPath = realpath($input->getArgument('dest-path'));
     if (!file_exists($destPath)) {
         throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not exist.", $input->getArgument('dest-path')));
     }
     if (!is_writable($destPath)) {
         throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not have write permissions.", $destPath));
     }
     if (count($metadatas)) {
         // Create EntityGenerator
         $entityGenerator = new EntityGenerator();
         $entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
         $entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
         $entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
         $entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
         $entityGenerator->setNumSpaces($input->getOption('num-spaces'));
         $entityGenerator->setBackupExisting(!$input->getOption('no-backup'));
         if (($extend = $input->getOption('extend')) !== null) {
             $entityGenerator->setClassToExtend($extend);
         }
         foreach ($metadatas as $metadata) {
             $output->writeln(sprintf('Processing entity "<info>%s</info>"', $metadata->name));
         }
         // Generating Entities
         $entityGenerator->generate($metadatas, $destPath);
         // Outputting information message
         $output->writeln(PHP_EOL . sprintf('Entity classes generated to "<info>%s</INFO>"', $destPath));
     } else {
         $output->writeln('No Metadata Classes to process.');
     }
 }
 protected function getEntityGenerator()
 {
     $entityGenerator = new EntityGenerator();
     $entityGenerator->setGenerateStubMethods(true);
     $entityGenerator->setRegenerateEntityIfExists(true);
     $entityGenerator->setBackupExisting(true);
     return $entityGenerator;
 }
Exemplo n.º 6
0
 /**
  * Generate entity classes
  *
  * @param array $metadata            
  */
 protected function generateEntities(array $metadata)
 {
     $generator = new EntityGenerator();
     $generator->setGenerateAnnotations(true);
     $generator->setGenerateStubMethods(true);
     $generator->setRegenerateEntityIfExists(false);
     $generator->setUpdateEntityIfExists(true);
     $generator->setBackupExisting(false);
     if (null !== ($superclass = $this->getSuperclass())) {
         $generator->setClassToExtend($superclass);
     }
     /* @var $classMetadata \Doctrine\ORM\Mapping\ClassMetadata */
     foreach ($metadata as $classMetadata) {
         $className = end(explode('\\', $classMetadata->getName()));
         $classMetadata->setCustomRepositoryClass($this->getNsRepository() . $className);
         if (null !== ($prefix = $this->getSequencePrefix())) {
             $classMetadata->setSequenceGeneratorDefinition(array('sequenceName' => strtoupper($prefix . '_' . $className)));
         }
     }
     $generator->generate($metadata, $this->getDirectory());
 }