1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Morphatic\AutoDeploy; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Http\Kernel; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
|
8
|
|
|
class AutoDeployServiceProvider extends ServiceProvider |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Bootstrap the application services. |
12
|
|
|
*/ |
13
|
36 |
|
public function boot(Kernel $kernel) |
14
|
|
|
{ |
15
|
36 |
|
$this->registerMiddleware($kernel); |
16
|
36 |
|
$this->registerRoutes(); |
17
|
36 |
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Register the application services. |
21
|
|
|
*/ |
22
|
36 |
|
public function register() |
23
|
|
|
{ |
24
|
36 |
|
$this->registerConfig(); |
25
|
36 |
|
$this->registerDeployCommands(); |
26
|
36 |
|
$this->registerDeployOrigins(); |
27
|
36 |
|
$this->registerDeployController(); |
28
|
36 |
|
} |
29
|
|
|
|
30
|
36 |
|
private function registerConfig() |
31
|
|
|
{ |
32
|
36 |
|
$config = realpath(__DIR__.'/../config/config.php'); |
33
|
36 |
|
$this->publishes([ |
34
|
36 |
|
$config => config_path('auto-deploy.php'), |
35
|
18 |
|
]); |
36
|
36 |
|
} |
37
|
|
|
|
38
|
36 |
|
private function registerDeployCommands() |
39
|
|
|
{ |
40
|
|
|
$this->app->singleton('command.morphatic.deployinit', function($app) { |
41
|
10 |
|
return $app['Morphatic\AutoDeploy\Commands\DeployInitCommand']; |
42
|
36 |
|
}); |
43
|
|
|
|
44
|
36 |
|
$this->app->singleton('command.morphatic.deployinfo', function($app) { |
45
|
10 |
|
return $app['Morphatic\AutoDeploy\Commands\DeployInfoCommand']; |
46
|
36 |
|
}); |
47
|
|
|
|
48
|
36 |
|
$this->commands('command.morphatic.deployinit'); |
49
|
36 |
|
$this->commands('command.morphatic.deployinfo'); |
50
|
36 |
|
} |
51
|
|
|
|
52
|
36 |
|
private function registerDeployOrigins() |
53
|
|
|
{ |
54
|
36 |
|
$originTypes = ['Github']; |
55
|
36 |
|
foreach ($originTypes as $ot) { |
56
|
36 |
|
$this->app->bind('Morphatic\AutoDeploy\Origins\OriginInterface', 'Morphatic\AutoDeploy\Origins\\'.$ot); |
57
|
18 |
|
} |
58
|
36 |
|
} |
59
|
|
|
|
60
|
36 |
|
private function registerDeployController() |
61
|
|
|
{ |
62
|
36 |
|
$this->app->make('Morphatic\AutoDeploy\Controllers\DeployController'); |
63
|
36 |
|
} |
64
|
|
|
|
65
|
36 |
|
private function registerMiddleware(Kernel $kernel) |
66
|
|
|
{ |
67
|
|
|
// add our middleware at the beginning, before CSRF checking |
68
|
36 |
|
$kernel->prependMiddleware(Middleware\VerifyDeployRequest::class); |
69
|
36 |
|
} |
70
|
|
|
|
71
|
36 |
|
private function registerRoutes() |
72
|
|
|
{ |
73
|
|
|
// only register routes if the secret route has been set |
74
|
36 |
|
if (!empty($this->app['config']->get('auto-deploy.route'))) { |
75
|
|
|
// register the route |
76
|
24 |
|
include_once __DIR__.'/routes.php'; |
77
|
12 |
|
} else { |
78
|
|
|
// throw an exception? display a warning? |
79
|
|
|
} |
80
|
36 |
|
} |
81
|
|
|
} |
82
|
|
|
|