add cs fixer and PHPStan and activate it (build 436)

This commit is contained in:
crazywhalecc
2022-03-15 18:05:33 +08:00
parent d01bd69aa5
commit 1706afbcd0
163 changed files with 4572 additions and 3588 deletions

View File

@@ -1,31 +1,31 @@
<?php
declare(strict_types=1);
namespace ZM\Http;
use ZM\Config\ZMConfig;
use ZM\Console\Console;
use ZM\Utils\HttpUtil;
class StaticFileHandler
{
public function __construct($filename, $path) {
$full_path = realpath($path . "/" . $filename);
public function __construct($filename, $path)
{
$full_path = realpath($path . '/' . $filename);
$response = ctx()->getResponse();
Console::debug("Full path: " . $full_path);
Console::debug('Full path: ' . $full_path);
if ($full_path !== false) {
if (strpos($full_path, $path) !== 0) {
$response->status(403);
$response->end("403 Forbidden");
$response->end('403 Forbidden');
return true;
}
if (is_file($full_path)) {
$exp = strtolower(pathinfo($full_path)['extension'] ?? 'unknown');
$response->setHeader('Content-Type', ZMConfig::get('file_header')[$exp] ?? 'application/octet-stream');
$response->end(file_get_contents($full_path));
return true;
} else {
if (is_file($full_path)) {
$exp = strtolower(pathinfo($full_path)['extension'] ?? "unknown");
$response->setHeader("Content-Type", ZMConfig::get("file_header")[$exp] ?? "application/octet-stream");
$response->end(file_get_contents($full_path));
return true;
}
}
}
$response->status(404);