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
This commit is contained in:
Fabien Potencier 2016-09-28 07:37:20 -07:00
commit 6acf54f26b
2 changed files with 72 additions and 22 deletions

View File

@ -11,6 +11,9 @@
namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Command\LintCommand as BaseLintCommand;
/**
@ -19,17 +22,39 @@ use Symfony\Component\Yaml\Command\LintCommand as BaseLintCommand;
* @author Grégoire Pineau <lyrixx@lyrixx.info>
* @author Robin Chalas <robin.chalas@gmail.com>
*/
class YamlLintCommand extends BaseLintCommand
class YamlLintCommand extends Command
{
private $command;
/**
* {@inheritdoc}
*/
protected function configure()
{
parent::configure();
$this->setName('lint:yaml');
$this->setHelp(
$this->getHelp().<<<EOF
if (!$this->isEnabled()) {
return;
}
$directoryIteratorProvider = function ($directory, $default) {
if (!is_dir($directory)) {
$directory = $this->getApplication()->getKernel()->locateResource($directory);
}
return $default($directory);
};
$isReadableProvider = function ($fileOrDirectory, $default) {
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
};
$this->command = new BaseLintCommand(null, $directoryIteratorProvider, $isReadableProvider);
$this
->setDescription($this->command->getDescription())
->setDefinition($this->command->getDefinition())
->setHelp($this->command->getHelp().<<<EOF
Or find all files in a bundle:
@ -39,17 +64,16 @@ EOF
);
}
protected function getDirectoryIterator($directory)
/**
* {@inheritdoc}
*/
public function isEnabled()
{
if (!is_dir($directory)) {
$directory = $this->getApplication()->getKernel()->locateResource($directory);
}
return parent::getDirectoryIterator($directory);
return class_exists(BaseLintCommand::class) && parent::isEnabled();
}
protected function isReadable($fileOrDirectory)
protected function execute(InputInterface $input, OutputInterface $output)
{
return 0 === strpos($fileOrDirectory, '@') || parent::isReadable($fileOrDirectory);
return $this->command->execute($input, $output);
}
}

View File

@ -30,6 +30,16 @@ class LintCommand extends Command
private $parser;
private $format;
private $displayCorrectFiles;
private $directoryIteratorProvider;
private $isReadableProvider;
public function __construct($name = null, $directoryIteratorProvider = null, $isReadableProvider = null)
{
parent::__construct($name);
$this->directoryIteratorProvider = $directoryIteratorProvider;
$this->isReadableProvider = $isReadableProvider;
}
/**
* {@inheritdoc}
@ -170,14 +180,6 @@ EOF
}
}
protected function getDirectoryIterator($directory)
{
return new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
\RecursiveIteratorIterator::LEAVES_ONLY
);
}
private function getStdin()
{
if (0 !== ftell(STDIN)) {
@ -201,8 +203,32 @@ EOF
return $this->parser;
}
protected function isReadable($fileOrDirectory)
private function getDirectoryIterator($directory)
{
return is_readable($fileOrDirectory);
$default = function ($directory) {
return new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
\RecursiveIteratorIterator::LEAVES_ONLY
);
};
if (null !== $this->directoryIteratorProvider) {
return call_user_func($this->directoryIteratorProvider, $directory, $default);
}
return $default($directory);
}
private function isReadable($fileOrDirectory)
{
$default = function ($fileOrDirectory) {
return is_readable($fileOrDirectory);
};
if (null !== $this->isReadableProvider) {
return call_user_func($this->isReadableProvider, $fileOrDirectory, $default);
}
return $default($fileOrDirectory);
}
}