|
1
|
|
|
<?php namespace Arcanesoft\Foundation; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanesoft\Core\Bases\PackageServiceProvider; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class FoundationServiceProvider |
|
7
|
|
|
* |
|
8
|
|
|
* @package Arcanesoft\Foundation |
|
9
|
|
|
* @author ARCANEDEV <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class FoundationServiceProvider extends PackageServiceProvider |
|
12
|
|
|
{ |
|
13
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
14
|
|
|
| Properties |
|
15
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* Package name. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $package = 'foundation'; |
|
23
|
|
|
|
|
24
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
25
|
|
|
| Getters & Setters |
|
26
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
27
|
|
|
*/ |
|
28
|
|
|
/** |
|
29
|
|
|
* Get the base path of the package. |
|
30
|
|
|
* |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
24 |
|
public function getBasePath() |
|
34
|
|
|
{ |
|
35
|
24 |
|
return dirname(__DIR__); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
39
|
|
|
| Main Functions |
|
40
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
41
|
|
|
*/ |
|
42
|
|
|
/** |
|
43
|
|
|
* Register the service provider. |
|
44
|
|
|
*/ |
|
45
|
24 |
|
public function register() |
|
46
|
|
|
{ |
|
47
|
24 |
|
$this->registerConfig(); |
|
48
|
24 |
|
$this->registerSidebarItems(); |
|
49
|
24 |
|
$this->registerServiceProviders(); |
|
50
|
24 |
|
$this->registerFoundationService(); |
|
51
|
|
|
|
|
52
|
24 |
|
if ($this->app->runningInConsole()) { |
|
53
|
24 |
|
$this->app->register(Providers\CommandServiceProvider::class); |
|
54
|
18 |
|
} |
|
55
|
24 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Boot the service provider. |
|
59
|
|
|
*/ |
|
60
|
24 |
|
public function boot() |
|
61
|
|
|
{ |
|
62
|
24 |
|
$this->publishAll(); |
|
63
|
|
|
|
|
64
|
24 |
|
$this->app->register(Providers\RouteServiceProvider::class); |
|
65
|
24 |
|
$this->app->register(Providers\ComposerServiceProvider::class); |
|
66
|
24 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the services provided by the provider. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
4 |
|
public function provides() |
|
74
|
|
|
{ |
|
75
|
|
|
return ['arcanesoft.foundation']; |
|
76
|
4 |
|
} |
|
77
|
3 |
|
|
|
78
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
79
|
|
|
| Services Functions |
|
80
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
81
|
|
|
*/ |
|
82
|
|
|
/** |
|
83
|
|
|
* Register all the required service providers. |
|
84
|
|
|
*/ |
|
85
|
|
|
private function registerServiceProviders() |
|
86
|
|
|
{ |
|
87
|
24 |
|
$this->app->register(\Arcanesoft\Core\CoreServiceProvider::class); |
|
88
|
|
|
$this->app->register(Providers\PackagesServiceProvider::class); |
|
89
|
24 |
|
$this->app->register(Providers\ModuleServiceProvider::class); |
|
90
|
24 |
|
$this->app->register(Providers\AuthorizationServiceProvider::class); |
|
91
|
24 |
|
} |
|
92
|
24 |
|
|
|
93
|
24 |
|
/** |
|
94
|
|
|
* Register Foundation service. |
|
95
|
|
|
*/ |
|
96
|
|
|
private function registerFoundationService() |
|
97
|
|
|
{ |
|
98
|
24 |
|
$this->singleton('arcanesoft.foundation', Foundation::class); |
|
99
|
|
|
} |
|
100
|
24 |
|
|
|
101
|
24 |
|
/* ------------------------------------------------------------------------------------------------ |
|
102
|
|
|
| Package Functions |
|
103
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
104
|
|
|
*/ |
|
105
|
|
|
/** |
|
106
|
|
|
* Publish all the package files. |
|
107
|
|
|
* |
|
108
|
|
|
* @param bool $load |
|
109
|
|
|
*/ |
|
110
|
24 |
|
protected function publishAll($load = true) |
|
111
|
|
|
{ |
|
112
|
24 |
|
parent::publishAll($load); |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
$this->publishes([ |
|
115
|
24 |
|
$this->getBasePath() . '/resources/assets/dist' => public_path("vendor/{$this->package}"), |
|
116
|
24 |
|
], 'assets'); |
|
117
|
24 |
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: