Skip to content

Commit

Permalink
[Core] Use New Router (#3584)
Browse files Browse the repository at this point in the history
This updates LORIS to use the PSR15 RequestHandler/Middleware based router that was implemented in PRs #3477, #3480, and #3513.

Most of the mod_rewrite rules, main.php, and NDB_Caller are replaced by a new index.php, which generates a PSR7 ServerRequestInterface and delegates to the module's Module handler.

AjaxHelper.php remains, but is deprecated, as existing scripts will need to be updated to be proper endpoints in the module's router. (Once this is done, the separate router.php for PHP's built in web server can also be removed, and mod_rewrite dependency for LORIS can be removed.)

main.php and NDB_Caller also remain for now in order to load instruments. Once an instrument module is implemented to handle the instruments routers, they can be removed.

Note that instrument URLs also change from $LORIS/instrumentname to $LORIS/instruments/instrumentname as part of this change.
  • Loading branch information
driusan authored May 9, 2018
1 parent 95b821a commit 8d1f30f
Show file tree
Hide file tree
Showing 52 changed files with 660 additions and 784 deletions.
2 changes: 1 addition & 1 deletion docs/config/apache2-site
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

php_value include_path .:/usr/share/php:%LORISROOT%/project/libraries:%LORISROOT%/php/libraries

DirectoryIndex main.php index.html
#DirectoryIndex main.php index.html

ErrorLog %LOGDIRECTORY%/loris-error.log

Expand Down
42 changes: 11 additions & 31 deletions htdocs/.htaccess
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^([a-zA-Z_-]+)/api/([a-zA-Z0-9_.-/]+)$ module-api.php
# FIXME: The /module/$name/ajax directory needs to be replaced with real NDB_Pages that
# remove the page decoration middlewares, but for now we need to keep this helper script.
RewriteRule ^([a-zA-Z_-]+)/ajax/([a-zA-Z0-9_.-]+)$ AjaxHelper.php?Module=$1&script=$2 [QSA,L]

# Bootstrap is not a Loris module, don't rewrite it.
RewriteRule ^bootstrap/(.*) bootstrap/$1 [L]
# Excel Dumps aren't a Loris module, don't rewrite it.
RewriteRule ^dataDumps/(.*) dataDumps/$1 [L]
# Instruments and reliability still use main.php, for now
RewriteRule ^instruments/([a-zA-Z0-9_-]+)/$ main.php?test_name=$1 [QSA,L]
RewriteRule ^instruments/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.-]+)/$ main.php?test_name=$1&subtest=$2 [QSA,L]

# Redirect /CandID/ to visit label list
RewriteRule ^([0-9]{6,6})/$ main.php?test_name=timepoint_list&candID=$1
# Want to redirect /CandID/Visit_label/ to instrument list, but
# because of the main.php URL structure it needs to be the sessionID instead
# of Visit_label
RewriteRule ^([0-9]{6,6})/([0-9]+)/$ main.php?test_name=instrument_list&candID=$1&sessionID=$2

# Redirect /CandID/Visit/Instrument/(subtest/) to the instrument
RewriteRule ^([0-9]{6,6})/([0-9]+)/([a-zA-Z0-9_]+)/$ main.php?test_name=$3&candID=$1&sessionID=$2 [QSA]
RewriteRule ^([0-9]{6,6})/([0-9]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ main.php?test_name=$3&candID=$1&sessionID=$2&subtest=$4 [QSA]

# Rewrite /foo/ to appropriate module
# Includes /foo/css/cssfile.css
# /foo/js/javascriptfile.js
# /foo/ajax/AjaxScript.php
# To use the appropriate helper script as well.
RewriteRule ^([a-zA-Z0-9_-]+)/$ main.php?test_name=$1 [QSA]
RewriteRule ^([a-zA-Z_-]+)/css/([a-zA-Z0-9_.-]+)$ GetCSS.php?Module=$1&file=$2
RewriteRule ^([a-zA-Z_-]+)/js/([a-zA-Z0-9_.-]+)$ GetJS.php?Module=$1&file=$2
RewriteRule ^([a-zA-Z_-]+)/static/([a-zA-Z0-9_.-/]+)$ GetStatic.php?Module=$1&file=$2
RewriteRule ^([a-zA-Z_-]+)/ajax/([a-zA-Z0-9_.-]+)$ AjaxHelper.php?Module=$1&script=$2 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.-]+)/$ main.php?test_name=$1&subtest=$2 [QSA]

# Add trailing slash to all directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=307]
RewriteRule ^([a-zA-Z0-9_-]+)reliability([a-zA-Z0-9_-]*) main.php?test_name=$1reliability$2 [QSA,L]

# Everything else gets rewritten to be handled by index.php, unless it's a file that's served
# directly from apache
RewriteCond "%{REQUEST_FILENAME}" "!-f"
RewriteRule ^(.*)$ index.php?lorispath=$1 [QSA,L]
</IfModule>

140 changes: 0 additions & 140 deletions htdocs/GetCSS.php

This file was deleted.

145 changes: 0 additions & 145 deletions htdocs/GetJS.php

This file was deleted.

Loading

0 comments on commit 8d1f30f

Please sign in to comment.