Update CoreLibs with phpstan level 8, add qqFileUploader implementation base, add base Test class for testing

This commit is contained in:
Clemens Schwaighofer
2021-10-26 16:35:26 +09:00
parent 736f822363
commit a6b42f243f
45 changed files with 1198 additions and 593 deletions

View File

@@ -5,16 +5,22 @@ namespace FileUpload\Core;
/**
* Handle file uploads via XMLHttpRequest
*/
class qqUploadedFileXhr
class qqUploadedFileXhr implements qqUploadedFile // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
{
/**
* Save the file to the specified path
*
* @param string $path
* @return boolean TRUE on success
*/
public function save($path)
public function save(string $path): bool
{
$input = fopen("php://input", "r");
$temp = tmpfile();
// abort if not resources
if (!is_resource($input) || !is_resource($temp)) {
return false;
}
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
@@ -23,17 +29,34 @@ class qqUploadedFileXhr
}
$target = fopen($path, "w");
if (!is_resource($target)) {
return false;
}
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
return true;
}
public function getName()
/**
* get qqfile name from _GET array
*
* @return string
*/
public function getName(): string
{
return $_GET['qqfile'];
return $_GET['qqfile'] ?? '';
}
public function getSize()
/**
* Get file size from _SERVERa array, throws an error if not possible
*
* @return int
*
* @throws \Exception
*/
public function getSize(): int
{
if (isset($_SERVER['CONTENT_LENGTH'])) {
return (int)$_SERVER['CONTENT_LENGTH'];