|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GarbuzIvan\LaravelGeneratorPackage; |
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use GarbuzIvan\LaravelGeneratorPackage\Commands\MakeCommand; |
|
9
|
|
|
use GarbuzIvan\LaravelGeneratorPackage\Contracts\FieldInterface; |
|
10
|
|
|
use GarbuzIvan\LaravelGeneratorPackage\Form\Field; |
|
11
|
|
|
use GarbuzIvan\LaravelGeneratorPackage\Form\Form; |
|
12
|
|
|
|
|
13
|
|
|
class ServiceProvider extends \Illuminate\Support\ServiceProvider |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Bootstrap the application services... |
|
17
|
|
|
* |
|
18
|
|
|
* @return void |
|
19
|
|
|
*/ |
|
20
|
41 |
|
public function boot() |
|
21
|
|
|
{ |
|
22
|
41 |
|
if ($this->app->runningInConsole()) { |
|
23
|
41 |
|
$this->commands([ |
|
24
|
41 |
|
MakeCommand::class, |
|
25
|
|
|
]); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
41 |
|
$configPath = $this->configPath(); |
|
29
|
|
|
|
|
30
|
41 |
|
$this->publishes([ |
|
31
|
41 |
|
$configPath . '/config.php' => $this->publishPath('laravel-generator-package.php'), |
|
32
|
41 |
|
], 'config'); |
|
33
|
|
|
|
|
34
|
41 |
|
$this->loadMigrationsFrom(__DIR__ . '/../migrations'); |
|
35
|
41 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Register the application services. |
|
39
|
|
|
* |
|
40
|
|
|
* @return void |
|
41
|
|
|
* @throws Exception |
|
42
|
|
|
*/ |
|
43
|
41 |
|
public function register() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->app->singleton(Configuration::class, function() { |
|
46
|
40 |
|
return new Configuration; |
|
47
|
41 |
|
}); |
|
48
|
|
|
$this->app->bind(Field::class, function() { |
|
49
|
23 |
|
return new Field(app(Configuration::class)); |
|
50
|
41 |
|
}); |
|
51
|
|
|
$this->app->bind(Form::class, function() { |
|
52
|
4 |
|
return new Form(app(Configuration::class)); |
|
53
|
41 |
|
}); |
|
54
|
41 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
41 |
|
protected function configPath(): string |
|
60
|
|
|
{ |
|
61
|
41 |
|
return __DIR__ . '/../config'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param $configFile |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
41 |
|
protected function publishPath($configFile): string |
|
69
|
|
|
{ |
|
70
|
41 |
|
if (function_exists('config_path')) { |
|
71
|
41 |
|
return config_path($configFile); |
|
72
|
|
|
} else { |
|
73
|
|
|
return base_path('config/' . $configFile); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|