Skip to content

Commit

Permalink
feature #97 New make:migration command (weaverryan)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 1.0-dev branch (closes #97).

Discussion
----------

New make:migration command

This replaces #10.

There are 2 cases:

(A) When there ARE schema changes:

<img width="1053" alt="screen shot 2017-12-29 at 11 07 47 pm" src="https://user-images.githubusercontent.com/121003/34451290-9b0c9bb0-ecef-11e7-9a1d-41ba78c84638.png">

(B) When there are NOT schema changes:

<img width="1269" alt="screen shot 2017-12-29 at 11 07 14 pm" src="https://user-images.githubusercontent.com/121003/34451291-a617113e-ecef-11e7-979f-c30f2cc3e91e.png">

This includes a BC break on `MakerInterface`, but it will only affect people who have created custom makers (and they'll get a clear error).

Commits
-------

f2e25e9 tweaking message
95af9fa Adding make:migration, which includes reworking MakerInterface
  • Loading branch information
weaverryan committed Dec 31, 2017
2 parents 0a46cfc + f2e25e9 commit 5e4f335
Show file tree
Hide file tree
Showing 30 changed files with 524 additions and 125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ composer.lock
phpunit.xml
vendor/
tests/tmp/*
.php_cs.cache
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1.1
===

* [BC BREAK] The MakerInterface changed: `writeNextStepsMessage`
was renamed to `writeSuccessMessage`. You should now extend
`AbstractMaker` instead of implementing the interface directly,
and use `parent::writeSuccessMessage()` to get the normal success
message after the command.
27 changes: 27 additions & 0 deletions src/ApplicationAwareMakerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle;

use Symfony\Component\Console\Application;

/**
* Implement this interface if your Maker needs access to the Application.
*
* @author Ryan Weaver <ryan@knpuniversity.com>
*/
interface ApplicationAwareMakerInterface
{
/**
* @param Application $application
*/
public function setApplication(Application $application);
}
26 changes: 20 additions & 6 deletions src/Command/MakerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@

namespace Symfony\Bundle\MakerBundle\Command;

use Symfony\Bundle\MakerBundle\ApplicationAwareMakerInterface;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
use Symfony\Bundle\MakerBundle\ExtraGenerationMakerInterface;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -92,13 +95,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
$params = $this->maker->getParameters($input);
$this->generator->generate($params, $this->maker->getFiles($params));

$this->io->newLine();
$this->io->writeln(' <bg=green;fg=white> </>');
$this->io->writeln(' <bg=green;fg=white> Success! </>');
$this->io->writeln(' <bg=green;fg=white> </>');
$this->io->newLine();
if ($this->maker instanceof ExtraGenerationMakerInterface) {
$this->maker->afterGenerate($this->io, $params);
}

$this->maker->writeSuccessMessage($params, $this->io);
}

public function setApplication(Application $application = null)
{
parent::setApplication($application);

if ($this->maker instanceof ApplicationAwareMakerInterface) {
if (null === $application) {
throw new \RuntimeException('Application cannot be null.');
}

$this->maker->writeNextStepsMessage($params, $this->io);
$this->maker->setApplication($application);
}
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/ExtraGenerationMakerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle;

/**
* Interface to do extra code generation in a maker.
*
* @author Ryan Weaver <ryan@knpuniversity.com>
*/
interface ExtraGenerationMakerInterface
{
/**
* Called after normal code generation.
*/
public function afterGenerate(ConsoleStyle $io, array $params);
}
36 changes: 36 additions & 0 deletions src/Maker/AbstractMaker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Maker;

use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;

/**
* Convenient abstract class for makers.
*/
abstract class AbstractMaker implements MakerInterface
{
public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
{
}

public function writeSuccessMessage(array $params, ConsoleStyle $io)
{
$io->newLine();
$io->writeln(' <bg=green;fg=white> </>');
$io->writeln(' <bg=green;fg=white> Success! </>');
$io->writeln(' <bg=green;fg=white> </>');
$io->newLine();
}
}
11 changes: 4 additions & 7 deletions src/Maker/MakeAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Component\Console\Command\Command;
Expand All @@ -25,7 +24,7 @@
/**
* @author Ryan Weaver <ryan@knpuniversity.com>
*/
final class MakeAuthenticator implements MakerInterface
final class MakeAuthenticator extends AbstractMaker
{
public static function getCommandName(): string
{
Expand All @@ -41,10 +40,6 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
;
}

public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
{
}

public function getParameters(InputInterface $input): array
{
$className = Str::asClassName($input->getArgument('authenticator-class'));
Expand All @@ -62,8 +57,10 @@ public function getFiles(array $params): array
];
}

public function writeNextStepsMessage(array $params, ConsoleStyle $io)
public function writeSuccessMessage(array $params, ConsoleStyle $io)
{
parent::writeSuccessMessage($params, $io);

$io->text([
'Next: Customize your new authenticator.',
'Then, configure the "guard" key on your firewall to use it.',
Expand Down
11 changes: 4 additions & 7 deletions src/Maker/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Component\Console\Command\Command;
Expand All @@ -25,7 +24,7 @@
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
* @author Ryan Weaver <weaverryan@gmail.com>
*/
final class MakeCommand implements MakerInterface
final class MakeCommand extends AbstractMaker
{
public static function getCommandName(): string
{
Expand All @@ -41,10 +40,6 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
;
}

public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
{
}

public function getParameters(InputInterface $input): array
{
$commandName = trim($input->getArgument('name'));
Expand All @@ -64,8 +59,10 @@ public function getFiles(array $params): array
];
}

public function writeNextStepsMessage(array $params, ConsoleStyle $io)
public function writeSuccessMessage(array $params, ConsoleStyle $io)
{
parent::writeSuccessMessage($params, $io);

$io->text([
'Next: open your new command class and customize it!',
'Find the documentation at <fg=yellow>https://symfony.com/doc/current/console.html</>',
Expand Down
11 changes: 4 additions & 7 deletions src/Maker/MakeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Bundle\TwigBundle\TwigBundle;
Expand All @@ -28,7 +27,7 @@
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
* @author Ryan Weaver <weaverryan@gmail.com>
*/
final class MakeController implements MakerInterface
final class MakeController extends AbstractMaker
{
private $router;

Expand All @@ -51,10 +50,6 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
;
}

public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
{
}

public function getParameters(InputInterface $input): array
{
$controllerClassName = Str::asClassName($input->getArgument('controller-class'), 'Controller');
Expand All @@ -76,8 +71,10 @@ public function getFiles(array $params): array
];
}

public function writeNextStepsMessage(array $params, ConsoleStyle $io)
public function writeSuccessMessage(array $params, ConsoleStyle $io)
{
parent::writeSuccessMessage($params, $io);

if (!count($this->router->getRouteCollection())) {
$io->text('<error> Warning! </> No routes configuration defined yet.');
$io->text(' You should probably uncomment the annotation routes in <comment>config/routes.yaml</>');
Expand Down
11 changes: 4 additions & 7 deletions src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Component\Console\Command\Command;
Expand All @@ -26,7 +25,7 @@
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
* @author Ryan Weaver <weaverryan@gmail.com>
*/
final class MakeEntity implements MakerInterface
final class MakeEntity extends AbstractMaker
{
public static function getCommandName(): string
{
Expand All @@ -42,10 +41,6 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
;
}

public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
{
}

public function getParameters(InputInterface $input): array
{
$entityClassName = Str::asClassName($input->getArgument('entity-class'));
Expand All @@ -68,8 +63,10 @@ public function getFiles(array $params): array
];
}

public function writeNextStepsMessage(array $params, ConsoleStyle $io)
public function writeSuccessMessage(array $params, ConsoleStyle $io)
{
parent::writeSuccessMessage($params, $io);

$io->text([
'Next: Add more fields to your entity and start using it.',
'Find the documentation at <fg=yellow>https://symfony.com/doc/current/doctrine.html#creating-an-entity-class</>',
Expand Down
11 changes: 4 additions & 7 deletions src/Maker/MakeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Component\Console\Command\Command;
Expand All @@ -27,7 +26,7 @@
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
* @author Ryan Weaver <weaverryan@gmail.com>
*/
final class MakeForm implements MakerInterface
final class MakeForm extends AbstractMaker
{
public static function getCommandName(): string
{
Expand All @@ -43,10 +42,6 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
;
}

public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
{
}

public function getParameters(InputInterface $input): array
{
$formClassName = Str::asClassName($input->getArgument('name'), 'Type');
Expand All @@ -66,8 +61,10 @@ public function getFiles(array $params): array
];
}

public function writeNextStepsMessage(array $params, ConsoleStyle $io)
public function writeSuccessMessage(array $params, ConsoleStyle $io)
{
parent::writeSuccessMessage($params, $io);

$io->text([
'Next: Add fields to your form and start using it.',
'Find the documentation at <fg=yellow>https://symfony.com/doc/current/forms.html</>',
Expand Down
11 changes: 4 additions & 7 deletions src/Maker/MakeFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Component\BrowserKit\Client;
Expand All @@ -27,7 +26,7 @@
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
* @author Ryan Weaver <weaverryan@gmail.com>
*/
class MakeFunctionalTest implements MakerInterface
class MakeFunctionalTest extends AbstractMaker
{
public static function getCommandName(): string
{
Expand All @@ -43,10 +42,6 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
;
}

public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
{
}

public function getParameters(InputInterface $input): array
{
$testClassName = Str::asClassName($input->getArgument('name'), 'Test');
Expand All @@ -64,8 +59,10 @@ public function getFiles(array $params): array
];
}

public function writeNextStepsMessage(array $params, ConsoleStyle $io)
public function writeSuccessMessage(array $params, ConsoleStyle $io)
{
parent::writeSuccessMessage($params, $io);

$io->text([
'Next: Open your new test class and start customizing it.',
'Find the documentation at <fg=yellow>https://symfony.com/doc/current/testing.html#functional-tests</>',
Expand Down

0 comments on commit 5e4f335

Please sign in to comment.