Example #1
0
 /**
  * Register a \Cx\Core\Core\Controller\Cx compatible object as new instance
  *
  * @param   \Cx\Core\Core\Controller\Cx $cx Instanciated Cx object
  * @param   string $configFilePath The absolute path to a Cloudrexx configuration file (configuration.php).
  * @param   boolean $setAsPreferred Whether or not to set the Cx instance as preferred instance to be used
  */
 public static function registerInstance($cx, $configFilePath = null, $setAsPreferred = false)
 {
     if (!isset(self::$instances[null])) {
         $key = null;
     } else {
         $key = spl_object_hash($cx);
     }
     self::$autoIncrementValueOfId++;
     $cx->setId(self::$autoIncrementValueOfId);
     if (!count(self::$instances) || $setAsPreferred) {
         self::$preferredInstance = $cx;
     }
     if (!isset(self::$instances[$configFilePath])) {
         self::$instances[$configFilePath] = array();
     }
     self::$instances[$configFilePath][] = $cx;
 }
Example #2
0
 /**
  * Initializes the Cx class
  * This does everything related to Contrexx.
  * @param string $mode (optional) Use constants, one of self::MODE_[FRONTEND|BACKEND|CLI|MINIMAL]
  * @param string $configFilePath The absolute path to a Contrexx configuration
  *                               file (configuration.php) that shall be loaded
  *                               instead of the default one.
  */
 protected function __construct($mode = null, $configFilePath = null, $setAsPreferred = false, $checkInstallationStatus = true)
 {
     /** setting up id of new initialized object**/
     self::$autoIncrementValueOfId++;
     $this->id = self::$autoIncrementValueOfId;
     if (!count(self::$instances) || $setAsPreferred) {
         self::$preferredInstance = $this;
     }
     if (!isset(self::$instances[$configFilePath])) {
         self::$instances[$configFilePath] = array();
     }
     self::$instances[$configFilePath][] = $this;
     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 Contrexx 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 Contrexx 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();
         /**
          * Load all components to have them ready and initialize request and license
          * Request is not initialized for command mode
          */
         $this->postInit();
         /*
          * Loads all active components
          */
         $this->loadComponents();
         /**
          * 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('Contrexx initialization failed! ' . get_class($e) . ': "' . $e->getMessage() . '"');
         \DBG::msg('In file ' . $e->getFile() . ' on Line ' . $e->getLine());
         \DBG::dump($e->getTrace());
         die;
     }
 }