leftypol/inc/Service/Media/MediaHandler.php

84 lines
2.4 KiB
PHP

<?php
namespace Vichan\Service\Media;
use Vichan\Data\ThumbGenerationResult;
interface MediaHandler {
/**
* PHP file upload. The handler may move or otherwise invalidate this file.
*/
public const FILE_KIND_UPLOADED = 0;
/**
* Temporary file that should be moved/copied elsewhere.
*/
public const FILE_KIND_TEMPORARY = 1;
/**
* Static file from somewhere in the filesystem.
*/
public const FILE_KIND_STATIC = 2;
/**
* Live file currently in use by vichan in some post somewhere.
*/
public const FILE_KIND_INSTALLED = 3;
/**
* Check if this handler implementation supports the files of the given mime type.
*
* @param string $mime Mime type string.
* @return bool Returns true if the handler supports the file type.
*/
public function supportsMime(string $mime): bool;
/**
* Opens a SINGLE USE handle over a file. After using the handle with any method of this class, the handle MUST be
* closed with {@link closeHandle}
*
* @param string $file_path Path to the file.
* @param string $file_mime The mime type of the file. MUST be of a value for which {@link supportsMime} returns true.
* @param int $file_kind One of the FILE_KIND_* constants.
* @return mixed An opaque handle.
* @throws \RuntimeException On error.
*/
public function openHandle(string $file_path, string $file_mime, int $file_kind): mixed;
/**
* Closes the handle.
* @param mixed $handle Handle to close, MUST NOT have already been closed.
* @return void
*/
public function closeHandle(mixed $handle);
public function installMediaAndGenerateThumb(
mixed $handle,
string $media_preferred_out_file_dir,
string $media_preferred_out_file_name,
string $thumb_preferred_out_file_dir,
string $thumb_preferred_out_file_name,
string $thumb_preferred_out_mime,
int $thumb_max_width,
int $thumb_max_height
);
/**
* Generates a thumbnail from the given file.
*
* @param mixed $handle An opaque handle obtained from {@link openHandle}.
* @param string $preferred_out_file_dir
* @param string $preferred_out_file_name
* @param string $preferred_out_mime
* @param int $max_width
* @param int $max_height
* @return ThumbGenerationResult
* @throws \RuntimeException On error.
*/
public function generateThumb(
mixed $handle,
string $preferred_out_file_dir,
string $preferred_out_file_name,
string $preferred_out_mime,
int $max_width,
int $max_height
): ThumbGenerationResult;
}