Ejemplo n.º 1
0
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $dm = $this->getHelper('documentManager')->getDocumentManager();
     $metadatas = $dm->getMetadataFactory()->getAllMetadata();
     $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
     // Process destination directory
     if (($destPath = $input->getArgument('dest-path')) === null) {
         $destPath = $dm->getConfiguration()->getProxyDir();
     }
     if (!is_dir($destPath)) {
         mkdir($destPath, 0775, true);
     }
     $destPath = realpath($destPath);
     if (!file_exists($destPath)) {
         throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $destPath));
     } elseif (!is_writable($destPath)) {
         throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath));
     }
     if (count($metadatas)) {
         foreach ($metadatas as $metadata) {
             $output->write(sprintf('Processing document "<info>%s</info>"', $metadata->name) . PHP_EOL);
         }
         // Generating Proxies
         $dm->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
         // Outputting information message
         $output->write(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
     } else {
         $output->write('No Metadata Classes to process.' . PHP_EOL);
     }
 }
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $dm = $this->getHelper('dm')->getDocumentManager();
     $metadatas = $dm->getMetadataFactory()->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("Documents destination directory '<info>%s</info>' does not exist.", $destPath));
     } else {
         if (!is_writable($destPath)) {
             throw new \InvalidArgumentException(sprintf("Documents destination directory '<info>%s</info>' does not have write permissions.", $destPath));
         }
     }
     if (count($metadatas)) {
         $numRepositories = 0;
         $generator = new DocumentRepositoryGenerator();
         foreach ($metadatas as $metadata) {
             if ($metadata->customRepositoryClassName) {
                 $output->write(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName) . PHP_EOL);
                 $generator->writeDocumentRepositoryClass($metadata->customRepositoryClassName, $destPath);
                 $numRepositories++;
             }
         }
         if ($numRepositories) {
             // Outputting information message
             $output->write(PHP_EOL . sprintf('Repository classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
         } else {
             $output->write('No Repository classes were found to be processed.' . PHP_EOL);
         }
     } else {
         $output->write('No Metadata Classes to process.' . PHP_EOL);
     }
 }
Ejemplo n.º 3
0
 public function execute()
 {
     if (empty($this->connection)) {
         $this->connection = $this->DbConfig->getConfig();
     }
     $this->out('Generating Proxy classes');
     $dm = ConnectionManager::getDataSource($this->connection)->getDocumentManager();
     $metadatas = $dm->getMetadataFactory()->getAllMetadata();
     $metadatas = MetadataFilter::filter($metadatas, isset($this->params['filter']) ? $this->params['filter'] : null);
     // Process destination directory
     $destPath = empty($this->params['destPath']) ? $dm->getConfiguration()->getHydratorDir() : $this->params['destPath'];
     if (!is_dir($destPath)) {
         mkdir($destPath, 0777, true);
     }
     $destPath = realpath($destPath);
     if (!file_exists($destPath)) {
         throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $destPath));
     } else {
         if (!is_writable($destPath)) {
             throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath));
         }
     }
     if (count($metadatas)) {
         foreach ($metadatas as $metadata) {
             $this->out(sprintf('Processing document "<info>%s</info>"', $metadata->name));
         }
         // Generating Proxies
         $dm->getHydratorFactory()->generateHydratorClasses($metadatas, $destPath);
         // Outputting information message
         $this->out(sprintf('Hydrator classes generated to "<info>%s</info>"', $destPath));
     } else {
         $this->out('No Metadata Classes to process.');
     }
 }
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $dm = $this->getHelper('dm')->getDocumentManager();
     $cmf = new DisconnectedClassMetadataFactory();
     $cmf->setDocumentManager($dm);
     $cmf->setConfiguration($dm->getConfiguration());
     $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("Documents destination directory '<info>%s</info>' does not exist.", $destPath));
     } else {
         if (!is_writable($destPath)) {
             throw new \InvalidArgumentException(sprintf("Documents destination directory '<info>%s</info>' does not have write permissions.", $destPath));
         }
     }
     if (count($metadatas)) {
         // Create DocumentGenerator
         $documentGenerator = new DocumentGenerator();
         $documentGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
         $documentGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
         $documentGenerator->setRegenerateDocumentIfExists($input->getOption('regenerate-documents'));
         $documentGenerator->setUpdateDocumentIfExists($input->getOption('update-documents'));
         $documentGenerator->setNumSpaces($input->getOption('num-spaces'));
         if (($extend = $input->getOption('extend')) !== null) {
             $documentGenerator->setClassToExtend($extend);
         }
         foreach ($metadatas as $metadata) {
             $output->write(sprintf('Processing document "<info>%s</info>"', $metadata->name) . PHP_EOL);
         }
         // Generating Documents
         $documentGenerator->generate($metadatas, $destPath);
         // Outputting information message
         $output->write(PHP_EOL . sprintf('Document classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
     } else {
         $output->write('No Metadata Classes to process.' . PHP_EOL);
     }
 }
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $dm = $this->getHelper('documentManager')->getDocumentManager();
     $metadatas = $dm->getMetadataFactory()->getAllMetadata();
     $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
     // Process destination directory
     if (($destPath = $input->getArgument('dest-path')) === null) {
         $destPath = $dm->getConfiguration()->getPersistentCollectionDir();
     }
     if (!is_dir($destPath)) {
         mkdir($destPath, 0775, true);
     }
     $destPath = realpath($destPath);
     if (!file_exists($destPath)) {
         throw new \InvalidArgumentException(sprintf("Persistent collections destination directory '<info>%s</info>' does not exist.", $destPath));
     } elseif (!is_writable($destPath)) {
         throw new \InvalidArgumentException(sprintf("Persistent collections destination directory '<info>%s</info>' does not have write permissions.", $destPath));
     }
     if (count($metadatas)) {
         $generated = [];
         $collectionGenerator = $dm->getConfiguration()->getPersistentCollectionGenerator();
         foreach ($metadatas as $metadata) {
             $output->write(sprintf('Processing document "<info>%s</info>"', $metadata->name) . PHP_EOL);
             foreach ($metadata->getAssociationNames() as $fieldName) {
                 $mapping = $metadata->getFieldMapping($fieldName);
                 if (empty($mapping['collectionClass']) || isset($generated[$mapping['collectionClass']])) {
                     continue;
                 }
                 $generated[$mapping['collectionClass']] = true;
                 $output->write(sprintf('Generating class for "<info>%s</info>"', $mapping['collectionClass']) . PHP_EOL);
                 $collectionGenerator->generateClass($mapping['collectionClass'], $destPath);
             }
         }
         // Outputting information message
         $output->write(PHP_EOL . sprintf('Persistent collections classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
     } else {
         $output->write('No Metadata Classes to process.' . PHP_EOL);
     }
 }