Skip to content

Commit ae46190

Browse files
authored
Merge pull request #61632 from nextcloud/jtr/docs-IPreview-and-IProviderV2
docs(preview): improve IPreview and IProviderV2 interface docs
2 parents c03dbb5 + 64860ee commit ae46190

2 files changed

Lines changed: 41 additions & 15 deletions

File tree

lib/public/IPreview.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,39 @@
1717
use OCP\Preview\IProviderV2;
1818

1919
/**
20-
* This class provides functions to render and show thumbnails and previews of files
20+
* Public interface for discovering preview providers and generating file previews.
21+
*
22+
* ProviderClosure lazily resolves a preview provider and may return false if it
23+
* cannot be loaded.
24+
*
2125
* @since 6.0.0
2226
* @psalm-type ProviderClosure = Closure():(IProviderV2|false)
2327
*/
2428
#[Consumable(since: '6.0.0')]
2529
interface IPreview {
2630
/**
31+
* Preview scaling mode that fills the requested dimensions.
32+
*
2733
* @since 11.0.0
2834
*/
2935
public const MODE_FILL = 'fill';
3036

3137
/**
38+
* Preview scaling mode that covers the requested dimensions.
39+
*
3240
* @since 11.0.0
3341
*/
3442
public const MODE_COVER = 'cover';
3543

3644
/**
37-
* Get all providers
38-
* @return array<string, list<ProviderClosure>>
45+
* Returns the registered preview providers grouped by supported mime-type regex.
46+
*
47+
* Each value is a list of closures that create preview providers when invoked,
48+
* not a list of already instantiated provider objects.
49+
*
50+
* The provider list is built on demand and is empty when previews are disabled.
51+
*
52+
* @return array<string, list<ProviderClosure>> Map of mime-type regex to provider-creating closures
3953
* @since 8.1.0
4054
*/
4155
public function getProviders(): array;
@@ -64,17 +78,25 @@ public function hasProviders(): bool;
6478
public function getPreview(File $file, int $width = -1, int $height = -1, bool $crop = false, string $mode = IPreview::MODE_FILL, ?string $mimeType = null, bool $cacheResult = true): ISimpleFile;
6579

6680
/**
67-
* Returns true if the passed mime type is supported
68-
* @param string $mimeType A glob
81+
* Returns whether any registered preview provider supports the given mime type.
82+
*
83+
* This checks the mime type against the providers' registered mime-type regexes.
84+
* It does not guarantee that preview generation will succeed for a specific file.
85+
*
86+
* @param string $mimeType Mime type string to test, for example "image/png"
6987
* @since 6.0.0
7088
*/
7189
public function isMimeSupported(string $mimeType = '*'): bool;
7290

7391
/**
74-
* Check if a preview can be generated for a file
92+
* Returns whether a preview can currently be generated for the given file.
93+
*
94+
* This checks whether the effective mime type is supported, whether previews
95+
* are allowed on the file's mount, and whether at least one matching provider is
96+
* available for the file in the current environment.
7597
*
7698
* @param FileInfo $file
77-
* @param string|null $mimeType To force a given mimetype for the file
99+
* @param string|null $mimeType Optional mime type override to use instead of $file->getMimeType()
78100
* @since 8.0.0
79101
* @since 32.0.0 - isAvailable($mimeType) added the $mimeType argument to the signature
80102
*/

lib/public/Preview/IProviderV2.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,35 @@
1313
use OCP\IImage;
1414

1515
/**
16+
* Public interface for preview providers.
17+
*
18+
* A preview provider generates a thumbnail image for supported files. That image
19+
* may be stored and reused by the preview system.
20+
*
1621
* @since 17.0.0
1722
*/
1823
interface IProviderV2 {
1924
/**
20-
* @return string Regex with the mimetypes that are supported by this provider
25+
* Returns a regex matching the MIME types supported by this provider.
26+
*
2127
* @since 17.0.0
2228
*/
2329
public function getMimeType(): string;
2430

2531
/**
26-
* Check if a preview can be generated for $path
32+
* Returns whether this provider can currently generate a thumbnail for the given file.
2733
*
28-
* @param FileInfo $file
29-
* @return bool
3034
* @since 17.0.0
3135
*/
3236
public function isAvailable(FileInfo $file): bool;
3337

3438
/**
35-
* get thumbnail for file at path $path
39+
* Generates a thumbnail image for the given file.
3640
*
3741
* @param File $file
38-
* @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
39-
* @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
40-
* @return null|\OCP\IImage null if no preview was generated
42+
* @param int $maxX Maximum thumbnail width; the returned image may be smaller depending on its aspect ratio
43+
* @param int $maxY Maximum thumbnail height; the returned image may be smaller depending on its aspect ratio
44+
* @return IImage|null Null if no thumbnail could be generated
4145
* @since 17.0.0
4246
*/
4347
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage;

0 commit comments

Comments
 (0)