1 | <?php |
||
9 | class HashidServiceProvider extends ServiceProvider |
||
10 | { |
||
11 | /** |
||
12 | * Register the service provider. |
||
13 | * |
||
14 | * @return void |
||
15 | */ |
||
16 | 6 | public function register() |
|
23 | |||
24 | /** |
||
25 | * Setup package assets. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | 6 | protected function setupAssets() |
|
30 | { |
||
31 | 6 | if ($this->app instanceof LumenApplication) { |
|
32 | $this->app->configure('hashid'); // @codeCoverageIgnore |
||
33 | } |
||
34 | |||
35 | 6 | $this->mergeConfigFrom($config = __DIR__.'/../config/hashid.php', 'hashid'); |
|
36 | |||
37 | 6 | if ($this->app->runningInConsole()) { |
|
38 | 6 | $this->publishes([$config => base_path('config/hashid.php')], 'hashid'); |
|
39 | } |
||
40 | 6 | } |
|
41 | |||
42 | /** |
||
43 | * Register service bindings. |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | protected function registerServices() |
||
48 | { |
||
49 | 6 | $this->app->singleton('hashid', function ($app) { |
|
50 | 4 | return new HashidManager($app); |
|
51 | 6 | }); |
|
52 | 6 | $this->app->alias('hashid', HashidManager::class); |
|
53 | |||
54 | 6 | foreach ($this->getSingletonDrivers() as $class) { |
|
55 | 6 | $this->app->singleton( |
|
56 | 6 | $key = $this->getBindingKeyForDriver($class), |
|
57 | 6 | function () use ($class) { |
|
58 | 1 | return new $class; |
|
59 | 6 | } |
|
60 | ); |
||
61 | 6 | $this->app->alias($key, $class); |
|
62 | } |
||
63 | |||
64 | 6 | foreach ($this->getNonSingletonDrivers() as $class) { |
|
65 | 6 | $this->app->bind($this->getBindingKeyForDriver($class), $class); |
|
66 | } |
||
67 | 6 | } |
|
68 | |||
69 | /** |
||
70 | * Get singleton drivers classes. |
||
71 | * |
||
72 | * @return array |
||
73 | */ |
||
74 | 6 | protected function getSingletonDrivers() |
|
75 | { |
||
76 | return [ |
||
77 | 6 | Base64Driver::class, |
|
78 | Base64IntegerDriver::class, |
||
79 | HexDriver::class, |
||
80 | HexIntegerDriver::class, |
||
81 | ]; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Get non-singleton drivers classes. |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | 6 | protected function getNonSingletonDrivers() |
|
101 | |||
102 | /** |
||
103 | * Get the binding key for the driver class. |
||
104 | * |
||
105 | * @param string $class |
||
106 | * @return string |
||
107 | */ |
||
108 | 6 | protected function getBindingKeyForDriver($class) |
|
114 | |||
115 | /** |
||
116 | * Register console commands. |
||
117 | * |
||
118 | * @return void |
||
119 | */ |
||
120 | 6 | protected function registerCommands() |
|
129 | } |
||
130 |