コード例 #1
0
 /**
  * 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);
     }
 }
コード例 #2
0
 public function manage(Request $request, PluginManager $plugins)
 {
     if ($request->has('action') && $request->has('id')) {
         $id = $request->get('id');
         if ($plugins->getPlugins()->has($id)) {
             $plugin = $plugins->getPlugin($id);
             switch ($request->get('action')) {
                 case 'enable':
                     $plugins->enable($id);
                     return redirect('admin/plugins/manage');
                     break;
                 case 'disable':
                     $plugins->disable($id);
                     return redirect('admin/plugins/manage');
                     break;
                 case 'delete':
                     if ($request->isMethod('post')) {
                         event(new Events\PluginWasDeleted($plugin));
                         $plugins->uninstall($id);
                         return json('插件已被成功删除', 0);
                     }
                     break;
                 case 'config':
                     if ($plugin->isEnabled() && $plugin->hasConfigView()) {
                         return View::file($plugin->getViewPath('config'));
                     } else {
                         abort(404);
                     }
                     break;
                 default:
                     # code...
                     break;
             }
         }
     }
     $data = ['installed' => $plugins->getPlugins(), 'enabled' => $plugins->getEnabledPlugins()];
     return view('admin.plugins', $data);
 }