szurubooru/src/Api/ApiFileOutput.php

31 lines
664 B
PHP
Raw Normal View History

<?php
/**
* Used for serializing files output from jobs
*/
2014-05-17 10:10:38 +02:00
class ApiFileOutput implements ISerializable
{
public $fileContent;
public $fileName;
2014-05-13 14:00:25 +02:00
public $lastModified;
public $mimeType;
public function __construct($filePath, $fileName)
{
$this->fileContent = file_get_contents($filePath);
$this->fileName = $fileName;
$this->lastModified = filemtime($filePath);
$this->mimeType = mime_content_type($filePath);
}
2014-05-17 10:10:38 +02:00
public function serializeToArray()
{
return
[
'name ' => $this->fileName,
'modification-time' => $this->lastModified,
'mime-type' => $this->mimeType,
'content' => base64_encode(gzencode($this->fileContent)),
];
}
}