Example #1
0
 /**
  * Bootstrap the application and
  * call the other bootstrap classes
  * from the projects (if they exist)
  *
  * @return self
  */
 public function bootstrap($environment = Application::ENVIRONMENT_WEB)
 {
     static::$environment = $environment;
     // Setup application
     $this->setup();
     try {
         Buffer::start();
         // Call own bootstrap
         (new Bootstrap($this))->autoCall();
         // Call bootstrap of active project
         $project = ProjectManager::getActiveProject();
         if ($project) {
             // Save it in case for further use
             $bootstrap = $project->bootstrap($this);
         }
     } catch (\Exception $err) {
         switch (static::$environment) {
             case Application::ENVIRONMENT_WEB:
                 self::renderException(array($err));
                 break;
             case Application::ENVIRONMENT_CMD:
                 throw $err;
                 break;
         }
     }
     return $this;
 }
Example #2
0
 public static function getInstance($refresh = false)
 {
     if (is_null(static::$environment) || $refresh) {
         static::$environment = new static();
     }
     return static::$environment;
 }
 /**
  * Resolve locale
  *
  * @return mixed
  */
 public function resolve()
 {
     if (static::$environment !== null) {
         return static::$environment;
     }
     $language = setlocale(LC_ALL, 0);
     $languages = explode(';', $language);
     $languageArray = [];
     foreach ($languages as $locale) {
         if (strpos($locale, '=') !== false) {
             $language = substr($locale, strpos($locale, '='));
             $language = substr($language, 1);
         }
         if ($language !== 'C') {
             if (strpos($language, '.') !== false) {
                 $language = substr($language, 0, strpos($language, '.'));
             } else {
                 if (strpos($language, '@') !== false) {
                     $language = substr($language, 0, strpos($language, '@'));
                 }
             }
             $language = str_ireplace(array_keys(Data::$languages), array_values(Data::$languages), (string) $language);
             $language = str_ireplace(array_keys(Data::$regions), array_values(Data::$regions), $language);
             $languageArray[$language] = 1;
             if (strpos($language, '_') !== false) {
                 $languageArray[substr($language, 0, strpos($language, '_'))] = 1;
             }
         }
     }
     static::$environment = $languageArray;
     return !empty($languageArray) ? array_keys($languageArray)[0] : null;
 }
Example #4
0
 /**
  * Check environment
  *
  * @return void
  */
 public static function checkEnv()
 {
     if (static::$environment == null) {
         static::$environment = \App::environment();
     }
     // use only local files in local environment
     if (static::$environment == 'local' && static::$domain != '/') {
         static::$domain = '/';
     }
 }
Example #5
0
 /**
  * Load config
  * @return Config
  * @throws AppException
  */
 public static function load()
 {
     global $CONFIG;
     static::$environment = new Environment($_SERVER);
     $appName = static::getApp();
     $appPath = APPS_PATH . DS . $appName . DS . 'config' . DS;
     $appConfigPath = $appPath . 'conf.php';
     if (file_exists($appConfigPath)) {
         include $appConfigPath;
         //error_log('CONFIG: '.var_export($CONFIG, true));
     } else {
         error_log('App config not set: ' . $appName);
     }
     $routesConfig = array();
     $routesConfigPath = $appPath . 'routes.php';
     if (file_exists($routesConfigPath)) {
         include $routesConfigPath;
     } else {
         throw new AppException('Routes not set for the app ' . $appName);
     }
     return new static($appName, $routesConfig);
 }
Example #6
0
 /**
  * start the ccf lifecycle
  *
  * this method sets the current environment, loads the configuration
  * and wakes the application
  *
  * @param string			$environment
  * @return void
  */
 public static function wake($environment)
 {
     if (!is_null(static::$environment)) {
         throw new CCException("ClanCats::wake - you cannot wake the application twice.");
     }
     // set environment
     static::$environment = $environment;
     // load the main configuration
     static::$config = CCConfig::create('main');
     // setup the application error tables
     CCError_Inspector::info_callback('ClanCatsFramework', function () {
         return array('Runtime Class' => \ClanCats::runtime(), 'CCF Version' => \ClanCats::version(), 'CCF Environment' => \ClanCats::environment(), 'Development env' => var_export(\ClanCats::in_development(), true), 'File extention' => EXT, 'Core namespace' => CCCORE_NAMESPACE);
     });
     CCError_Inspector::info_callback('CCF Paths', array('ClanCats', 'paths'));
     CCError_Inspector::info_callback('CCF Directories', array('ClanCats', 'directories'));
     CCError_Inspector::info_callback('Namespaces', function () {
         return \CCFinder::$namespaces;
     });
 }
Example #7
0
 /**
  * Verify application environment
  *
  * Priority of different entries
  *
  *  1. Load specified in file via `define('APPLICATION_ENV', <evn-value>)`;
  *  2. Load specified value via `Pi::environment('<env-value>')`;
  *  3. Load via `getenv('APPLICATION_ENV')`
  *      - set in `.htaccess` via `SetEnv APPLICATION_ENV <env-value>`;
  *  4. Load from system config via `Pi::config('environment')`
  *      - set in `var/config/engine.php`.
  *
  * @param string|null $environment
  * @return null|string
  * @api
  */
 public static function environment($environment = null)
 {
     if (null !== $environment) {
         static::$environment = $environment;
         return;
     }
     $result = static::DEFAULT_APPLICATION_ENV;
     if (defined('APPLICATION_ENV')) {
         $result = constant('APPLICATION_ENV');
     } elseif (static::$environment) {
         $result = static::$environment;
     } elseif (getenv('APPLICATION_ENV')) {
         $result = getenv('APPLICATION_ENV');
     } elseif (static::config('environment')) {
         $result = static::config('environment');
     }
     return $result;
 }
Example #8
0
 public static function setEnvironment($environment)
 {
     static::$environment = $environment;
 }
 /**
  * {@inheritdoc}
  */
 public static function setUpBeforeClass()
 {
     static::$environment = new Twig_Environment(new Twig_Loader_Filesystem(__DIR__ . static::$RESOURCE_PATH), ['strict_variables' => true]);
     static::$environment->addExtension(new TwigExcelExtension());
     static::$environment->setCache(__DIR__ . static::$TEMP_PATH);
 }
Example #10
0
 static function setEnvironment(Environment $env)
 {
     static::$environment = $env;
 }