Skip to content

Commit

Permalink
Added missing file, make extension based implementation also use the …
Browse files Browse the repository at this point in the history
…reverse lookup.
  • Loading branch information
frankdejonge committed Aug 5, 2023
1 parent 32796d9 commit 86216ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/ExtensionLookup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);

namespace League\MimeTypeDetection;

interface ExtensionLookup
{
public function lookupExtension(string $mimetype): ?string;

/**
* @return string[]
*/
public function lookupAllExtensions(string $mimetype): array;
}
16 changes: 15 additions & 1 deletion src/ExtensionMimeTypeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use const PATHINFO_EXTENSION;

class ExtensionMimeTypeDetector implements MimeTypeDetector
class ExtensionMimeTypeDetector implements MimeTypeDetector, ExtensionLookup
{
/**
* @var ExtensionToMimeTypeMap
Expand Down Expand Up @@ -39,4 +39,18 @@ public function detectMimeTypeFromBuffer(string $contents): ?string
{
return null;
}

public function lookupExtension(string $mimetype): ?string
{
return $this->extensions instanceof ExtensionLookup
? $this->extensions->lookupExtension($mimetype)
: null;
}

public function lookupAllExtensions(string $mimetype): array
{
return $this->extensions instanceof ExtensionLookup
? $this->extensions->lookupAllExtensions($mimetype)
: [];
}
}

0 comments on commit 86216ae

Please sign in to comment.