Skip to content

Commit 6e7c1f7

Browse files
authored
Merge pull request #2 from adrienrn/develop
0.2.0
2 parents 4c3334d + 2658dc6 commit 6e7c1f7

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "php-mimetyper",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "PHP mime type and extension mapping library: compatible with Symfony, powered by jshttp/mime-db",
55
"main": "index.js",
66
"scripts": {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace MimeTyper\Symfony;
4+
5+
if (class_exists("Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface")) {
6+
class_alias(
7+
"Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface",
8+
"Mimetyper\Symfony\MimeTypeGuesserInterface"
9+
);
10+
} else {
11+
/*
12+
* Some project with PHP 5.3+ compatibility forced the fork of symfony/http-foundation.
13+
* Look away, don't judge, bisous.
14+
*/
15+
class_alias(
16+
"Madhouse\HttpFoundation\File\MimeType\MimeTypeGuesserInterface",
17+
"Mimetyper\Symfony\MimeTypeGuesserInterface"
18+
);
19+
}
20+
21+
/**
22+
* Guesses the mime type using the deprecated – but yet useful sometimes,
23+
* mime_content_type.
24+
*
25+
* @author Hussard <adrien.ricartnoblet@gmail.com>
26+
* @since 0.2.0
27+
*/
28+
class MimeContentMimeTypeGuesser implements MimeTypeGuesserInterface
29+
{
30+
/**
31+
* Constructor.
32+
*
33+
* @link http://php.net/manual/fr/function.mime-content-type.php
34+
*/
35+
public function __construct()
36+
{
37+
}
38+
39+
/**
40+
* Returns whether this guesser is supported on the current OS/PHP setup.
41+
*
42+
* @return bool
43+
*/
44+
public static function isSupported()
45+
{
46+
return function_exists('mime_content_type');
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
public function guess($path)
53+
{
54+
if (!is_file($path)) {
55+
throw new FileNotFoundException($path);
56+
}
57+
58+
if (!is_readable($path)) {
59+
throw new AccessDeniedException($path);
60+
}
61+
62+
if (!self::isSupported()) {
63+
return;
64+
}
65+
66+
return mime_content_type($path);
67+
}
68+
}

0 commit comments

Comments
 (0)