/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     $metadatas = $em->getMetadataFactory()->getAllMetadata();
     $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
     $repositoryName = $em->getConfiguration()->getDefaultRepositoryClassName();
     // 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)) {
         $numRepositories = 0;
         $generator = new EntityRepositoryGenerator();
         $generator->setDefaultRepositoryName($repositoryName);
         foreach ($metadatas as $metadata) {
             if ($metadata->customRepositoryClassName) {
                 $output->writeln(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName));
                 $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath);
                 $numRepositories++;
             }
         }
         if ($numRepositories) {
             // Outputting information message
             $output->writeln(PHP_EOL . sprintf('Repository classes generated to "<info>%s</INFO>"', $destPath));
         } else {
             $output->writeln('No Repository classes were found to be processed.');
         }
     } else {
         $output->writeln('No Metadata Classes to process.');
     }
 }
 /**
  * @param string $className
  * @param string $defaultRepository
  * @return string
  */
 private function writeRepositoryClass($className, $defaultRepository = null)
 {
     $this->_repositoryGenerator->setDefaultRepositoryName($defaultRepository);
     $this->_repositoryGenerator->writeEntityRepositoryClass($className . 'Repository', $this->_tmpDir);
     return $this->_tmpDir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className) . 'Repository.php';
 }