Skip to content

Commit

Permalink
Removing unnecessary service locator: just let the registry be null
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Feb 27, 2018
1 parent 1f57317 commit 0f2d52d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
12 changes: 8 additions & 4 deletions src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ final class MakeEntity extends AbstractMaker
{
private $fileManager;
private $generator;
private $serviceLocator;
private $registry;
private $projectDirectory;

public function __construct(FileManager $fileManager, Generator $generator, ContainerInterface $serviceLocator, string $projectDirectory)
public function __construct(FileManager $fileManager, Generator $generator, string $projectDirectory, ?ManagerRegistry $registry)
{
$this->fileManager = $fileManager;
$this->generator = $generator;
$this->serviceLocator = $serviceLocator;
$this->projectDirectory = $projectDirectory;
$this->registry = $registry;
}

public static function getCommandName(): string
Expand Down Expand Up @@ -445,7 +445,11 @@ private function printAvailableTypes(ConsoleStyle $io)
*/
private function getRegistry()
{
return $this->serviceLocator->get('doctrine');
// this should never happen: we will have checked for the
// DoctrineBundle dependency before calling this
if (null === $this->registry) {
throw new \Exception('Somehow the doctrine service is missing. Is DoctrineBundle installed?');
}
}

private function createEntityClassQuestion(string $questionText): Question
Expand Down
9 changes: 1 addition & 8 deletions src/Resources/config/makers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@
<service id="maker.maker.make_entity" class="Symfony\Bundle\MakerBundle\Maker\MakeEntity">
<argument type="service" id="maker.file_manager" />
<argument type="service" id="maker.generator" />
<argument type="service">
<service class="Symfony\Component\DependencyInjection\ServiceLocator">
<tag name="container.service_locator" />
<argument type="collection">
<argument key="doctrine" type="service" id="doctrine" on-invalid="null" />
</argument>
</service>
</argument>
<argument>%kernel.project_dir%</argument>
<argument type="service" id="doctrine" on-invalid="null" />
<tag name="maker.command" />
</service>

Expand Down

0 comments on commit 0f2d52d

Please sign in to comment.