11
11
12
12
namespace Symfony \Bundle \FrameworkBundle \Command ;
13
13
14
+ use Symfony \Component \Console \Command \Command ;
15
+ use Symfony \Component \Console \Input \InputInterface ;
16
+ use Symfony \Component \Console \Output \OutputInterface ;
14
17
use Symfony \Component \Yaml \Command \LintCommand as BaseLintCommand ;
15
18
16
19
/**
19
22
* @author Grégoire Pineau <lyrixx@lyrixx.info>
20
23
* @author Robin Chalas <robin.chalas@gmail.com>
21
24
*/
22
- class YamlLintCommand extends BaseLintCommand
25
+ class YamlLintCommand extends Command
23
26
{
27
+ private $ command ;
28
+
24
29
/**
25
30
* {@inheritdoc}
26
31
*/
27
32
protected function configure ()
28
33
{
29
- parent ::configure ();
34
+ $ this ->setName ('lint:yaml ' );
35
+
36
+ if (!$ this ->isEnabled () && null !== $ this ->command ) {
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
+ };
30
51
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
33
58
34
59
Or find all files in a bundle:
35
60
@@ -39,17 +64,16 @@ protected function configure()
39
64
);
40
65
}
41
66
42
- protected function getDirectoryIterator ($ directory )
67
+ /**
68
+ * {@inheritdoc}
69
+ */
70
+ public function isEnabled ()
43
71
{
44
- if (!is_dir ($ directory )) {
45
- $ directory = $ this ->getApplication ()->getKernel ()->locateResource ($ directory );
46
- }
47
-
48
- return parent ::getDirectoryIterator ($ directory );
72
+ return class_exists ('Symfony\Component\Yaml\Command\LintCommand ' ) && parent ::isEnabled ();
49
73
}
50
74
51
- protected function isReadable ( $ fileOrDirectory )
75
+ protected function execute ( InputInterface $ input , OutputInterface $ output )
52
76
{
53
- return 0 === strpos ( $ fileOrDirectory , ' @ ' ) || parent :: isReadable ( $ fileOrDirectory );
77
+ return $ this -> command -> execute ( $ input , $ output );
54
78
}
55
79
}
0 commit comments