leftypol/inc/Service/Media/MediaHandler.php

86 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace Vichan\Service\Media;
use Vichan\Data\MediaInstallResult;
use Vichan\Data\ThumbGenerationResult;
interface MediaHandler {
2025-03-18 11:51:18 +01:00
/**
2025-03-25 11:48:35 +01:00
* PHP file upload. The handler may move or otherwise invalidate this file.
2025-03-18 11:51:18 +01:00
*/
public const FILE_KIND_UPLOADED = 0;
/**
* Temporary file that should be moved/copied elsewhere.
*/
public const FILE_KIND_TEMPORARY = 1;
/**
2025-03-25 11:48:35 +01:00
* Static file from somewhere in the filesystem.
2025-03-18 11:51:18 +01:00
*/
public const FILE_KIND_STATIC = 2;
/**
2025-03-25 11:48:35 +01:00
* Live file currently in use by vichan in some post somewhere.
2025-03-18 11:51:18 +01:00
*/
public const FILE_KIND_INSTALLED = 3;
2025-03-25 11:48:35 +01:00
/**
* 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;
2025-03-25 11:48:35 +01:00
/**
* 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.
*/
2025-03-18 11:51:18 +01:00
public function openHandle(string $file_path, string $file_mime, int $file_kind): mixed;
2025-03-18 11:31:23 +01:00
2025-03-25 11:48:35 +01:00
/**
* 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
): MediaInstallResult;
/**
* Generates a thumbnail from the given file.
*
2025-03-25 11:48:35 +01:00
* @param mixed $handle An opaque handle obtained from {@link openHandle}.
* @param string $preferred_out_file_dir
* @param string $preferred_out_file_name
2025-03-18 00:40:51 +01:00
* @param string $preferred_out_mime
* @param int $max_width
* @param int $max_height
* @return ThumbGenerationResult
2025-03-25 11:48:35 +01:00
* @throws \RuntimeException On error.
*/
2025-03-18 00:40:51 +01:00
public function generateThumb(
mixed $handle,
string $preferred_out_file_dir,
string $preferred_out_file_name,
2025-03-18 00:40:51 +01:00
string $preferred_out_mime,
int $max_width,
int $max_height
): ThumbGenerationResult;
}