From 937100e9bb2a2f5ab035e283e01e6d96e569ee51 Mon Sep 17 00:00:00 2001 From: marvin-borner@live.com Date: Sat, 14 Apr 2018 21:01:44 +0200 Subject: Added login things --- login/app/system/UserFrosting.php | 187 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100755 login/app/system/UserFrosting.php (limited to 'login/app/system/UserFrosting.php') diff --git a/login/app/system/UserFrosting.php b/login/app/system/UserFrosting.php new file mode 100755 index 0000000..4f569ec --- /dev/null +++ b/login/app/system/UserFrosting.php @@ -0,0 +1,187 @@ +ci = new Container; + + // Set up facade reference to container. + Facade::setFacadeContainer($this->ci); + } + + /** + * Fires an event with optional parameters. + * + * @param string $eventName + * @param Event $event + * + * @return Event + */ + public function fireEvent($eventName, Event $event = null) + { + /** @var EventDispatcher $events */ + $eventDispatcher = $this->ci->eventDispatcher; + + return $eventDispatcher->dispatch($eventName, $event); + } + + /** + * Return the underlying Slim App instance, if available. + * + * @return Slim\App + */ + public function getApp() + { + return $this->app; + } + + /** + * Return the DI container. + * + * @return Slim\Container + */ + public function getContainer() + { + return $this->ci; + } + + /** + * Include all defined routes in route stream. + * + * Include them in reverse order to allow higher priority routes to override lower priority. + */ + public function loadRoutes() + { + // Since routes aren't encapsulated in a class yet, we need this workaround :( + global $app; + $app = $this->app; + + $routePaths = array_reverse($this->ci->locator->findResources('routes://', true, true)); + foreach ($routePaths as $path) { + $routeFiles = glob($path . '/*.php'); + foreach ($routeFiles as $routeFile) { + require_once $routeFile; + } + } + } + + /** + * Initialize the application. Set up Sprinkles and the Slim app, define routes, register global middleware, and run Slim. + */ + public function run() + { + $this->setupSprinkles(); + + // Set the configuration settings for Slim in the 'settings' service + $this->ci->settings = $this->ci->config['settings']; + + // Next, we'll instantiate the Slim application. Note that the application is required for the SprinkleManager to set up routes. + $this->app = new App($this->ci); + + $slimAppEvent = new SlimAppEvent($this->app); + + $this->fireEvent('onAppInitialize', $slimAppEvent); + + // Set up all routes + $this->loadRoutes(); + + // Add global middleware + $this->fireEvent('onAddGlobalMiddleware', $slimAppEvent); + + $this->app->run(); + } + + /** + * Register system services, load all sprinkles, and add their resources and services. + * + * @param bool $isWeb Set to true if setting up in an HTTP/web environment, false if setting up for CLI scripts. + */ + public function setupSprinkles($isWeb = true) + { + // Register system services + $serviceProvider = new ServicesProvider(); + $serviceProvider->register($this->ci); + + // Boot the Sprinkle manager, which creates Sprinkle classes and subscribes them to the event dispatcher + $sprinkleManager = $this->ci->sprinkleManager; + + try { + $sprinkleManager->initFromSchema(\UserFrosting\SPRINKLES_SCHEMA_FILE); + } catch (FileNotFoundException $e) { + if ($isWeb) { + $this->renderSprinkleErrorPage($e->getMessage()); + } else { + $this->renderSprinkleErrorCli($e->getMessage()); + } + } + + $this->fireEvent('onSprinklesInitialized'); + + // Add Sprinkle resources (assets, templates, etc) to locator + $sprinkleManager->addResources(); + $this->fireEvent('onSprinklesAddResources'); + + // Register Sprinkle services + $sprinkleManager->registerAllServices(); + $this->fireEvent('onSprinklesRegisterServices'); + } + + /** + * Render a basic error page for problems with loading Sprinkles. + */ + protected function renderSprinkleErrorPage($errorMessage = "") + { + ob_clean(); + $title = "UserFrosting Application Error"; + $errorMessage = "Unable to start site. Contact owner.

" . + "Version: UserFrosting ".\UserFrosting\VERSION."
" . + $errorMessage; + $output = sprintf( + "" . + "%s

%s

%s", + $title, + $title, + $errorMessage + ); + exit($output); + } + + /** + * Render a CLI error message for problems with loading Sprinkles. + */ + protected function renderSprinkleErrorCli($errorMessage = "") + { + exit($errorMessage . PHP_EOL); + } +} -- cgit v1.2.3