App\services\PluginManager::getEnabledBootstrappers PHP Method

getEnabledBootstrappers() public method

Loads all bootstrap.php files of the enabled plugins.
public getEnabledBootstrappers ( ) : Collection
return Illuminate\Support\Collection
    public function getEnabledBootstrappers()
    {
        $bootstrappers = new Collection();
        foreach ($this->getEnabledPlugins() as $plugin) {
            if ($this->filesystem->exists($file = $plugin->getPath() . '/bootstrap.php')) {
                $bootstrappers->push($file);
            }
        }
        return $bootstrappers;
    }

Usage Example

 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot(PluginManager $plugins)
 {
     // store paths of class files of plugins
     $src_paths = [];
     $loader = $this->app->make('translation.loader');
     // make view instead of view.finder since the finder is defined as not a singleton
     $finder = $this->app->make('view');
     foreach ($plugins->getPlugins() as $plugin) {
         $src_paths[$plugin->getNameSpace()] = $plugin->getPath() . "/src";
         // add paths of translation files for namespace hints
         $loader->addNamespace($plugin->getNameSpace(), $plugin->getPath() . "/lang");
         // add paths of views
         $finder->addNamespace($plugin->getNameSpace(), $plugin->getPath() . "/views");
     }
     $this->registerClassAutoloader($src_paths);
     $bootstrappers = $plugins->getEnabledBootstrappers();
     foreach ($bootstrappers as $file) {
         $bootstrapper = (require $file);
         // call closure using service container
         $this->app->call($bootstrapper);
     }
 }