Skip to content
Snippets Groups Projects
Commit 4c5377c2 authored by Stein Magne Bjorklund's avatar Stein Magne Bjorklund
Browse files

Improve inline comments and do strict checks

We should not trust language " auto magic". Let us
be sure we do a strict type check.
parent 37b0fea2
No related branches found
No related tags found
1 merge request!16Resolve "Introduce PSR-4 autoloading"
<?php <?php declare(strict_types=1);
use uib\ub\loadspeakr\Endpoint; use uib\ub\loadspeakr\Endpoint;
use uib\ub\loadspeakr\Exporter; use uib\ub\loadspeakr\Exporter;
...@@ -9,27 +9,23 @@ use uib\ub\loadspeakr\Utils; ...@@ -9,27 +9,23 @@ use uib\ub\loadspeakr\Utils;
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
//Import if (isset($_GET['q']) && $_GET['q'] === 'import') {
if (isset($_GET['q']) && $_GET['q'] == 'import') {
include_once('classes/Importer.php');
$imp = new Importer(); $imp = new Importer();
$imp->run(); $imp->run();
exit(0); exit(0);
} }
//Test if LODSPeaKr is configured // Check that application is installed.
if (!file_exists('settings.inc.php')) { if (!file_exists('settings.inc.php')) {
echo 'Need to configure lodspeakr first. Please run "install.sh". Alternatively, you can <a href="import">import an existing application</a>'; echo 'Need to configure lodspeakr first. Please run "install.sh". Alternatively, you can <a href="import">import an existing application</a>';
exit(0); exit(0);
} }
include_once('common.inc.php'); include_once('common.inc.php');
//Debug output
$conf['logfile'] = null; $conf['logfile'] = null;
if ($conf['debug']) { if ($conf['debug']) {
include_once('classes/Logging.php'); if (isset($_GET['q']) && $_GET['q'] === 'logs') {
if (isset($_GET['q']) && $_GET['q'] == 'logs') {
Logging::init(); Logging::init();
exit(0); exit(0);
} else { } else {
...@@ -54,13 +50,12 @@ $acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT'], $conf['h ...@@ -54,13 +50,12 @@ $acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT'], $conf['h
$extension = Utils::getExtension($acceptContentType, $conf['http_accept']); $extension = Utils::getExtension($acceptContentType, $conf['http_accept']);
//Check content type is supported by LODSPeaKr // Check that content type is supported by LODSPeaKr.
if ($acceptContentType == null) { if ($acceptContentType === null) {
HTTPStatus::send406($uri); HTTPStatus::send406($uri);
} }
//Export if ($conf['export'] && $_GET['q'] === 'export') {
if ($conf['export'] && $_GET['q'] == 'export') {
include_once('settings.inc.php'); include_once('settings.inc.php');
include_once('classes/Exporter.php'); include_once('classes/Exporter.php');
$exp = new Exporter(); $exp = new Exporter();
...@@ -69,22 +64,21 @@ if ($conf['export'] && $_GET['q'] == 'export') { ...@@ -69,22 +64,21 @@ if ($conf['export'] && $_GET['q'] == 'export') {
exit(0); exit(0);
} }
//Redirect to root URL if necessary // Redirect to root URL if necessary.
$uri = $conf['basedir'] . $_GET['q']; $uri = $conf['basedir'] . $_GET['q'];
$localUri = $uri; $localUri = $uri;
if ($uri == $conf['basedir']) { if ($uri === $conf['basedir']) {
header('Location: ' . $conf['root']); header('Location: ' . $conf['root']);
exit(0); exit(0);
} }
//Configure external URIs if necessary // Configure external URIs if necessary.
$localUri = $conf['basedir'] . $_GET['q']; $localUri = $conf['basedir'] . $_GET['q'];
$uri = Utils::getMirroredUri($localUri); $uri = Utils::getMirroredUri($localUri);
// Load Loadspeakr modules.
//Load Loadspeakr modules.
foreach ($conf['modules']['available'] as $i) { foreach ($conf['modules']['available'] as $i) {
$className = $i . 'Module'; $className = $i . 'Module';
$currentModule = $conf['modules']['directory'] . $className . '.php'; $currentModule = $conf['modules']['directory'] . $className . '.php';
...@@ -99,10 +93,10 @@ foreach ($conf['modules']['available'] as $i) { ...@@ -99,10 +93,10 @@ foreach ($conf['modules']['available'] as $i) {
$module = new $namespacedClassName(); $module = new $namespacedClassName();
$matching = $module->match($uri); $matching = $module->match($uri);
if ($matching != false) { if ($matching !== false) {
$module->execute($matching); $module->execute($matching);
if ($conf['logfile'] != null) { if ($conf['logfile'] !== null) {
fwrite($conf['logfile'], "]}"); fwrite($conf['logfile'], "]}");
fclose($conf['logfile']); fclose($conf['logfile']);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment