Skip to content

Commit 1794008

Browse files
author
Shawn McCool
committed
get further along towards Laravel 5 support
1 parent 4aed30b commit 1794008

File tree

5 files changed

+166
-9
lines changed

5 files changed

+166
-9
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@ composer require league/flysystem-sftp
5858

5959
#### Laravel Configuration
6060

61-
To install into a Laravel project, first do the composer install then add the following class to your config/app.php service providers list.
61+
To install into a Laravel project, first do the composer install then add **one of the following classes** to your config/app.php service providers list.
6262

6363
```php
64-
BackupManager\Laravel\BackupManagerServiceProvider::class,
64+
BackupManager\Laravel\Laravel4BackupManagerServiceProvider::class,
65+
```
66+
67+
or
68+
69+
```php
70+
BackupManager\Laravel\Laravel5BackupManagerServiceProvider::class,
6571
```
6672

6773
Copy the `config/storage.php` file to `app/config/packages/backup-manager/laravel/config/storage.php` and configure it to suit your needs.

src/BaseCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
/**
77
* Class BaseCommand
8-
* @package BackupManager\Laravel4
8+
* @package BackupManager\Laravel
99
*/
1010
class BaseCommand extends Command {
1111

src/DbBackupCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
* Class ManagerBackupCommand
10-
* @package BackupManager\Laravel4
10+
* @package BackupManager\Laravel
1111
*/
1212
class DbBackupCommand extends BaseCommand {
1313

src/BackupManagerServiceProvider.php renamed to src/Laravel4BackupManagerServiceProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
/**
1212
* Class BackupManagerServiceProvider
13-
* @package BackupManager\Laravel4
13+
* @package BackupManager\Laravel
1414
*/
15-
class BackupManagerServiceProvider extends ServiceProvider {
15+
class Laravel4BackupManagerServiceProvider extends ServiceProvider {
1616

1717
protected $defer = true;
1818

@@ -102,9 +102,9 @@ private function registerShellProcessor() {
102102
*/
103103
private function registerArtisanCommands() {
104104
$this->commands([
105-
\BackupManager\Laravel4\DbBackupCommand::class,
106-
\BackupManager\Laravel4\DbRestoreCommand::class,
107-
\BackupManager\Laravel4\DbListCommand::class
105+
\BackupManager\Laravel\DbBackupCommand::class,
106+
\BackupManager\Laravel\DbRestoreCommand::class,
107+
\BackupManager\Laravel\DbListCommand::class
108108
]);
109109
}
110110

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php namespace BackupManager\Laravel;
2+
3+
use BackupManager\Databases;
4+
use BackupManager\Filesystems;
5+
use BackupManager\Compressors;
6+
use Symfony\Component\Process\Process;
7+
use Illuminate\Support\ServiceProvider;
8+
use BackupManager\Config\Config;
9+
use BackupManager\ShellProcessing\ShellProcessor;
10+
11+
/**
12+
* Class BackupManagerServiceProvider
13+
* @package BackupManager\Laravel
14+
*/
15+
class Laravel4BackupManagerServiceProvider extends ServiceProvider {
16+
17+
protected $defer = true;
18+
19+
/**
20+
* Bootstrap the application events.
21+
*
22+
* @return void
23+
*/
24+
public function boot() {
25+
$this->package('backup-manager/laravel-4', 'backup-manager', realpath(app_path("config/packages/backup-manager/laravel-4")));
26+
}
27+
28+
/**
29+
* Register the service provider.
30+
*
31+
* @return void
32+
*/
33+
public function register() {
34+
$this->registerFilesystemProvider();
35+
$this->registerDatabaseProvider();
36+
$this->registerCompressorProvider();
37+
$this->registerShellProcessor();
38+
$this->registerArtisanCommands();
39+
}
40+
41+
/**
42+
* Register the filesystem provider.
43+
*
44+
* @return void
45+
*/
46+
private function registerFilesystemProvider() {
47+
$this->app->bind(\BackupManager\Filesystems\FilesystemProvider::class, function ($app) {
48+
$provider = new Filesystems\FilesystemProvider(new Config($app['config']['backup-manager::storage']));
49+
$provider->add(new Filesystems\Awss3Filesystem);
50+
$provider->add(new Filesystems\DropboxFilesystem);
51+
$provider->add(new Filesystems\FtpFilesystem);
52+
$provider->add(new Filesystems\LocalFilesystem);
53+
$provider->add(new Filesystems\RackspaceFilesystem);
54+
$provider->add(new Filesystems\SftpFilesystem);
55+
return $provider;
56+
});
57+
}
58+
59+
/**
60+
* Register the database provider.
61+
*
62+
* @return void
63+
*/
64+
private function registerDatabaseProvider() {
65+
$this->app->bind(\BackupManager\Databases\DatabaseProvider::class, function ($app) {
66+
$provider = new Databases\DatabaseProvider($this->getDatabaseConfig($app['config']['database.connections']));
67+
$provider->add(new Databases\MysqlDatabase);
68+
$provider->add(new Databases\PostgresqlDatabase);
69+
return $provider;
70+
});
71+
}
72+
73+
/**
74+
* Register the compressor provider.
75+
*
76+
* @return void
77+
*/
78+
private function registerCompressorProvider() {
79+
$this->app->bind(\BackupManager\Compressors\CompressorProvider::class, function () {
80+
$provider = new Compressors\CompressorProvider;
81+
$provider->add(new Compressors\GzipCompressor);
82+
$provider->add(new Compressors\NullCompressor);
83+
return $provider;
84+
});
85+
}
86+
87+
/**
88+
* Register the filesystem provider.
89+
*
90+
* @return void
91+
*/
92+
private function registerShellProcessor() {
93+
$this->app->bind(\BackupManager\ShellProcessing\ShellProcessor::class, function () {
94+
return new ShellProcessor(new Process(''));
95+
});
96+
}
97+
98+
/**
99+
* Register the artisan commands.
100+
*
101+
* @return void
102+
*/
103+
private function registerArtisanCommands() {
104+
$this->commands([
105+
\BackupManager\Laravel\DbBackupCommand::class,
106+
\BackupManager\Laravel\DbRestoreCommand::class,
107+
\BackupManager\Laravel\DbListCommand::class
108+
]);
109+
}
110+
111+
/**
112+
* Get the services provided by the provider.
113+
*
114+
* @return array
115+
*/
116+
public function provides() {
117+
return [
118+
\BackupManager\Filesystems\FilesystemProvider::class,
119+
\BackupManager\Databases\DatabaseProvider::class,
120+
\BackupManager\ShellProcessing\ShellProcessor::class,
121+
];
122+
}
123+
124+
private function getDatabaseConfig($connections) {
125+
$mapped = array_map(function ($connection) {
126+
if ( ! in_array($connection['driver'], ['mysql', 'pgsql'])) {
127+
return;
128+
}
129+
130+
if (isset($connection['port'])) {
131+
$port = $connection['port'];
132+
} else {
133+
if ($connection['driver'] == 'mysql') {
134+
$port = '3306';
135+
} elseif ($connection['driver'] == 'pgsql') {
136+
$port = '5432';
137+
}
138+
}
139+
140+
return [
141+
'type' => $connection['driver'],
142+
'host' => $connection['host'],
143+
'port' => $port,
144+
'user' => $connection['username'],
145+
'pass' => $connection['password'],
146+
'database' => $connection['database'],
147+
];
148+
}, $connections);
149+
return new Config($mapped);
150+
}
151+
}

0 commit comments

Comments
 (0)