Skip to content

Commit

Permalink
[minor] Detect missing maker bundle and suggest installation via Stub…
Browse files Browse the repository at this point in the history
…Commands (#161)

Fixes #16.
  • Loading branch information
jschaedl committed May 15, 2021
1 parent d1fc25b commit 6001e7e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Bundle/Command/StubCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Zenstruck\Foundry\Bundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

abstract class StubCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
(new SymfonyStyle($input, $output))
->error(
\sprintf("To run \"%s\" you need the \"%s\" which is currently not installed.\n\nTry running \"composer require %s\".", static::$defaultName, 'MakerBundle', 'symfony/maker-bundle --dev')
)
;

return Command::SUCCESS;
}
}
8 changes: 8 additions & 0 deletions src/Bundle/Command/StubMakeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zenstruck\Foundry\Bundle\Command;

final class StubMakeFactory extends StubCommand
{
protected static $defaultName = 'make:factory';
}
8 changes: 8 additions & 0 deletions src/Bundle/Command/StubMakeStory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zenstruck\Foundry\Bundle\Command;

final class StubMakeStory extends StubCommand
{
protected static $defaultName = 'make:story';
}
8 changes: 8 additions & 0 deletions src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace Zenstruck\Foundry\Bundle\DependencyInjection;

use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
use Zenstruck\Foundry\Bundle\Command\StubMakeFactory;
use Zenstruck\Foundry\Bundle\Command\StubMakeStory;
use Zenstruck\Foundry\Configuration;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Story;
Expand Down Expand Up @@ -37,6 +40,11 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
} elseif (false === $mergedConfig['auto_refresh_proxies']) {
$container->getDefinition(Configuration::class)->addMethodCall('disableDefaultProxyAutoRefresh');
}

if (!\class_exists(AbstractMaker::class)) {
$container->register(StubMakeFactory::class)->addTag('console.command');
$container->register(StubMakeStory::class)->addTag('console.command');
}
}

private function configureFaker(array $config, ContainerBuilder $container): void
Expand Down

0 comments on commit 6001e7e

Please sign in to comment.