|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Neurony\Revisions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Foundation\Application; |
|
6
|
|
|
use Illuminate\Support\Facades\File; |
|
7
|
|
|
use Illuminate\Support\Facades\Route; |
|
8
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
|
9
|
|
|
use Neurony\Revisions\Contracts\RevisionModelContract; |
|
10
|
|
|
use Neurony\Revisions\Models\Revision; |
|
11
|
|
|
|
|
12
|
|
|
class ServiceProvider extends BaseServiceProvider |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Create a new service provider instance. |
|
16
|
|
|
* |
|
17
|
|
|
* @param Application $app |
|
18
|
|
|
*/ |
|
19
|
|
|
public function __construct(Application $app) |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct($app); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Bootstrap the application services. |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
|
|
public function boot() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->publishConfigs(); |
|
32
|
|
|
$this->publishMigrations(); |
|
33
|
|
|
$this->registerRouteBindings(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Register the application services. |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
|
|
public function register() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->registerBindings(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function publishConfigs() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->publishes([ |
|
52
|
|
|
__DIR__.'/../config/revisions.php' => config_path('revisions.php'), |
|
53
|
|
|
], 'config'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function publishMigrations() |
|
60
|
|
|
{ |
|
61
|
|
|
if (empty(File::glob(database_path('migrations/*_create_revisions_table.php')))) { |
|
62
|
|
|
$timestamp = date('Y_m_d_His', time()); |
|
63
|
|
|
$migration = database_path("migrations/{$timestamp}_create_revisions_table.php"); |
|
64
|
|
|
|
|
65
|
|
|
$this->publishes([ |
|
66
|
|
|
__DIR__.'/../database/migrations/create_revisions_table.php.stub' => $migration, |
|
67
|
|
|
], 'migrations'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function registerRouteBindings() |
|
75
|
|
|
{ |
|
76
|
|
|
Route::model('revision', RevisionModelContract::class); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return void |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function registerBindings() |
|
83
|
|
|
{ |
|
84
|
|
|
$this->app->bind(RevisionModelContract::class, $this->config['revisions']['revision_model'] ?? Revision::class); |
|
|
|
|
|
|
85
|
|
|
$this->app->alias(RevisionModelContract::class, 'revision.model'); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: