Example #1
0
 /**
  * Get all setting meta info.
  *
  * @return array
  */
 protected function getAllMeta()
 {
     if ($this->all === null) {
         $this->all = new Collection();
         foreach ($this->modules->enabled() as $module) {
             /* @var Module $module */
             $path = $module->getPath('Config/settings.php');
             if (is_file($path)) {
                 $config = (require $path);
                 if (array_key_exists('groups', $config)) {
                     foreach ((array) $config['groups'] as $name => $group) {
                         if (!is_array($group)) {
                             $group = ['caption' => $group];
                         }
                         if ($this->groups->has($name)) {
                             if (empty($group['slave'])) {
                                 throw new \RuntimeException('Settings group `' . $name . '` already defined.');
                             }
                             continue;
                         }
                         $this->groups->put($name, new Group($name, $group));
                     }
                 }
                 if (array_key_exists('settings', $config)) {
                     foreach ((array) $config['settings'] as $name => $option) {
                         $meta = new Meta($name, (array) $option);
                         $this->addMeta($meta);
                     }
                 }
             }
         }
     }
     return $this->all;
 }
Example #2
0
 /**
  * Boot the application events.
  *
  * @param ConfigRepository $config
  * @param Router $router
  * @param ModulesManager $modules
  */
 public function boot(ConfigRepository $config, Router $router, ModulesManager $modules)
 {
     $this->app->make('config')->set('auth.guards.backend', ['driver' => 'session', 'provider' => 'backend']);
     $this->app->make('config')->set('auth.providers.backend', ['driver' => 'eloquent', 'model' => UserEntity::class]);
     $modules->enabled()->each(function (Module $module) use($router) {
         $path = $module->getPath('Config/backend.php');
         if (file_exists($path)) {
             $value = (require_once $path);
             if (is_callable($value)) {
                 $this->app->call($value);
             } elseif (is_array($value)) {
                 if (array_key_exists('boot', $value) && is_callable($value['boot'])) {
                     $this->app->call($value['boot']);
                 }
             }
         }
     });
     $router->group(['as' => 'backend.', 'prefix' => $config->get('module.backend.path'), 'domain' => $config->get('module.backend.domain'), 'middleware' => ['backend']], function (Router $router) use($modules) {
         $router->get('auth/login', ['uses' => AuthController::class . '@getLogin', 'as' => 'auth']);
         $router->post('auth/login', ['uses' => AuthController::class . '@postLogin', 'as' => 'auth.login']);
         $router->get('auth/logout', ['uses' => AuthController::class . '@getLogout', 'as' => 'auth.logout']);
         $router->group(['middleware' => ['backend.auth']], function (Router $router) use($modules) {
             $router->get('', ['uses' => function () {
                 return view('backend::index');
             }, 'as' => 'index']);
             $modules->enabled()->each(function (Module $module) use($router) {
                 $path = $module->getPath('Config/backend.php');
                 if (file_exists($path)) {
                     $namespace = $module->getNamespace();
                     $router->group(['prefix' => $module->getName(), 'as' => $module->getName() . '.', 'namespace' => $namespace === null ? '' : trim($namespace, '\\') . '\\Http\\Controllers\\Backend'], function (Router $router) use($path) {
                         $value = (require $path);
                         //todo cache module backend config
                         if (is_array($value)) {
                             if (array_key_exists('routes', $value) && is_callable($value['routes'])) {
                                 $this->app->call($value['routes'], ['router' => $router]);
                             }
                         }
                     });
                 }
             });
         });
     });
 }