/** * Registers routes for the entire CMS. * * @return $this */ protected function registerViewComposers() { view()->composer($this->core->config('views.menu'), MenuComposer::class); view()->composer($this->core->config('views.top'), TopComposer::class); view()->composer($this->core->config('views.locale-switch'), LocaleComposer::class); return $this; }
/** * Registers any service providers listed in the core config. * * @return $this */ protected function registerConfiguredServiceProviders() { $providers = $this->core->apiConfig('providers', []); foreach ($providers as $provider) { $this->app->register($provider); } return $this; }
/** * Returns any previously flashed messages. * * @param bool $clear whether to delete the flashed messages from the session * @return array set of associative arrays with message, level keys */ public function getFlashed($clear = true) { $messages = $this->core->session()->get(static::SESSION_FLASH_KEY, []); if ($clear) { $this->core->session()->remove(static::SESSION_FLASH_KEY); } return $messages; }
/** * Returns the cacheTags to use, if any, or false if none set. * * @return string[]|false */ protected function getCacheTags() { $tags = $this->core->config('cache.tags', false); if (false === $tags || empty($tags)) { return false; } return is_array($tags) ? $tags : [$tags]; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param Closure $next * @param string|null $permission * @return mixed */ public function handle($request, Closure $next, $permission = null) { if ($permission && !$this->core->auth()->admin() && !$this->core->auth()->can($permission)) { if ($this->core->bootChecker()->isCmsApiRequest()) { return $this->core->api()->error('Permission denied', 403); } if ($request->ajax() || $request->wantsJson()) { return response('Permission denied.', 403); } /** @var CoreInterface $core */ $core = app(Component::CORE); return redirect()->route($core->prefixRoute(NamedRoute::HOME)); } return $next($request); }
/** * Formats an exception as a standardized error response. * * @param Exception $e * @param null|string $fallbackMessage message to use if exception has none * @return mixed */ protected function formatExceptionError(Exception $e, $fallbackMessage = null) { if (app()->isLocal() && $this->core->apiConfig('debug.local-exception-trace', true)) { return $this->formatExceptionErrorForLocal($e, $fallbackMessage); } $message = $e->getMessage() ?: $fallbackMessage; return ['message' => $message]; }
/** * Determines and returns the available locales for the application. * * @return string[] */ public function getAvailable() { // If explicitly set in CMS config, this overrules all else $configLocales = $this->core->config('locale.available'); if (is_array($configLocales)) { return $configLocales; } // Check if the localization package is used, and get locales from it $localizationLocales = $this->getLocalesForMcamaraLocalization(); if ($localizationLocales) { return $localizationLocales; } // Alternatively, check if translatable package locales are available $localizationLocales = $this->getLocalesForTranslatable(); if ($localizationLocales) { return $localizationLocales; } // Fallback is to check whether the default locale is equal to the fallback locale // If it isn't, we still have two locales to provide, otherwise localization is disabled. return array_unique([config('app.locale'), config('app.fallback_locale')]); }
/** * Loads the modules from the module manager and assigns them to the * configured groups. * * @return $this */ protected function loadMenuModules() { // Gather all modules with any menu inherent or overridden presence // and store them locally according to their nature. foreach ($this->core->modules()->getModules() as $moduleKey => $module) { // If the configuration has overriding data for this module's presence, // use it. Otherwise load the menu's own presence. // Normalize single & plural presences for each module. if ($this->isConfiguredModulePresenceDisabled($module)) { continue; } $configuredPresencesForModule = $this->getConfiguredModulePresence($module); $presencesForModule = $module->getMenuPresence(); $presencesForModule = $this->mergeNormalizedMenuPresences($presencesForModule, $configuredPresencesForModule); // If a module has no presence, skip it if (!$presencesForModule) { continue; } foreach ($this->normalizeMenuPresence($presencesForModule) as $presence) { $presence = $this->filterUnpermittedFromPresence($presence); if (!$presence) { continue; } if ($this->isMenuPresenceAlternative($presence)) { // If a menu presence is deemed 'alternative', it should not // appear in the normal menu structure. $this->alternativePresences->push($presence); } else { // Otherwise, determine whether it is assigned to a group // or should be left 'ungrouped'. $groupKey = $this->getConfiguredModuleGroupKey($module); $menuGroup = $this->findMenuGroupPresenceByKey($groupKey); if (false === $menuGroup) { $this->menuUngrouped->push($presence); } else { /** @var MenuPresenceInterface $menuGroup */ $menuGroup->addChild($presence); } } } } return $this; }
/** * Loads the ACL presences from modules and stores it normalized in the main presences collection. * * @return $this */ protected function loadAclModules() { // Gather all modules with any menu inherent or overridden presence // and store them locally according to their nature. foreach ($this->core->modules()->getModules() as $moduleKey => $module) { $presencesForModule = $module->getAclPresence(); // If a module has no presence, skip it if (!$presencesForModule) { continue; } if (!$this->modulePresences->has($moduleKey)) { $this->modulePresences->put($moduleKey, new Collection()); } foreach ($this->normalizeAclPresence($presencesForModule) as $presence) { if (!$presence) { continue; } $this->presences->push($presence); $this->modulePresences->get($moduleKey)->push($presence); } } return $this; }
/** * Returns the default action to bind to the root /. * * @return string|array */ protected function getDefaultHomeAction() { return $this->core->config('route.default'); }
/** * @return string */ protected function getLogoutMethod() { return $this->core->apiConfig('route.auth.method.logout', 'post'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param Closure $next * @return mixed */ public function handle($request, Closure $next) { $this->core->menu()->initialize(); return $next($request); }
/** * @return string */ protected function getSessionLocale() { $sessionKey = $this->core->config('session.prefix') . 'locale'; return session($sessionKey); }
/** * Returns the middleware group that all CMS API routes belongs to. * * @return string */ protected function getConfiguredApiGroupName() { return $this->core->apiConfig('middleware.group', 'cms-api'); }
/** * Loads the module class FQNs from the core config. */ protected function loadConfiguredModuleClasses() { $this->moduleClasses = $this->core->moduleConfig('modules', []); }