Make PHPStan happy.
This commit is contained in:
parent
8b0f960c86
commit
737c99280e
3 changed files with 59 additions and 37 deletions
|
@ -36,6 +36,44 @@ class InfoRoutes extends RouteHandler {
|
|||
);
|
||||
}
|
||||
|
||||
private static function findDocPath(string $projectPath, string $name): string {
|
||||
// User provided case, without extension
|
||||
$attempt = sprintf('%s/%s', $projectPath, $name);
|
||||
if(is_file($attempt))
|
||||
return $attempt;
|
||||
|
||||
// User provided case, with extension
|
||||
$attempt = sprintf('%s/%s.md', $projectPath, $name);
|
||||
if(is_file($attempt))
|
||||
return $attempt;
|
||||
|
||||
$name = strtoupper($name);
|
||||
|
||||
// Uppercase, without extension
|
||||
$attempt = sprintf('%s/%s', $projectPath, $name);
|
||||
if(is_file($attempt))
|
||||
return $attempt;
|
||||
|
||||
// Uppercase, with extension
|
||||
$attempt = sprintf('%s/%s.md', $projectPath, $name);
|
||||
if(is_file($attempt))
|
||||
return $attempt;
|
||||
|
||||
$name = strtolower($name);
|
||||
|
||||
// Lowercase, without extension
|
||||
$attempt = sprintf('%s/%s', $projectPath, $name);
|
||||
if(is_file($attempt))
|
||||
return $attempt;
|
||||
|
||||
// Lowercase, with extension
|
||||
$attempt = sprintf('%s/%s.md', $projectPath, $name);
|
||||
if(is_file($attempt))
|
||||
return $attempt;
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
#[Route('GET', '/info/:project/:name')]
|
||||
public function getProjectPage($response, $request, string $project, string $name) {
|
||||
if(!array_key_exists($project, self::PROJECT_PATHS))
|
||||
|
@ -46,37 +84,19 @@ class InfoRoutes extends RouteHandler {
|
|||
$projectPath = self::PROJECT_PATHS[$project];
|
||||
$titleSuffix = array_key_exists($project, self::PROJECT_SUFFIXES) ? self::PROJECT_SUFFIXES[$project] : '';
|
||||
|
||||
$attempts = 0;
|
||||
$licenceHack = false;
|
||||
for(;;) {
|
||||
$path = match(++$attempts) {
|
||||
1 => sprintf('%s/%s', $projectPath, $name),
|
||||
2 => sprintf('%s/%s.md', $projectPath, $name),
|
||||
3 => sprintf('%s/%s', $projectPath, strtoupper($name)),
|
||||
4 => sprintf('%s/%s.md', $projectPath, strtoupper($name)),
|
||||
5 => sprintf('%s/%s', $projectPath, strtolower($name)),
|
||||
6 => sprintf('%s/%s.md', $projectPath, strtolower($name)),
|
||||
default => '',
|
||||
};
|
||||
|
||||
$path = self::findDocPath($projectPath, $name);
|
||||
if($path === '') {
|
||||
if(!$licenceHack) {
|
||||
$isBritish = strtolower($name) === 'licence';
|
||||
$isAmerican = strtolower($name) === 'license';
|
||||
$isBritishLicense = strtolower($name) === 'licence';
|
||||
$isAmericanLicence = strtolower($name) === 'license';
|
||||
|
||||
if($isBritish || $isAmerican) {
|
||||
$attempts = 0;
|
||||
$licenceHack = true;
|
||||
$name = $isAmerican ? 'licence' : 'license';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if($isBritishLicense || $isAmericanLicence) {
|
||||
$name = $isAmericanLicence ? 'licence' : 'license';
|
||||
$path = self::findDocPath($projectPath, $name);
|
||||
|
||||
if($path === '')
|
||||
return 404;
|
||||
} else
|
||||
return 404;
|
||||
}
|
||||
|
||||
if(is_file($path))
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->serveMarkdownDocument($path, $titleSuffix);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
use Index\Environment;
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigrationRepo;
|
||||
use Index\Data\Migration\DbMigrationManager;
|
||||
|
@ -202,21 +203,21 @@ class MisuzuContext {
|
|||
['eeprom.app:s', '', 'eeprom_app'],
|
||||
]);
|
||||
|
||||
$isDebug = Environment::isDebug();
|
||||
$globals['assets'] = $this->getWebAssetInfo();
|
||||
$globals['auth_info'] = $this->authInfo;
|
||||
$globals['active_ban_info'] = $this->usersCtx->tryGetActiveBan($this->authInfo->getUserInfo());
|
||||
$globals['display_timings_info'] = MSZ_DEBUG
|
||||
|| $this->authInfo->getPerms('global')->check(Perm::G_TIMINGS_VIEW);
|
||||
$globals['display_timings_info'] = $isDebug || $this->authInfo->getPerms('global')->check(Perm::G_TIMINGS_VIEW);
|
||||
|
||||
$templating = new SasaeEnvironment(
|
||||
$this->templating = new SasaeEnvironment(
|
||||
MSZ_TEMPLATES,
|
||||
cache: MSZ_DEBUG ? null : ['Misuzu', GitInfo::hash(true)],
|
||||
debug: MSZ_DEBUG
|
||||
cache: $isDebug ? null : ['Misuzu', GitInfo::hash(true)],
|
||||
debug: $isDebug
|
||||
);
|
||||
$templating->addExtension(new MisuzuSasaeExtension($this));
|
||||
$templating->addGlobal('globals', $globals);
|
||||
$this->templating->addExtension(new MisuzuSasaeExtension($this));
|
||||
$this->templating->addGlobal('globals', $globals);
|
||||
|
||||
Template::init($templating);
|
||||
Template::init($this->templating);
|
||||
}
|
||||
|
||||
public function startRouter(): void {
|
||||
|
|
|
@ -5,6 +5,7 @@ use stdClass;
|
|||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Index\DateTime;
|
||||
use Index\Environment;
|
||||
use Index\Data\DbStatementCache;
|
||||
use Index\Data\DbTools;
|
||||
use Index\Data\IDbConnection;
|
||||
|
@ -370,7 +371,7 @@ class Permissions {
|
|||
}
|
||||
|
||||
private static function precalculatePermissionsLog(string $fmt, ...$args): void {
|
||||
if(!MSZ_CLI)
|
||||
if(!Environment::isConsole())
|
||||
return;
|
||||
|
||||
echo DateTime::now()->format('[H:i:s.u] ');
|
||||
|
|
Loading…
Reference in a new issue