Пример #1
0
 /** 
  *	Shared
  *	@return \Parse\Control\Client
  */
 public static function shared()
 {
     $instance = StaticStore::shared()->get(self::CLIENT_KEY, false);
     if (!$instance || is_null($instance)) {
         $config = ConfigStore::create();
         try {
             //Load Main Configuration File
             $configurationData = IniConfigProvider::create()->parseIniFile(File::create('../config.ini'));
             $config->addConfig($configurationData->getConfiguration());
         } catch (\Exception $e) {
         }
         //Validation
         if (!$config instanceof ConfigStore) {
             throw new \RuntimeException("No configuration settings found.");
         }
         $instanceName = $config->get("client")->get("provider", "\\Touchbase\\API\\Client\\Provider\\CurlClientProvider");
         $instance = new $instanceName();
         //Validation
         if (!$instance instanceof ClientInterface) {
             throw new \InvalidArgumentException("Client provider must be an instance of \\Touchbase\\API\\Client\\ClientInterface");
         }
         //Configure
         $instance->configure($config);
         //Save
         StaticStore::shared()->set(self::CLIENT_KEY, $instance);
     }
     return $instance;
 }
Пример #2
0
 /** 
  *	Shared
  *	@return \Touchbase\Utils\SystemDetection
  */
 public static function shared()
 {
     $instance = StaticStore::shared()->get(self::DETECTION_KEY, false);
     if (!$instance || is_null($instance)) {
         $instance = new self();
         $instance->findBrowserInformation();
         StaticStore::shared()->set(self::DETECTION_KEY, $instance);
     }
     return $instance;
 }
Пример #3
0
 /** 
  *	Shared
  *	@return \Touchbase\Security\Permission
  */
 public static function shared()
 {
     $instance = StaticStore::shared()->get(self::PERMISSION_KEY, false);
     if (!$instance || is_null($instance)) {
         $config = StaticStore::shared()->get(ConfigStore::CONFIG_KEY, false);
         //Validation
         if (!$config instanceof ConfigStore) {
             $config = ConfigStore::create();
         }
         $instanceName = $config->get("permission")->get("provider", "\\Touchbase\\Security\\Permission\\Provider\\AccessAllAreasProvider");
         $instance = new $instanceName();
         //Validation
         if (!$instance instanceof PermissionInterface) {
             throw new \InvalidArgumentException("Permission provider must be an instance of \\Touchbase\\Security\\PermissionInterface");
         }
         //Configure
         $instance->configure($config);
         //Save
         StaticStore::shared()->set(self::PERMISSION_KEY, $instance);
     }
     return $instance;
 }
Пример #4
0
 /** 
  *	Shared
  *	@return \Touchbase\Security\Encryption
  */
 public static function shared()
 {
     $instance = StaticStore::shared()->get(self::ENCRYPTION_KEY, false);
     if (!$instance || is_null($instance)) {
         $config = StaticStore::shared()->get(ConfigStore::CONFIG_KEY, false);
         //Validation
         if (!$config instanceof ConfigStore) {
             throw new \RuntimeException("No configuration settings found.");
         }
         $instanceName = $config->get("encryption")->get("provider", "\\Touchbase\\Security\\Encryption\\Provider\\PHPSecLibProvider");
         $instance = new $instanceName();
         //Validation
         if (!$instance instanceof EncryptionInterface) {
             throw new \InvalidArgumentException("Encryption provider must be an instance of \\Touchbase\\Security\\EncryptionInterface");
         }
         //Configure
         $instance->configure($config);
         //Save
         StaticStore::shared()->set(self::ENCRYPTION_KEY, $instance);
     }
     return $instance;
 }
Пример #5
0
 /** 
  *	Shared
  *	@return \Touchbase\Security\Auth
  */
 public static function shared()
 {
     $instance = StaticStore::shared()->get(self::AUTH_KEY, false);
     if (!$instance || is_null($instance)) {
         $config = StaticStore::shared()->get(ConfigStore::CONFIG_KEY, false);
         //Validation
         if (!$config instanceof ConfigStore) {
             $config = ConfigStore::create();
         }
         $instanceName = $config->get("auth")->get("provider", "\\Touchbase\\Security\\Auth\\Provider\\CookieProvider");
         $instance = new $instanceName();
         //Validation
         if (!$instance instanceof AuthInterface) {
             throw new \InvalidArgumentException("Auth provider must be an instance of \\Touchbase\\Security\\AuthInterface");
         }
         //Configure
         $instance->configure($config);
         //Save
         StaticStore::shared()->set(self::AUTH_KEY, $instance);
     }
     return $instance;
 }
Пример #6
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;
 }
Пример #7
0
 /**
  *	Config
  *	@param string $section
  *	@return Touchbase\Core\Config\Store
  */
 public static function config($section = null)
 {
     $config = StaticStore::shared()->get(ConfigStore::CONFIG_KEY, false);
     return $section ? $config->get($section) : $config;
 }
Пример #8
0
 /**
  *	Url For Path
  *	@param string $path
  *	@return string
  */
 public static function urlForPath($path)
 {
     $path = Router::relativeUrl($path);
     $assetMaps = StaticStore::shared()->get(ConfigStore::CONFIG_KEY)->get("assets")->get("asset_map");
     $assetMaps->uasort(function ($a, $b) {
         return strlen($b) - strlen($a);
     });
     foreach ($assetMaps as $assetMap => $searchPath) {
         if (strcasecmp(substr($path, 0, strlen($searchPath)), $searchPath) === 0) {
             $path = Router::buildPath($assetMap, substr($path, strlen($searchPath)));
             break;
         }
     }
     return Router::absoluteUrl($path);
 }