1 | <?php |
||
8 | class HashidServiceProvider extends ServiceProvider |
||
9 | { |
||
10 | /** |
||
11 | * Indicates if loading of the provider is deferred. |
||
12 | * |
||
13 | * @var bool |
||
14 | */ |
||
15 | protected $defer = true; |
||
16 | |||
17 | /** |
||
18 | * Bootstrap the service provider. |
||
19 | * |
||
20 | * @return void |
||
21 | */ |
||
22 | 6 | public function boot() |
|
23 | { |
||
24 | // |
||
25 | 6 | } |
|
26 | |||
27 | /** |
||
28 | * Register the service provider. |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | 6 | public function register() |
|
33 | { |
||
34 | 6 | $this->setupAssets(); |
|
35 | |||
36 | 6 | $this->registerServices(); |
|
37 | 6 | $this->registerCommands(); |
|
38 | 6 | } |
|
39 | |||
40 | /** |
||
41 | * Setup package assets. |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | 6 | protected function setupAssets() |
|
46 | { |
||
47 | 6 | if (is_a($this->app, 'Laravel\Lumen\Application')) { |
|
48 | $this->app->configure('hashid'); |
||
|
|||
49 | } |
||
50 | |||
51 | 6 | $this->mergeConfigFrom($config = __DIR__.'/../config/hashid.php', 'hashid'); |
|
52 | |||
53 | 6 | if ($this->app->runningInConsole()) { |
|
54 | 6 | $this->publishes([$config => config_path('hashid.php')], 'hashid'); |
|
55 | 6 | } |
|
56 | 6 | } |
|
57 | |||
58 | /** |
||
59 | * Register service bindings. |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | 6 | protected function registerServices() |
|
64 | { |
||
65 | 6 | foreach ($this->getSingletonBindings() as $abstract => $concrete) { |
|
66 | 6 | $this->app->singleton($abstract, function ($app) use ($concrete) { |
|
67 | 6 | return $this->createInstance($concrete, [$app]); |
|
68 | 6 | }); |
|
69 | |||
70 | 6 | $this->app->alias($abstract, $concrete); |
|
71 | 6 | } |
|
72 | |||
73 | 6 | foreach ($this->getClassAliases() as $abstract => $alias) { |
|
74 | 6 | $this->app->alias($abstract, $alias); |
|
75 | 6 | } |
|
76 | 6 | } |
|
77 | |||
78 | /** |
||
79 | * Create a new instance from class name. |
||
80 | * |
||
81 | * @param string $class |
||
82 | * @param array $args |
||
83 | * @return mixed |
||
84 | */ |
||
85 | 5 | protected function createInstance($class, array $args = []) |
|
86 | { |
||
87 | 5 | $reflector = new ReflectionClass($class); |
|
88 | |||
89 | 5 | if (is_null($reflector->getConstructor())) { |
|
90 | return new $class; |
||
91 | } |
||
92 | |||
93 | 5 | return $reflector->newInstanceArgs($args); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Get singleton bindings to be registered. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | 6 | protected function getSingletonBindings() |
|
102 | { |
||
103 | return [ |
||
104 | 6 | 'hashid' => HashidManager::class, |
|
105 | 6 | 'hashid.driver.base64' => Base64Driver::class, |
|
106 | 6 | 'hashid.driver.base64.integer' => Base64IntegerDriver::class, |
|
107 | 6 | 'hashid.driver.hex' => HexDriver::class, |
|
108 | 6 | 'hashid.driver.hex.integer' => HexIntegerDriver::class, |
|
109 | 6 | ]; |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * Get class aliases to be registered. |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | 6 | protected function getClassAliases() |
|
118 | { |
||
119 | return [ |
||
120 | 6 | Base62Driver::class => 'hashid.driver.base62', |
|
121 | 6 | Base62IntegerDriver::class => 'hashid.driver.base62.integer', |
|
122 | 6 | OptimusDriver::class => 'hashid.driver.optimus', |
|
123 | 6 | ]; |
|
124 | } |
||
125 | |||
126 | /** |
||
127 | * Register console commands. |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | 6 | protected function registerCommands() |
|
139 | |||
140 | /** |
||
141 | * Get the services provided by the provider. |
||
142 | * |
||
143 | * @return string[] |
||
144 | */ |
||
145 | 2 | public function provides() |
|
152 | } |
||
153 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.