1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Presspack\Framework\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Presspack\Framework\Post; |
7
|
|
|
use Presspack\Framework\Support\Translation\Strings; |
8
|
|
|
use Presspack\Framework\Support\Localization\Localize; |
9
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
10
|
|
|
use Presspack\Framework\Support\Facades\Strings as StringFacade; |
11
|
|
|
|
12
|
|
|
class ServiceProvider extends BaseServiceProvider |
13
|
|
|
{ |
14
|
|
|
protected $commands = [ |
15
|
|
|
'Presspack\Framework\Commands\SaltsGenerate', |
16
|
|
|
'Presspack\Framework\Commands\MakeCustomPostType', |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
public $singletons = [ |
20
|
|
|
'presspack/localize' => Localize::class, |
21
|
|
|
'presspack/strings' => Strings::class, |
22
|
|
|
]; |
23
|
|
|
public $facades = [ |
24
|
|
|
'presspack/post' => Post::class, |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Bootstrap the application services. |
29
|
|
|
*/ |
30
|
|
|
public function boot() |
31
|
|
|
{ |
32
|
|
|
if ($this->app->runningInConsole()) { |
33
|
|
|
$this->publishes([ |
34
|
|
|
__DIR__.'/../../config/presspack.php' => config_path('presspack.php'), |
|
|
|
|
35
|
|
|
], 'config'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (config('presspack.i18n')) { |
|
|
|
|
39
|
|
|
Str::macro('get', function (string $string) { |
40
|
|
|
return StringFacade::get($string); |
|
|
|
|
41
|
|
|
}); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Register the application services. |
47
|
|
|
*/ |
48
|
|
|
public function register() |
49
|
|
|
{ |
50
|
|
|
$this->commands($this->commands); |
51
|
|
|
|
52
|
|
|
$this->bindFacades(); |
53
|
|
|
$this->bindSingletons(); |
54
|
|
|
|
55
|
|
|
$this->mergeConfigFrom(__DIR__.'/../../config/presspack.php', 'presspack'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function bindFacades() |
59
|
|
|
{ |
60
|
|
|
foreach ($this->facades as $accessor => $class) { |
61
|
|
|
$this->app->bind($accessor, function ($class) { |
62
|
|
|
return new $class(); |
63
|
|
|
}); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function bindSingletons() |
68
|
|
|
{ |
69
|
|
|
foreach ($this->singletons as $accessor => $class) { |
70
|
|
|
$this->app->singleton($accessor, function ($class) { |
71
|
|
|
return new $class(); |
72
|
|
|
}); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|