public function loadConfig() { $cfg = PathResolver::getInstance()->getPath("{APP}/config/application.sdl"); if (file_exists($cfg)) { $this->debug("WebApplication: Reading %s", $cfg); $config = new SdlTag("root"); $config->loadString(file_get_contents($cfg)); $this->config = $config; } else { $this->debug("WebApplication: Could not find %s", $cfg); } }
public function route($uri) { $fspath = PathResolver::getInstance()->getPath("{PUBLIC}" . $uri); if (_IS_CLI_SERVER && is_file($fspath)) { $r = new \Cherry\Web\Response(); return $r->sendFile($fspath); } // Loop through every route and compare it with the URI foreach ($this->routes as $route) { // Create a route with all identifiers replaced with ([^/]+) regex syntax // E.g. $route_regex = shop-please/([^/]+)/moo (originally shop-please/:some_identifier/moo) $route_regex = preg_replace('@:[^/]+@', '([^/]+)', $route[0]); // Check if URI path matches regex pattern, if so create an array of values from the URI if (!preg_match('@^' . $route_regex . '$@', $uri, $matches)) { continue; } // Create an array of identifiers from the route preg_match('@^' . $route_regex . '$@', $route[0], $identifiers); // Decode the matches $matches = array_map(function ($str) { return urldecode($str); }, $matches); $identifiers = array_map(function ($str) { return substr($str, 1); }, $identifiers); // Combine the identifiers with the values $params = array_combine($identifiers, $matches); array_shift($params); $action = $route->action; $this->dispatch($action, $params); return 200; } return 404; }
function run() { $ks = KeyStore::getInstance(); $pr = PathResolver::getInstance(); $ks_user = $pr->getPath("{USER}/user.cks"); $ks_system = $pr->getPath("{SYSTEM}/system.cks"); if (file_exists($ks_user)) { $key = getenv("KEYSTORE_USERKEY"); if ($key) { $ks->attachFile($ks_user, $key); putenv("KEYSTORE_USERKEY"); } else { $this->debug("Info: To auto-mount the user KeyStore, define the KEYSTORE_USERKEY envvar."); } } else { $this->debug("Keystore {$ks_user} not found."); } if (file_exists($ks_system)) { $key = getenv("KEYSTORE_SYSTEMKEY"); if ($key) { $ks->attachFile($ks_system, $key); putenv("KEYSTORE_SYSTEMKEY"); } else { $this->debug("Info: To auto-mount the system KeyStore, define the KEYSTORE_SYSTEMKEY envvar."); } } else { $this->debug("Keystore {$ks_system} not found."); } return $this->main(); }