/** * Get Config * @param string $section * @return \Touchbase\Core\Config\Store */ public function config($section = null) { if ($section) { return $this->_config->get($section); } return $this->_config; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * _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; }
/** * Decrypt * @param string $string * @return string */ public function decrypt($string) { return $this->_encryption->decrypt($string); }