/** * Initializes the Cx class * This does everything related to Cloudrexx. * @param string $mode (optional) Use constants, one of self::MODE_[FRONTEND|BACKEND|CLI|MINIMAL] * @param string $configFilePath The absolute path to a Cloudrexx configuration * file (configuration.php) that shall be loaded * instead of the default one. * @param boolean $setAsPreferred Whether or not to set the Cx instance as preferred instance to be used */ protected function __construct($mode = null, $configFilePath = null, $setAsPreferred = false, $checkInstallationStatus = true) { // register this new Cx instance // will be used by \Cx\Core\Core\Controller\Cx::instanciate() self::registerInstance($this, $configFilePath, $setAsPreferred); try { /** * This starts time measurement * Timer will get stopped in finalize() method */ $this->startTimer(); /** * Load config/configuration.php */ $this->loadConfig($configFilePath); /** * Loads the basic configuration ($_CONFIG) from config/settings.php */ $this->loadSettings(); /** * Checks if the system has been installed (CONTREXX_INSTALLED). * If not, the user will be redirected to the web-installer. */ if ($checkInstallationStatus) { $this->checkInstallationStatus(); } /** * Verifies that the basic configuration ($_CONFIG) has bee loaded. * If not, the system will halt. */ $this->checkBasicConfiguration(); /** * Sets the path to the customizing directory (/customizing) of the website, * if the associated functionality has been activatd. */ $this->setCustomizingPath(); /** * Sets the mode Cloudrexx runs in * One of self::MODE_[FRONTEND|BACKEND|CLI|MINIMAL] */ $this->setMode($mode); /** * Early initializations. Verifies that the system is online (not suspended). * Initializes the ClassLoader, the legacy Environment variables and executes * the preInit-hook-scripts. Finally it verifies the requested HTTP-Host. */ $this->preInit(); /** * Defines the core constants (ASCMS_*) of Cloudrexx as defined in config/set_constants.php * and config/SetCustomizableConstants.php. */ $this->defineLegacyConstants(); /** * Loads ClassLoader, EventManager and Database connection * For now, this also loads some legacy things like API, AdoDB, Env and InitCMS */ $this->init(); /** * In order to make this file customizable, we explicitly * search for a subclass of Cx\Core\Core\Controller\Cx named Cx\Customizing\Core\Cx * If such a class is found, it is loaded and this request will be stopped */ $this->handleCustomizing(); /** * Initialize license */ $this->preComponentLoad(); /** * Loads all active components */ $this->loadComponents(); $this->postComponentLoad(); /** * Initialize request * Request is not initialized for command mode */ $this->postInit(); /** * Since we have a valid state now, we can start executing * all of the component's hook methods. * This initializes the main template, executes all hooks * and parses the template. * * This is not executed automaticly in minimal. Invoke it * yourself if necessary and be sure to handle exceptions. * * Command mode is different ;-) */ if ($this->mode == self::MODE_MINIMAL) { return; } $this->loadContrexx(); } catch (InstanceException $e) { return; } catch (\Cx\Core\Error\Model\Entity\ShinyException $e) { if ($this->mode != self::MODE_BACKEND) { throw new \Exception($e->getMessage()); } // reset root of Cx\Core\Html\Sigma to backend template path $this->template->setRoot($this->codeBaseAdminTemplatePath); $this->template->setVariable('ADMIN_CONTENT', $e->getBackendViewMessage()); $this->setPostContentLoadPlaceholders(); $this->finalize(); die; } catch (\Exception $e) { \header($_SERVER['SERVER_PROTOCOL'] . ' 500 Server Error'); if (file_exists($this->websiteDocumentRootPath . '/offline.html')) { $offlinePath = $this->websiteDocumentRootPath; } else { $offlinePath = $this->codeBaseDocumentRootPath; } echo file_get_contents($offlinePath . '/offline.html'); \DBG::msg('Cloudrexx initialization failed! ' . get_class($e) . ': "' . $e->getMessage() . '"'); \DBG::msg('In file ' . $e->getFile() . ' on Line ' . $e->getLine()); \DBG::dump($e->getTrace()); die; } }