11<?php namespace Stolz \SchemaSpy ;
22
3+ use Config ;
34use Illuminate \Console \Command as ConsoleCommand ;
45use Symfony \Component \Console \Input \InputArgument ;
56
@@ -27,31 +28,43 @@ class Command extends ConsoleCommand
2728 protected $ parameters = [];
2829
2930 /**
30- * Set parameters from config file
31+ * Set schemaspy command parameters.
3132 *
32- * @return Command
33+ * @return array
3334 */
34- protected function setParametersFromConfig ()
35+ protected function setParameters ()
3536 {
36- // Set output dir parameter
37- $ this ->parameters ['-o ' ] = config ('spy.output ' , app_path ('database/schema ' ));
37+ $ parameters = [];
38+
39+ // Set output directory
40+ $ parameters ['-o ' ] = Config::get ('spy.output ' , app_path ('database/schema ' ));
3841
39- // Set database connection parameters
40- $ connections = config ('database.connections ' , []);
41- $ connection = ($ this ->argument ('connection ' )) ?: config ('database.default ' );
42+ // Set database connection details
43+ $ connections = Config:: get ('database.connections ' , []);
44+ $ connection = ($ this ->argument ('connection ' )) ?: Config:: get ('database.default ' );
4245 if (isset ($ connections [$ connection ]))
4346 {
4447 $ this ->info ("Using ' $ connection' connection " );
4548
46- $ this -> parameters ['-host ' ] = $ connections [$ connection ]['host ' ];
47- $ this -> parameters ['-db ' ] = $ connections [$ connection ]['database ' ];
48- $ this -> parameters ['-u ' ] = $ connections [$ connection ]['username ' ];
49- $ this -> parameters ['-p ' ] = $ connections [$ connection ]['password ' ];
49+ $ parameters ['-host ' ] = $ connections [$ connection ]['host ' ];
50+ $ parameters ['-db ' ] = $ connections [$ connection ]['database ' ];
51+ $ parameters ['-u ' ] = $ connections [$ connection ]['username ' ];
52+ $ parameters ['-p ' ] = $ connections [$ connection ]['password ' ];
5053 }
5154 else
5255 $ this ->comment ("Unknown connection ' $ connection'. Command will fail unless you provide DB credentials. " );
5356
54- return $ this ;
57+ // Merge with user's parameters
58+ $ parameters = array_merge ($ parameters , Config::get ('spy.parameters ' , []));
59+
60+ // Ask for missing mandatory parameters
61+ if ( ! isset ($ parameters ['-db ' ]))
62+ $ parameters ['-db ' ] = $ this ->ask ('Enter database name ' );
63+
64+ if ( ! isset ($ parameters ['-u ' ]))
65+ $ parameters ['-u ' ] = $ this ->ask ('Enter database username ' );
66+
67+ return $ this ->parameters = $ parameters ;
5568 }
5669
5770 /**
@@ -61,25 +74,19 @@ protected function setParametersFromConfig()
6174 */
6275 public function fire ()
6376 {
64- // Merge automatic parameters with user configurable parameters
65- $ this ->parameters = array_merge ($ this ->setParametersFromConfig ()->parameters , config ('spy.arguments ' , []));
66-
67- // Ask for missing mandatory parameters
68- if ( ! isset ($ this ->parameters ['-db ' ]))
69- $ this ->parameters ['-db ' ] = $ this ->ask ('Enter database name ' );
70-
71- if ( ! isset ($ this ->parameters ['-u ' ]))
72- $ this ->parameters ['-u ' ] = $ this ->ask ('Enter database username ' );
77+ // Set schemaSpy parameters
78+ $ this ->setParameters ();
7379
7480 // Build command
75- $ command = config ('spy.command ' , 'java -jar schemaSpy.jar ' );
81+ $ command = Config::get ('spy.command ' , 'java -jar schemaSpy.jar ' );
82+
7683 foreach ($ this ->parameters as $ key => $ value )
7784 $ command .= " $ key $ value " ;
7885
7986 // Run command
8087 exec ($ command , $ output , $ returnValue );
8188
82- if ($ returnValue == 0 )
89+ if ($ returnValue === 0 )
8390 $ this ->info ('Files successfully written to ' . $ this ->parameters ['-o ' ]);
8491 else
8592 {
@@ -97,8 +104,8 @@ public function fire()
97104 */
98105 protected function getArguments ()
99106 {
100- return array (
101- array ( 'connection ' , InputArgument::OPTIONAL , 'Database connection name ' ) ,
102- ) ;
107+ return [
108+ [ 'connection ' , InputArgument::OPTIONAL , 'Database connection name ' , Config:: get ( ' database.default ' )] ,
109+ ] ;
103110 }
104111}
0 commit comments