Doctrine\OXM\Tools\XmlEntityRepositoryGenerator::writeXmlEntityRepositoryClass PHP Метод

writeXmlEntityRepositoryClass() публичный Метод

public writeXmlEntityRepositoryClass ( $fullClassName, $outputDirectory )
    public function writeXmlEntityRepositoryClass($fullClassName, $outputDirectory)
    {
        $code = $this->generateXmlEntityRepositoryClass($fullClassName);
        $path = $outputDirectory . DIRECTORY_SEPARATOR . str_replace('\\', \DIRECTORY_SEPARATOR, $fullClassName) . '.php';
        $dir = dirname($path);
        if (!is_dir($dir)) {
            mkdir($dir, 0777, true);
        }
        if (!file_exists($path)) {
            file_put_contents($path, $code);
        }
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $bundleName = $input->getArgument('bundle');
     $filterXmlEntity = $input->getOption('xml-entity');
     $foundBundle = $this->findBundle($bundleName);
     if ($metadatas = $this->getBundleMetadatas($foundBundle)) {
         $output->writeln(sprintf('Generating xml-entity repositories for "<info>%s</info>"', $foundBundle->getName()));
         $generator = new XmlEntityRepositoryGenerator();
         foreach ($metadatas as $metadata) {
             if ($filterXmlEntity && $filterXmlEntity !== $metadata->reflClass->getShortname()) {
                 continue;
             }
             if ($metadata->customRepositoryClassName) {
                 if (strpos($metadata->customRepositoryClassName, $foundBundle->getNamespace()) === false) {
                     throw new \RuntimeException("Repository " . $metadata->customRepositoryClassName . " and bundle don't have a common namespace, " . "generation failed because the target directory cannot be detected.");
                 }
                 $output->writeln(sprintf('  > <info>OK</info> generating <comment>%s</comment>', $metadata->customRepositoryClassName));
                 $generator->writeXmlEntityRepositoryClass($metadata->customRepositoryClassName, $this->findBasePathForBundle($foundBundle));
             } else {
                 $output->writeln(sprintf('  > <error>SKIP</error> no custom repository for <comment>%s</comment>', $metadata->name));
             }
         }
     } else {
         throw new \RuntimeException("Bundle " . $bundleName . " does not contain any mapped xml-entities.");
     }
 }