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