/** * 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; }
/** * __construct * @param object $autoLoader - Autoloader instance * @param string $basePath */ public function __construct($autoLoader = null, $basePath = null) { $this->_autoLoader = $autoLoader; //Base Working Directory if (!defined('BASE_PATH')) { if (is_null($basePath)) { define('BASE_PATH', rtrim(realpath(dirname($_SERVER['DOCUMENT_ROOT'])), DIRECTORY_SEPARATOR)); } else { define('BASE_PATH', rtrim($basePath, DIRECTORY_SEPARATOR)); } } //Error Logging $error = new \Touchbase\Debug\Error(); //Configure Touchbase Project $this->setConfig($this->_configure(ConfigStore::create())); if (!defined('TOUCHBASE_ENV')) { define("TOUCHBASE_ENV", $this->config()->get("project")->get("environment", "production"), true); } //Work out touchbase path if ($this->_autoLoader instanceof \Composer\Autoload\ClassLoader) { $prefixes = $this->_autoLoader->getPrefixesPsr4(); foreach ($prefixes as $prefix => $path) { if (rtrim($prefix, "\\") == __NAMESPACE__) { $nsBasePath = realpath($path[0]) . DIRECTORY_SEPARATOR; break; } } } if (!defined('TOUCHBASE_PATH')) { define('TOUCHBASE_PATH', rtrim(realpath($nsBasePath), DIRECTORY_SEPARATOR)); } //Base Working Directory if (!defined('WORKING_DIR')) { // Determine the base URL by comparing SCRIPT_NAME to SCRIPT_FILENAME and getting common elements $path = realpath($_SERVER['SCRIPT_FILENAME']); if (substr($path, 0, strlen(BASE_PATH)) == BASE_PATH) { $urlSegmentToRemove = substr($path, strlen(BASE_PATH)); if (substr($_SERVER['SCRIPT_NAME'], -strlen($urlSegmentToRemove)) == $urlSegmentToRemove) { $baseURL = substr($_SERVER['SCRIPT_NAME'], 0, -strlen($urlSegmentToRemove)); } } define('WORKING_DIR', strtolower(rtrim(isset($baseURL) ? $baseURL : $this->config()->get("project")->get("working_dir", ""), "/")) . "/"); } if (!Router::isCLI()) { if (!defined('SITE_PROTOCOL')) { $protocol = ''; if (isset($_SERVER['HTTP_X_FORWARDED_PROTOCOL']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTOCOL']) == 'https') { $protocol = 'https://'; } else { if (isset($_SERVER['SSL']) || !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { $protocol = 'https://'; } else { $protocol = 'http://'; } } define('SITE_PROTOCOL', $protocol); } if (!defined('SITE_URL')) { define("SITE_URL", Router::buildPath(SITE_PROTOCOL . htmlentities(filter_var(strtolower(@$_SERVER['HTTP_X_FORWARDED_HOST'] ?: $_SERVER['HTTP_HOST']), FILTER_SANITIZE_URL), ENT_QUOTES, 'UTF-8'), WORKING_DIR), true); define("SITE_ROOT", SITE_URL, true); } } // \pre_r(BASE_PATH); // \pre_r(TOUCHBASE_PATH); // \pre_r(PROJECT_PATH); // \pre_r(SITE_URL); // \pre_r(TOUCHBASE_ENV); }