Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added generate-basename-only option

  • Loading branch information...
commit c836cc495982cbe1f895ae78580482abcdb74abe 1 parent 9445502
Bryan C. Geraghty authored
5 lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php
@@ -59,6 +59,10 @@ protected function configure()
59 59 'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.'
60 60 ),
61 61 new InputOption(
  62 + 'generate-basename-only', null, InputOption::VALUE_OPTIONAL,
  63 + 'Flag to define if generator should generate file names reflecting the class basename only.', false
  64 + ),
  65 + new InputOption(
62 66 'generate-annotations', null, InputOption::VALUE_OPTIONAL,
63 67 'Flag to define if generator should generate annotation metadata on entities.', false
64 68 ),
@@ -136,6 +140,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
136 140 $entityGenerator = new EntityGenerator();
137 141
138 142 $entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
  143 + $entityGenerator->setGenerateBasenameOnly($input->getOption('generate-basename-only'));
139 144 $entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
140 145 $entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
141 146 $entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
26 lib/Doctrine/ORM/Tools/EntityGenerator.php
@@ -108,6 +108,12 @@ class EntityGenerator
108 108 private $generateAnnotations = false;
109 109
110 110 /**
  111 + * Whether or not the generated file name should only reflect the
  112 + * class basename
  113 + */
  114 + private $generateBasenameOnly = false;
  115 +
  116 + /**
111 117 * @var string
112 118 */
113 119 private $annotationsPrefix = '';
@@ -271,7 +277,13 @@ public function generate(array $metadatas, $outputDirectory)
271 277 */
272 278 public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory)
273 279 {
274   - $path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name) . $this->extension;
  280 + if ($this->generateBasenameOnly) {
  281 + $classPath = substr($metadata->name, strrpos($metadata->name, '\\') + 1);
  282 + } else {
  283 + $classPath = str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name);
  284 + }
  285 +
  286 + $path = $outputDirectory . '/' . $classPath . $this->extension;;
275 287 $dir = dirname($path);
276 288
277 289 if ( ! is_dir($dir)) {
@@ -370,6 +382,18 @@ public function setExtension($extension)
370 382 }
371 383
372 384 /**
  385 + * Set whether or not generated file names should only reflect the class
  386 + * bansename
  387 + *
  388 + * @param bool $bool
  389 + * @return void
  390 + */
  391 + public function setGenerateBasenameOnly($bool)
  392 + {
  393 + $this->generateBasenameOnly = $bool;
  394 + }
  395 +
  396 + /**
373 397 * Set the name of the class the generated classes should extend from
374 398 *
375 399 * @return void

0 comments on commit c836cc4

Please sign in to comment.
Something went wrong with that request. Please try again.