mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
79 lines
No EOL
1.7 KiB
PHP
79 lines
No EOL
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Description of Controller
|
|
*
|
|
* @author jeremy
|
|
*/
|
|
class Controller
|
|
{
|
|
public static function dispatch($uri)
|
|
{
|
|
try
|
|
{
|
|
list($viewTemplate, $viewParameters) = static::execute($uri);
|
|
|
|
if ($viewTemplate === null)
|
|
{
|
|
return '';
|
|
}
|
|
|
|
if (!$viewTemplate)
|
|
{
|
|
throw new LogicException('All execute methods must return a template.');
|
|
}
|
|
|
|
echo View::render('layout/basic', [
|
|
'content' => View::render($viewTemplate, $viewParameters + ['fullPage' => true])
|
|
]);
|
|
}
|
|
catch (StopException $e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public static function execute($uri)
|
|
{
|
|
switch($uri)
|
|
{
|
|
case '/':
|
|
return ContentActions::executeHome();
|
|
case '/postcommit':
|
|
return OpsActions::executePostCommit();
|
|
case '/list-subscribe':
|
|
return MailActions::executeListSubscribe();
|
|
default:
|
|
$noSlashUri = ltrim($uri, '/');
|
|
if (View::exists('page/' . $noSlashUri))
|
|
{
|
|
return ['page/' . $noSlashUri, []];
|
|
}
|
|
else
|
|
{
|
|
return ['page/404', []];
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function redirect($url, $statusCode = 302)
|
|
{
|
|
if (empty($url))
|
|
{
|
|
throw new InvalidArgumentException('Cannot redirect to an empty URL.');
|
|
}
|
|
|
|
$url = str_replace('&', '&', $url);
|
|
|
|
if ($statusCode == 201 || ($statusCode >= 300 && $statusCode < 400))
|
|
{
|
|
header('Location: ' . $url, true, $statusCode);
|
|
}
|
|
else
|
|
{
|
|
echo sprintf('<html><head><meta http-equiv="refresh" content="0;url=%s"/></head></html>', htmlspecialchars($url, ENT_QUOTES));
|
|
}
|
|
|
|
throw new StopException('Time to redirect');
|
|
}
|
|
} |