Skip to content

Commit c75ac16

Browse files
committed
Add isType method to File DTO
Introduces the isType(string $type): bool method to the File DTO, allowing checks for specific MIME types. Also improves comments and formatting around data URI handling.
1 parent 9241e03 commit c75ac16

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Files/DTO/File.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ private function detectAndProcessFile(string $file, ?string $providedMimeType):
8787
return;
8888
}
8989

90-
// Check if it's a data URI
90+
// Data URI pattern.
9191
$dataUriPattern = '/^data:(?:([a-zA-Z0-9][a-zA-Z0-9!#$&\-\^_+.]*\/[a-zA-Z0-9][a-zA-Z0-9!#$&\-\^_+.]*'
92-
. '(?:;[a-zA-Z0-9\-]+=[a-zA-Z0-9\-]+)*)?;)?base64,([A-Za-z0-9+\/]*={0,2})$/';
92+
. '(?:;[a-zA-Z0-9\-]+=[a-zA-Z0-9\-]+)*)?;)?base64,([A-Za-z0-9+\/]*={0,2})$/';
9393

94+
// Check if it's a data URI.
9495
if (preg_match($dataUriPattern, $file, $matches)) {
9596
$this->fileType = FileTypeEnum::inline();
9697
$this->base64Data = $matches[2]; // Extract just the base64 data
@@ -285,6 +286,20 @@ public function isText(): bool
285286
return $this->mimeType->isText();
286287
}
287288

289+
/**
290+
* Checks if the file is a specific MIME type.
291+
*
292+
* @since n.e.x.t
293+
*
294+
* @param string $type The type to check.
295+
*
296+
* @return bool True if the file is of the specified type.
297+
*/
298+
public function isType(string $type): bool
299+
{
300+
return $this->mimeType->isType($type);
301+
}
302+
288303
/**
289304
* Determines the MIME type from various sources.
290305
*

0 commit comments

Comments
 (0)