Skip to content

Commit 0060101

Browse files
committed
[FrameworkBundle] fixed yaml:lint when yaml is not installed along side framwork-bundle
1 parent fc11aa3 commit 0060101

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)