1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Arcanedev\Support\Providers\Concerns; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Trait InteractsWithApplication |
9
|
|
|
* |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
trait InteractsWithApplication |
13
|
|
|
{ |
14
|
|
|
/* ----------------------------------------------------------------- |
15
|
|
|
| Main Methods |
16
|
|
|
| ----------------------------------------------------------------- |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Register multiple service providers. |
21
|
|
|
* |
22
|
|
|
* @param array $providers |
23
|
|
|
*/ |
24
|
|
|
protected function registerProviders(array $providers) |
25
|
|
|
{ |
26
|
|
|
foreach ($providers as $provider) { |
27
|
|
|
$this->registerProvider($provider); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Register a service provider. |
33
|
|
|
* |
34
|
|
|
* @param \Illuminate\Support\ServiceProvider|string $provider |
35
|
|
|
* @param bool $force |
36
|
|
|
* |
37
|
|
|
* @return \Illuminate\Support\ServiceProvider |
38
|
|
|
*/ |
39
|
|
|
protected function registerProvider($provider, $force = false) |
40
|
|
|
{ |
41
|
|
|
return $this->app->register($provider, $force); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Register a console service provider. |
46
|
|
|
* |
47
|
|
|
* @param \Illuminate\Support\ServiceProvider|string $provider |
48
|
|
|
* @param bool $force |
49
|
|
|
* |
50
|
|
|
* @return \Illuminate\Support\ServiceProvider|null |
51
|
|
|
*/ |
52
|
|
|
protected function registerConsoleServiceProvider($provider, $force = false) |
53
|
|
|
{ |
54
|
|
|
if ($this->app->runningInConsole()) { |
55
|
|
|
return $this->registerProvider($provider, $force); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Register the package's custom Artisan commands when running in console. |
63
|
|
|
* |
64
|
|
|
* @param array $commands |
65
|
|
|
*/ |
66
|
|
|
protected function registerCommands(array $commands) |
67
|
|
|
{ |
68
|
|
|
if ($this->app->runningInConsole()) { |
69
|
|
|
$this->commands($commands); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Register a binding with the container. |
75
|
|
|
* |
76
|
|
|
* @param string $abstract |
77
|
|
|
* @param \Closure|string|null $concrete |
78
|
|
|
* @param bool $shared |
79
|
|
|
*/ |
80
|
|
|
protected function bind($abstract, $concrete = null, $shared = false) |
81
|
|
|
{ |
82
|
|
|
$this->app->bind($abstract, $concrete, $shared); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Register a shared binding in the container. |
87
|
|
|
* |
88
|
|
|
* @param string|array $abstract |
89
|
|
|
* @param \Closure|string|null $concrete |
90
|
|
|
*/ |
91
|
|
|
protected function singleton($abstract, $concrete = null) |
92
|
|
|
{ |
93
|
|
|
$this->app->singleton($abstract, $concrete); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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: