Dispatcher: check actions before tags.

This commit is contained in:
Aaron van Geffen 2016-09-02 11:18:56 +02:00
parent 7487068171
commit c4f65aaa0a

View File

@ -36,23 +36,24 @@ class Dispatcher
$_SERVER['PATH_INFO'] = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')); $_SERVER['PATH_INFO'] = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));
} }
// Nothing in particular? Just show the root of the album list. // Just showing the album index?
if (empty($_SERVER['PATH_INFO']) || $_SERVER['PATH_INFO'] == '/') if (empty($_SERVER['PATH_INFO']) || $_SERVER['PATH_INFO'] == '/')
{ {
return new ViewPhotoAlbum(); return new ViewPhotoAlbum();
} }
// Look for particular actions...
elseif (preg_match('~^/(?<action>[a-z]+)/?~', $_SERVER['PATH_INFO'], $path) && isset($possibleActions[$path['action']]))
{
$_GET = array_merge($_GET, $path);
return new $possibleActions[$path['action']]();
}
// An album, person, or any other tag? // An album, person, or any other tag?
elseif (preg_match('~^/(?<tag>.+?)(?:/page/(?<page>\d+))?/?$~', $_SERVER['PATH_INFO'], $path) && Tag::matchSlug($path['tag'])) elseif (preg_match('~^/(?<tag>.+?)(?:/page/(?<page>\d+))?/?$~', $_SERVER['PATH_INFO'], $path) && Tag::matchSlug($path['tag']))
{ {
$_GET = array_merge($_GET, $path); $_GET = array_merge($_GET, $path);
return new ViewPhotoAlbum(); return new ViewPhotoAlbum();
} }
// Look for an action... // No idea, then?
elseif (preg_match('~^/(?<action>[a-z]+)(?:/page/(?<page>\d+))?/?~', $_SERVER['PATH_INFO'], $path) && isset($possibleActions[$path['action']]))
{
$_GET = array_merge($_GET, $path);
return new $possibleActions[$path['action']]();
}
else else
throw new NotFoundException(); throw new NotFoundException();
} }