Skip to content

Commit 17580bb

Browse files
committed
bug #20066 [FrameworkBundle] fix yaml:lint when yaml is not installed along side framework-bundle (fabpot)
This PR was merged into the 3.2-dev branch. Discussion ---------- [FrameworkBundle] fix yaml:lint when yaml is not installed along side framework-bundle | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a YAML is not an explicit dependency of FrameworkBundle. If it is not installed, the console is broken as the yaml:lint commands tries to extends the one in the YAML component. This bug only exists in master as this refactoring happened in 3.2 Commits ------- b1c5a68 [FrameworkBundle] fixed yaml:lint when yaml is not installed along side framwork-bundle
2 parents a56ae00 + 0060101 commit 17580bb

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

Command/YamlLintCommand.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
1417
use Symfony\Component\Yaml\Command\LintCommand as BaseLintCommand;
1518

1619
/**
@@ -19,17 +22,39 @@
1922
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2023
* @author Robin Chalas <robin.chalas@gmail.com>
2124
*/
22-
class YamlLintCommand extends BaseLintCommand
25+
class YamlLintCommand extends Command
2326
{
27+
private $command;
28+
2429
/**
2530
* {@inheritdoc}
2631
*/
2732
protected function configure()
2833
{
29-
parent::configure();
34+
$this->setName('lint:yaml');
35+
36+
if (!$this->isEnabled()) {
37+
return;
38+
}
39+
40+
$directoryIteratorProvider = function ($directory, $default) {
41+
if (!is_dir($directory)) {
42+
$directory = $this->getApplication()->getKernel()->locateResource($directory);
43+
}
44+
45+
return $default($directory);
46+
};
47+
48+
$isReadableProvider = function ($fileOrDirectory, $default) {
49+
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
50+
};
3051

31-
$this->setHelp(
32-
$this->getHelp().<<<EOF
52+
$this->command = new BaseLintCommand(null, $directoryIteratorProvider, $isReadableProvider);
53+
54+
$this
55+
->setDescription($this->command->getDescription())
56+
->setDefinition($this->command->getDefinition())
57+
->setHelp($this->command->getHelp().<<<EOF
3358
3459
Or find all files in a bundle:
3560
@@ -39,17 +64,16 @@ protected function configure()
3964
);
4065
}
4166

42-
protected function getDirectoryIterator($directory)
67+
/**
68+
* {@inheritdoc}
69+
*/
70+
public function isEnabled()
4371
{
44-
if (!is_dir($directory)) {
45-
$directory = $this->getApplication()->getKernel()->locateResource($directory);
46-
}
47-
48-
return parent::getDirectoryIterator($directory);
72+
return class_exists(BaseLintCommand::class) && parent::isEnabled();
4973
}
5074

51-
protected function isReadable($fileOrDirectory)
75+
protected function execute(InputInterface $input, OutputInterface $output)
5276
{
53-
return 0 === strpos($fileOrDirectory, '@') || parent::isReadable($fileOrDirectory);
77+
return $this->command->execute($input, $output);
5478
}
5579
}

0 commit comments

Comments
 (0)