/** * Match a given request. * * @param Request $request Request to match * * @return RouteMatch */ public function match(Request $request) { // Get command line arguments and present working directory from // server superglobal: $filename = $request->getScriptName(); $pwd = CLI_DIR; // Convert base filename (minus .php extension and underscores) and // containing directory name into action and controller, respectively: $baseFilename = str_replace('_', '', basename($filename)); $baseFilename = substr($baseFilename, 0, strlen($baseFilename) - 4); $baseDirname = basename(dirname(realpath($pwd . '/' . $filename))); $routeMatch = new RouteMatch(array('controller' => $baseDirname, 'action' => $baseFilename), 1); // Override standard routing: $routeMatch->setMatchedRouteName('default'); return $routeMatch; }
/** * Legacy handling for scripts: Match a given request. * * @param Request $request Request to match * * @return RouteMatch */ public function match(Request $request) { // Get command line arguments and present working directory from // server superglobal: $filename = $request->getScriptName(); // WARNING: cwd is $VUFIND_HOME, so that throws off realpath! // // Convert base filename (minus .php extension and underscores) and // containing directory name into action and controller, respectively: $base = basename($filename, ".php"); $actionName = str_replace('_', '', $base); // action is the easy part $dir = dirname($filename); if ($dir == false || $dir == '' || $dir == '.' || basename($dir) == '.') { // legacy style: cd to subdir, but set CLI_DIR $dir = $this->getCliDir(); $path = $dir . '/' . $filename; } else { // modern style: invoked as, e.g. $base=util/ping.php, already has path $level1 = basename(dirname($filename)); // but we need to re-orient relative to VUFIND_HOME $path = $level1 . '/' . basename($filename); } $controller = basename($dir); // the last directory part // Special case: if user is accessing index.php directly, we expect // controller and action as first two parameters. if ($controller == 'public' && $actionName == 'index') { list($controller, $actionName) = $this->extractFromCommandLine(); } $routeMatch = new RouteMatch(['controller' => $controller, 'action' => $actionName], 1); // Override standard routing: $routeMatch->setMatchedRouteName('default'); return $routeMatch; }