Skip to content

Commit cc4b758

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 1b95509 + 14fa7ef commit cc4b758

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1150
-570
lines changed

CHANGELOG.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
1.1
22
===
33

4-
* [BC BREAK] The MakerInterface changed: `writeNextStepsMessage`
5-
was renamed to `writeSuccessMessage`. You should now extend
6-
`AbstractMaker` instead of implementing the interface directly,
7-
and use `parent::writeSuccessMessage()` to get the normal success
8-
message after the command.
4+
* [BC BREAK] The MakerInterface changed: `getParameters()`, `getFiles()`
5+
and `writeNextStepsMessage()` were removed and `generate()` was added
6+
in their place. We recommend extending `AbstractMaker` instead of implementing
7+
the interface directly, and use `$this->writeSuccessMessage()` to get
8+
the normal "success" message after the command #120 via @weaverryan
9+
10+
* Added new `make:migration` command, which wraps the normal
11+
`doctrine:migrations:diff` command #97 via @weaverryan
12+
13+
* Added new `make:fixtures` command to generate an empty fixtures class
14+
#105 via @javiereguiluz
15+
16+
* Added PHPDoc to generated entity repositories so that your IDE knows
17+
what type of objects are returned #116 @enleur
18+
19+
* Allowed generation of all classes into sub-namespaces #120 via @weaverryan

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"symfony/http-kernel": "^3.4|^4.0"
2222
},
2323
"require-dev": {
24+
"allocine/twigcs": "^3.0",
2425
"friendsofphp/php-cs-fixer": "^2.8",
2526
"symfony/phpunit-bridge": "^3.4|^4.0",
2627
"symfony/process": "^3.4|^4.0"

src/Command/MakerCommand.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1616
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1717
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
18-
use Symfony\Bundle\MakerBundle\ExtraGenerationMakerInterface;
18+
use Symfony\Bundle\MakerBundle\FileManager;
1919
use Symfony\Bundle\MakerBundle\Generator;
2020
use Symfony\Bundle\MakerBundle\InputConfiguration;
2121
use Symfony\Bundle\MakerBundle\MakerInterface;
@@ -33,16 +33,16 @@
3333
final class MakerCommand extends Command
3434
{
3535
private $maker;
36-
private $generator;
36+
private $fileManager;
3737
private $inputConfig;
3838
/** @var ConsoleStyle */
3939
private $io;
4040
private $checkDependencies = true;
4141

42-
public function __construct(MakerInterface $maker, Generator $generator)
42+
public function __construct(MakerInterface $maker, FileManager $fileManager)
4343
{
4444
$this->maker = $maker;
45-
$this->generator = $generator;
45+
$this->fileManager = $fileManager;
4646
$this->inputConfig = new InputConfiguration();
4747

4848
parent::__construct();
@@ -56,12 +56,14 @@ protected function configure()
5656
protected function initialize(InputInterface $input, OutputInterface $output)
5757
{
5858
$this->io = new ConsoleStyle($input, $output);
59+
$this->fileManager->setIo($this->io);
5960

6061
if ($this->checkDependencies) {
6162
$dependencies = new DependencyBuilder();
6263
$this->maker->configureDependencies($dependencies);
63-
if ($missingPackages = $dependencies->getMissingDependencies()) {
64-
throw new RuntimeCommandException(sprintf("Missing package%s: to use the %s command, run: \n\ncomposer require %s", 1 === count($missingPackages) ? '' : 's', $this->getName(), implode(' ', $missingPackages)));
64+
65+
if ($missingPackagesMessage = $dependencies->getMissingPackagesMessage($this->getName())) {
66+
throw new RuntimeCommandException($missingPackagesMessage);
6567
}
6668
}
6769
}
@@ -86,15 +88,14 @@ protected function interact(InputInterface $input, OutputInterface $output)
8688

8789
protected function execute(InputInterface $input, OutputInterface $output)
8890
{
89-
$this->generator->setIO($this->io);
90-
$params = $this->maker->getParameters($input);
91-
$this->generator->generate($params, $this->maker->getFiles($params));
91+
$generator = new Generator($this->fileManager, 'App\\');
9292

93-
if ($this->maker instanceof ExtraGenerationMakerInterface) {
94-
$this->maker->afterGenerate($this->io, $params);
95-
}
93+
$this->maker->generate($input, $this->io, $generator);
9694

97-
$this->maker->writeSuccessMessage($params, $this->io);
95+
// sanity check for custom makers
96+
if ($generator->hasPendingOperations()) {
97+
throw new \LogicException('Make sure to call the writeChanges() method on the generator.');
98+
}
9899
}
99100

100101
public function setApplication(Application $application = null)

src/DependencyBuilder.php

+93-27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
final class DependencyBuilder
1515
{
1616
private $dependencies = [];
17+
private $devDependencies = [];
1718

1819
/**
1920
* Add a dependency that will be reported if the given class is missing.
@@ -22,52 +23,117 @@ final class DependencyBuilder
2223
* the user if other required dependencies are missing. An example
2324
* is the "validator" when trying to work with forms.
2425
*/
25-
public function addClassDependency(string $class, string $package, bool $required = true)
26+
public function addClassDependency(string $class, string $package, bool $required = true, bool $devDependency = false)
2627
{
27-
$this->dependencies[$class] = [
28-
'name' => $package,
29-
'required' => $required,
30-
];
28+
if ($devDependency) {
29+
$this->devDependencies[] = [
30+
'class' => $class,
31+
'name' => $package,
32+
'required' => $required,
33+
];
34+
} else {
35+
$this->dependencies[] = [
36+
'class' => $class,
37+
'name' => $package,
38+
'required' => $required,
39+
];
40+
}
3141
}
3242

43+
/**
44+
* @internal
45+
*/
3346
public function getMissingDependencies(): array
3447
{
35-
$missingPackages = [];
36-
$missingOptionalPackages = [];
37-
38-
foreach ($this->dependencies as $class => $package) {
39-
if (class_exists($class)) {
40-
continue;
41-
}
48+
return $this->calculateMissingDependencies($this->dependencies);
49+
}
4250

43-
if (true === $package['required']) {
44-
$missingPackages[] = $package['name'];
45-
} else {
46-
$missingOptionalPackages[] = $package['name'];
47-
}
48-
}
51+
/**
52+
* @internal
53+
*/
54+
public function getMissingDevDependencies(): array
55+
{
56+
return $this->calculateMissingDependencies($this->devDependencies);
57+
}
4958

50-
if (empty($missingPackages)) {
51-
return [];
52-
}
59+
/**
60+
* @internal
61+
*/
62+
public function getAllRequiredDependencies(): array
63+
{
64+
return $this->getRequiredDependencyNames($this->dependencies);
65+
}
5366

54-
return array_merge($missingPackages, $missingOptionalPackages);
67+
/**
68+
* @internal
69+
*/
70+
public function getAllRequiredDevDependencies(): array
71+
{
72+
return $this->getRequiredDependencyNames($this->devDependencies);
5573
}
5674

5775
/**
5876
* @internal
5977
*/
60-
public function getAllRequiredDependencies(): array
78+
public function getMissingPackagesMessage(string $commandName): string
79+
{
80+
$packages = $this->getMissingDependencies();
81+
$packagesDev = $this->getMissingDevDependencies();
82+
83+
if (empty($packages) && empty($packagesDev)) {
84+
return '';
85+
}
86+
87+
$packagesCount = count($packages) + count($packagesDev);
88+
89+
$message = sprintf(
90+
"Missing package%s: to use the %s command, run:\n",
91+
$packagesCount > 1 ? 's' : '',
92+
$commandName
93+
);
94+
95+
if (!empty($packages)) {
96+
$message .= sprintf("\ncomposer require %s", implode(' ', $packages));
97+
}
98+
99+
if (!empty($packagesDev)) {
100+
$message .= sprintf("\ncomposer require %s --dev", implode(' ', $packagesDev));
101+
}
102+
103+
return $message;
104+
}
105+
106+
private function getRequiredDependencyNames(array $dependencies)
61107
{
62-
$dependencies = [];
63-
foreach ($this->dependencies as $class => $package) {
108+
$packages = [];
109+
foreach ($dependencies as $package) {
64110
if (!$package['required']) {
65111
continue;
66112
}
113+
$packages[] = $package['name'];
114+
}
67115

68-
$dependencies[] = $package['name'];
116+
return $packages;
117+
}
118+
119+
private function calculateMissingDependencies(array $dependencies)
120+
{
121+
$missingPackages = [];
122+
$missingOptionalPackages = [];
123+
foreach ($dependencies as $package) {
124+
if (class_exists($package['class'])) {
125+
continue;
126+
}
127+
if (true === $package['required']) {
128+
$missingPackages[] = $package['name'];
129+
} else {
130+
$missingOptionalPackages[] = $package['name'];
131+
}
132+
}
133+
if (empty($missingPackages)) {
134+
return [];
69135
}
70136

71-
return $dependencies;
137+
return array_merge($missingPackages, $missingOptionalPackages);
72138
}
73139
}

src/DependencyInjection/CompilerPass/MakeCommandRegistrationPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function process(ContainerBuilder $container)
3737
MakerCommand::class
3838
)->setArguments([
3939
new Reference($id),
40-
new Reference('maker.generator'),
40+
new Reference('maker.file_manager'),
4141
])->addTag('console.command', ['command' => $class::getCommandName()]);
4242
}
4343
}

src/ExtraGenerationMakerInterface.php

-25
This file was deleted.

0 commit comments

Comments
 (0)