Skip to content

Commit 79eb738

Browse files
committed
Reverted support for Laravel 4
1 parent 58b5a6b commit 79eb738

File tree

4 files changed

+80
-34
lines changed

4 files changed

+80
-34
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ To configure the package use the following command to copy the configuration fil
4444

4545
All available settings are included inside `spy.php` and with the provided comments they should be self-explanatory.
4646

47+
## Laravel 4
48+
49+
If you are still using Laravel 4 instead of loading `Stolz\SchemaSpy\ServiceProvider` use `Stolz\SchemaSpy\LegacyServiceProvider` and manually copy the config file:
50+
51+
cp vendor/stolz/laravel-schema-spy/src/config.php app/config/spy.php
52+
4753
## License
4854

4955
MIT License
50-
(c) [Stolz](https://github.com/Stolz)
56+
© [Stolz](https://github.com/Stolz)
57+
58+
Read the provided `LICENSE` file for details.

src/Command.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Stolz\SchemaSpy;
22

3+
use Config;
34
use Illuminate\Console\Command as ConsoleCommand;
45
use 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
}

src/LegacyServiceProvider.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php namespace Stolz\SchemaSpy;
2+
3+
class LegacyServiceProvider extends \Illuminate\Support\ServiceProvider
4+
{
5+
/**
6+
* Register the service provider.
7+
*
8+
* @return void
9+
*/
10+
public function register()
11+
{
12+
// Bind 'stolz.schemaspy.command.spy' component to the IoC container
13+
$this->app->bind('stolz.schemaspy.command.spy', function ($app) {
14+
return new Command();
15+
});
16+
17+
// Add artisan command
18+
$this->commands('stolz.schemaspy.command.spy');
19+
}
20+
21+
/**
22+
* Bootstrap the application events.
23+
*
24+
* @return void
25+
*/
26+
public function boot()
27+
{
28+
//$this->package('stolz/spy', 'spy'); // Only valid if config file is at src/config/config.php
29+
$this->app->config->package('stolz/spy', __DIR__, 'spy');
30+
}
31+
}

src/config.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
| Base command to run schemaSpy.jar on your system
2222
|--------------------------------------------------------------------------
2323
|
24-
| No parameters here, instead use 'arguments' array below!
24+
| No parameters here, instead use the 'parameters' array below!
2525
|
2626
| Default: java -jar schemaSpy.jar
2727
|
@@ -31,17 +31,17 @@
3131

3232
/*
3333
|--------------------------------------------------------------------------
34-
| Extra parametes to pass to the command
34+
| Extra parameters to pass to the command
3535
|--------------------------------------------------------------------------
3636
|
37-
| Database connection settings will be read form Laravel database config so
38-
| there is no need to specify them here unless you want to override them.
37+
| Database connection settings will be read form Laravel's database config
38+
| file but they can be overridden here.
3939
|
40-
| Full list of possible arguments: http://schemaspy.sourceforge.net/
40+
| Full list of possible parameters: http://schemaspy.sourceforge.net/
4141
|
4242
*/
4343

44-
'arguments' => [
44+
'parameters' => [
4545
'-t' => 'mysql',
4646
'-dp' => '/path/to/mysql-connector-java-5.1.30-bin.jar', // download from http://dev.mysql.com/downloads/connector/j/
4747
'-hq' => null,

0 commit comments

Comments
 (0)