|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Vinelab\UrlShortener; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class UrlShortenerServiceProvider. |
|
9
|
|
|
* |
|
10
|
|
|
* @category The package service provider |
|
11
|
|
|
* |
|
12
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class UrlShortenerServiceProvider extends ServiceProvider |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Indicates if loading of the provider is deferred. |
|
18
|
|
|
* |
|
19
|
|
|
* @var bool |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $defer = false; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Boot the package. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function boot() |
|
27
|
|
|
{ |
|
28
|
|
|
/* |
|
29
|
|
|
|-------------------------------------------------------------------------- |
|
30
|
|
|
| Publish the Config file from the Package to the App directory |
|
31
|
|
|
|-------------------------------------------------------------------------- |
|
32
|
|
|
*/ |
|
33
|
|
|
$this->configPublisher(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Register the service provider. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function register() |
|
40
|
|
|
{ |
|
41
|
|
|
/* |
|
42
|
|
|
|-------------------------------------------------------------------------- |
|
43
|
|
|
| Implementation Bindings |
|
44
|
|
|
|-------------------------------------------------------------------------- |
|
45
|
|
|
*/ |
|
46
|
|
|
$this->implementationBindings(); |
|
47
|
|
|
|
|
48
|
|
|
/* |
|
49
|
|
|
|-------------------------------------------------------------------------- |
|
50
|
|
|
| Facade Bindings |
|
51
|
|
|
|-------------------------------------------------------------------------- |
|
52
|
|
|
*/ |
|
53
|
|
|
$this->facadeBindings(); |
|
54
|
|
|
|
|
55
|
|
|
/* |
|
56
|
|
|
|-------------------------------------------------------------------------- |
|
57
|
|
|
| Registering Service Providers |
|
58
|
|
|
|-------------------------------------------------------------------------- |
|
59
|
|
|
*/ |
|
60
|
|
|
$this->serviceProviders(); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the services provided by the provider. |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public function provides() |
|
69
|
|
|
{ |
|
70
|
|
|
return []; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Publish the Config file from the Package to the App directory. |
|
75
|
|
|
*/ |
|
76
|
|
|
private function configPublisher() |
|
77
|
|
|
{ |
|
78
|
|
|
// When users execute Laravel's vendor:publish command, the config file will be copied to the specified location |
|
79
|
|
|
$this->publishes([ |
|
80
|
|
|
__DIR__.'/Config/url-shortener.php' => config_path('url-shortener.php'), |
|
81
|
|
|
]); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Facades Binding. |
|
86
|
|
|
*/ |
|
87
|
|
|
private function facadeBindings() |
|
88
|
|
|
{ |
|
89
|
|
|
// Register 'vinelab.shorten' instance container |
|
90
|
|
|
$this->app['vinelab.shorten'] = $this->app->share(function ($app) { |
|
|
|
|
|
|
91
|
|
|
return $app->make('Vinelab\UrlShortener\Shorten'); |
|
92
|
|
|
}); |
|
93
|
|
|
|
|
94
|
|
|
// Register 'Shorten' Alias, So users don't have to add the Alias to the 'app/config/app.php' |
|
95
|
|
|
$this->app->booting(function () { |
|
96
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
|
97
|
|
|
$loader->alias('Shorten', 'Vinelab\UrlShortener\Facades\ShortenFacadeAccessor'); |
|
98
|
|
|
}); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Implementation Bindings. |
|
103
|
|
|
*/ |
|
104
|
|
|
private function implementationBindings() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->app->bind( |
|
107
|
|
|
'Vinelab\UrlShortener\Contracts\ShortenInterface', |
|
108
|
|
|
'Vinelab\UrlShortener\Shorten' |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Registering Other Custom Service Providers. |
|
114
|
|
|
*/ |
|
115
|
|
|
private function serviceProviders() |
|
116
|
|
|
{ |
|
117
|
|
|
// $this->app->register('Vinelab\...\...'); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: