| 1 | <?php |
||
| 8 | class AppsServiceProvider extends ServiceProvider |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Bootstrap the service provider. |
||
| 12 | * |
||
| 13 | * @return void |
||
| 14 | */ |
||
| 15 | 2 | public function boot() |
|
| 16 | { |
||
| 17 | 2 | $this->macroUrlGenerator(); |
|
| 18 | |||
| 19 | if ($this->app->runningInConsole()) { |
||
| 20 | $this->publishAssets(); |
||
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Register macros for UrlGenerator. |
||
| 26 | * |
||
| 27 | * @return void |
||
| 28 | */ |
||
| 29 | protected function macroUrlGenerator() |
||
| 30 | { |
||
| 31 | $this->app['url']->macro('getRootControllerNamespace', function () { |
||
| 32 | return $this->rootNamespace; |
||
|
|
|||
| 33 | }); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Publish assets from package. |
||
| 38 | * |
||
| 39 | * @return void |
||
| 40 | */ |
||
| 41 | protected function publishAssets() |
||
| 42 | { |
||
| 43 | $this->publishes([ |
||
| 44 | __DIR__.'/../config/apps.php' => base_path('config/apps.php'), |
||
| 45 | ], 'laravel-apps'); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Register the service provider. |
||
| 50 | * |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | 2 | public function register() |
|
| 54 | { |
||
| 55 | 2 | $this->setupAssets(); |
|
| 56 | |||
| 57 | 2 | $this->app->singleton('apps', function ($app) { |
|
| 58 | return new Apps($app); |
||
| 59 | 2 | }); |
|
| 60 | 2 | $this->app->alias('apps', Apps::class); |
|
| 61 | 2 | } |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Setup package assets. |
||
| 65 | * |
||
| 66 | * @return void |
||
| 67 | */ |
||
| 68 | 2 | protected function setupAssets() |
|
| 76 | } |
||
| 77 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: