1212namespace FOS \JsRoutingBundle \Command ;
1313
1414use FOS \JsRoutingBundle \Extractor \ExposedRoutesExtractorInterface ;
15- use Symfony \Bundle \FrameworkBundle \Command \RouterDebugCommand ;
1615use Symfony \Bundle \FrameworkBundle \Console \Helper \DescriptorHelper ;
16+ use Symfony \Component \Console \Command \Command ;
17+ use Symfony \Component \Console \Input \InputArgument ;
1718use Symfony \Component \Console \Input \InputInterface ;
19+ use Symfony \Component \Console \Input \InputOption ;
1820use Symfony \Component \Console \Output \OutputInterface ;
1921use Symfony \Component \Routing \Route ;
22+ use Symfony \Component \Routing \RouterInterface ;
2023
2124/**
2225 * A console command for retrieving information about exposed routes.
2326 *
2427 * @author William DURAND <[email protected] > 2528 */
26- class RouterDebugExposedCommand extends RouterDebugCommand
29+ class RouterDebugExposedCommand extends Command
2730{
31+ protected static $ defaultName = 'fos:js-routing:debug ' ;
32+
33+ private $ extractor ;
34+
35+ private $ router ;
36+
37+ public function __construct (ExposedRoutesExtractorInterface $ extractor , RouterInterface $ router )
38+ {
39+ $ this ->extractor = $ extractor ;
40+ $ this ->router = $ router ;
41+
42+ parent ::__construct ();
43+ }
44+
45+
2846 /**
2947 * {@inheritdoc}
3048 */
3149 protected function configure ()
3250 {
33- parent ::configure ();
34-
3551 $ this
52+ ->setDefinition (array (
53+ new InputArgument ('name ' , InputArgument::OPTIONAL , 'A route name ' ),
54+ new InputOption ('show-controllers ' , null , InputOption::VALUE_NONE , 'Show assigned controllers in overview ' ),
55+ new InputOption ('format ' , null , InputOption::VALUE_REQUIRED , 'The output format (txt, xml, json, or md) ' , 'txt ' ),
56+ new InputOption ('raw ' , null , InputOption::VALUE_NONE , 'To output raw route(s) ' ),
57+ ))
3658 ->setName ('fos:js-routing:debug ' )
37- ->setAliases (array ()) // reset the aliases used by the parent command in Symfony 2.6+
3859 ->setDescription ('Displays currently exposed routes for an application ' )
3960 ->setHelp (<<<EOF
4061The <info>fos:js-routing:debug</info> command displays an application's routes which will be available via JavaScript.
@@ -55,44 +76,31 @@ protected function configure()
5576 */
5677 protected function execute (InputInterface $ input , OutputInterface $ output )
5778 {
58- /** @var ExposedRoutesExtractorInterface $extractor */
59- $ extractor = $ this ->getContainer ()->get ('fos_js_routing.extractor ' );
60-
6179 if ($ name = $ input ->getArgument ('name ' )) {
6280 /** @var Route $route */
63- $ route = $ this ->getContainer ()-> get ( ' router ' ) ->getRouteCollection ()->get ($ name );
81+ $ route = $ this ->router ->getRouteCollection ()->get ($ name );
6482
6583 if (!$ route ) {
6684 throw new \InvalidArgumentException (sprintf ('The route "%s" does not exist. ' , $ name ));
6785 }
6886
69- if (!$ extractor ->isRouteExposed ($ route , $ name )) {
87+ if (!$ this -> extractor ->isRouteExposed ($ route , $ name )) {
7088 throw new \InvalidArgumentException (sprintf ('The route "%s" was found, but it is not an exposed route. ' , $ name ));
7189 }
7290
73- if (!class_exists ('Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper ' )) {
74- // BC layer for Symfony 2.3
75- $ this ->outputRoute ($ output , $ name );
76- } else {
77- $ helper = new DescriptorHelper ();
78- $ helper ->describe ($ output , $ route , array (
79- 'format ' => $ input ->getOption ('format ' ),
80- 'raw_text ' => $ input ->getOption ('raw ' ),
81- 'show_controllers ' => $ input ->getOption ('show-controllers ' ),
82- ));
83- }
91+ $ helper = new DescriptorHelper ();
92+ $ helper ->describe ($ output , $ route , array (
93+ 'format ' => $ input ->getOption ('format ' ),
94+ 'raw_text ' => $ input ->getOption ('raw ' ),
95+ 'show_controllers ' => $ input ->getOption ('show-controllers ' ),
96+ ));
8497 } else {
85- if (!class_exists ('Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper ' )) {
86- // BC layer for Symfony 2.3
87- $ this ->outputRoutes ($ output , $ extractor ->getRoutes ());
88- } else {
89- $ helper = new DescriptorHelper ();
90- $ helper ->describe ($ output , $ extractor ->getRoutes (), array (
91- 'format ' => $ input ->getOption ('format ' ),
92- 'raw_text ' => $ input ->getOption ('raw ' ),
93- 'show_controllers ' => $ input ->getOption ('show-controllers ' ),
94- ));
95- }
98+ $ helper = new DescriptorHelper ();
99+ $ helper ->describe ($ output , $ this ->extractor ->getRoutes (), array (
100+ 'format ' => $ input ->getOption ('format ' ),
101+ 'raw_text ' => $ input ->getOption ('raw ' ),
102+ 'show_controllers ' => $ input ->getOption ('show-controllers ' ),
103+ ));
96104 }
97105 }
98106}
0 commit comments