Example #1
0
 /**
  *	_configure
  *	@param \Touchbase\Core\Config\Store
  *	@return Touchbase\Core\Config\Store
  */
 private function _configure(ConfigStore $config)
 {
     $ns = $src = "";
     try {
         //Load Main Configuration File
         $configurationData = IniConfigProvider::create()->parseIniFile(File::create([BASE_PATH, 'config.ini']));
         $config->addConfig($configurationData->getConfiguration());
         $ns = $config->get("project")->get("namespace", "Project");
         $src = $config->get("project")->get("source", "src");
         //Load Extra Configuration Files
         $loadExtraConfig = function ($files, $configFilePath = BASE_PATH) use(&$loadExtraConfig, &$config) {
             if (!empty($files)) {
                 foreach ($files as $condition => $file) {
                     $extraConfigFile = File::create([$configFilePath, $file]);
                     //Not a domain, path or environment - load always
                     if (is_numeric($condition)) {
                         if ($extraConfigFile->exists()) {
                             $configurationData = IniConfigProvider::create()->parseIniFile($extraConfigFile);
                             $config->addConfig($extraConfig = $configurationData->getConfiguration());
                             $loadExtraConfig($extraConfig->get("config")->get("files", ""), File::buildPath($configFilePath, dirname($file)));
                         }
                         //We want to match a certain condition
                     } else {
                         if ((!Router::isCLI() && strpos(@$_SERVER['HTTP_X_FORWARDED_HOST'] ?: $_SERVER['HTTP_HOST'], $condition) !== false || !Router::isCLI() && strpos($_SERVER["REQUEST_URI"], $condition) === 0 || !Router::isCLI() && strpos($_SERVER["SERVER_NAME"], $condition) === 0 || strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN' && $condition == "windows" || defined("TOUCHBASE_ENV") && TOUCHBASE_ENV == $condition) && $extraConfigFile->exists()) {
                             $configurationData = IniConfigProvider::create()->parseIniFile($extraConfigFile);
                             $config->addConfig($extraConfig = $configurationData->getConfiguration());
                             $loadExtraConfig($extraConfig->get("config")->get("files", ""), File::buildPath($configFilePath, dirname($file)));
                         }
                     }
                 }
             }
         };
         $loadExtraConfig($config->get("config")->get("files", ""));
         StaticStore::shared()->set(ConfigStore::CONFIG_KEY, $config);
     } catch (\Exception $e) {
     }
     if (!defined('PROJECT_PATH')) {
         $psr0 = realpath(File::buildPath(BASE_PATH, $src, $ns));
         $psr4 = realpath(File::buildPath(BASE_PATH, $src));
         define('PROJECT_PATH', $psr0 ?: $psr4);
     }
     return $config;
 }
Example #2
0
 /**
  *	Handler
  *	This method handles the displaying of the error message
  *	@param int $errorType
  *	@param string $errorMessage
  *	@param string $errorFile
  *	@param int $errorLine
  *	@param array $errorContext
  *	@return VOID
  */
 private function handler($errorType, $errorMessage, $errorFile = null, $errorLine = 0, $errorContext = array())
 {
     if (in_array($errorType, array(E_CORE_WARNING, E_CORE_ERROR))) {
         return;
     }
     //Lets add the real line and file number to errors that have been thrown via `trigger_error`
     if (in_array($errorType, self::$userErrors)) {
         $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4 + (self::$callerBacktraceBump ? self::$callerBacktraceBump-- : 0));
         $caller = end($backtrace);
         $errorFile = $caller['file'];
         $errorLine = $caller['line'];
     }
     error_log(sprintf($cliError = "PHP %s: %s in %s on line %d", $this->errorText[$errorType], $errorMessage, $errorFile, $errorLine));
     print sprintf(Router::isCLI() ? $cliError : "<pre><strong>%s:</strong> %s in <strong>%s</strong> on line <strong>%d</strong></pre>", $this->errorText[$errorType], $errorMessage, $errorFile, $errorLine);
     //Kill the application if required.
     if (in_array($errorType, self::$terminalErrors)) {
         exit;
     }
 }