Пример #1
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $printer = $this->getPrinter();
     $arguments = $this->getArguments();
     $from = $arguments['from'];
     $dest = realpath($arguments['dest']);
     $entityGenerator = new EntityGenerator();
     $entityGenerator->setGenerateAnnotations(false);
     $entityGenerator->setGenerateStubMethods(true);
     $entityGenerator->setRegenerateEntityIfExists(false);
     $entityGenerator->setUpdateEntityIfExists(true);
     if (isset($arguments['extend']) && $arguments['extend']) {
         $entityGenerator->setClassToExtend($arguments['extend']);
     }
     if (isset($arguments['num-spaces']) && $arguments['extend']) {
         $entityGenerator->setNumSpaces($arguments['num-spaces']);
     }
     $reader = new ClassMetadataReader();
     $reader->setEntityManager($this->getConfiguration()->getAttribute('em'));
     $reader->addMappingSource($from);
     $metadatas = $reader->getMetadatas();
     foreach ($metadatas as $metadata) {
         $printer->writeln(sprintf('Processing entity "%s"', $printer->format($metadata->name, 'KEYWORD')));
     }
     $entityGenerator->generate($metadatas, $dest);
     $printer->write(PHP_EOL);
     $printer->writeln(sprintf('Entity classes generated to "%s"', $printer->format($dest, 'KEYWORD')));
 }
Пример #2
0
 /**
  *
  * @param  string $className
  * @return ClassMetadata
  */
 protected function extractClassMetadata($className)
 {
     $cm = new ClassMetadataReader();
     $cm->addMappingSource(new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($this->_sm));
     $metadatas = $cm->getMetadatas();
     $output = false;
     foreach ($metadatas as $metadata) {
         if (strtolower($metadata->name) == strtolower($className)) {
             return $metadata;
         }
     }
     $this->fail("No class matching the name '" . $className . "' was found!");
 }
Пример #3
0
 public function run()
 {
     $printer = $this->getPrinter();
     $arguments = $this->getArguments();
     $dest = realpath($arguments['dest']);
     $reader = new ClassMetadataReader();
     $reader->setEntityManager($this->getConfiguration()->getAttribute('em'));
     $reader->addMappingSource($arguments['from']);
     $metadatas = $reader->getMetadatas();
     foreach ($metadatas as $metadata) {
         if ($metadata->customRepositoryClassName) {
             $code = $this->_generateRepositoryClass($metadata->customRepositoryClassName);
             $path = $dest . '/' . str_replace('\\', '/', $metadata->customRepositoryClassName) . '.php';
             $dir = dirname($path);
             if (!is_dir($dir)) {
                 mkdir($dir, 0777, true);
             }
             $printer->writeln(sprintf('Processing entity "%s"', $printer->format($metadata->customRepositoryClassName, 'KEYWORD')));
             file_put_contents($path, $code);
         }
     }
     $printer->writeln('');
     $printer->writeln(sprintf('Entity repository classes generated to "%s"', $printer->format($dest, 'KEYWORD')));
 }