Skip to content
This repository was archived by the owner on Feb 12, 2020. It is now read-only.

Commit 3e46709

Browse files
committed
-- reorganize
-- simplify methods
1 parent eee97f7 commit 3e46709

24 files changed

+469
-1790
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build export-ignore
2+
/tests export-ignore

README.md

Lines changed: 173 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ A comprehensive MIME and file extension tool for PHP. Finally!
99
1. [Features](#features)
1010
2. [Requirements](#requirements)
1111
2. [Installation](#installation)
12-
3. Reference
13-
* [By MIME](https://github.com/Blobfolio/blob-mimes/blob/master/docs/MIME.md)
14-
* [By Extension](https://github.com/Blobfolio/blob-mimes/blob/master/docs/EXTENSION.md)
15-
* [By File](https://github.com/Blobfolio/blob-mimes/blob/master/docs/FILE.md)
16-
* [Build Sources](https://github.com/Blobfolio/blob-mimes/blob/master/docs/BUILD.md)
12+
3. [Reference](#reference)
13+
* [check_ext_and_mime()](#check_ext_and_mime)
14+
* [finfo()](#finfo)
15+
* [get_extension()](#get_extension)
16+
* [get_extensions()](#get_extensions)
17+
* [get_mime()](#get_mime)
18+
* [get_mimes()](#get_mimes)
1719
4. [License](#license)
1820

1921

@@ -34,38 +36,189 @@ The database is compiled from the following sources:
3436
* [Apache](https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types)
3537
* [Nginx](http://hg.nginx.org/nginx/raw-file/default/conf/mime.types)
3638
* [freedesktop.org](https://cgit.freedesktop.org/xdg/shared-mime-info/plain/freedesktop.org.xml.in)
37-
* [WordPress](https://developer.wordpress.org/reference/functions/wp_get_mime_types/) *at runtime, if present
3839

3940

4041

4142
## Requirements
4243

43-
At a bare minimum you need to be running PHP v5.3+ with the `php-json` module.
44+
blob-mimes requires PHP 7+ with the following modules:
4445

45-
Composer requires PHP v5.3.2.
46+
* BCMath
47+
* DOM
48+
* Fileinfo
49+
* Filter
50+
* JSON
51+
* MBString
52+
* SimpleXML
4653

47-
Optional modules include:
48-
49-
* `php-mbstring`: multi-byte support;
50-
* `php-fileinfo`: derive "true" file type from contents;
51-
* `php-iconv`: UTF-8 support if you have not installed via Composer or are not running WordPress
54+
UTF-8 is used for all string encoding. This could create conflicts on environments using something else.
5255

53-
The standalone build script requires a Unix environment (e.g. Linux, OS X, BSD...) and PHP CLI v7.0+ with the following modules:
54-
55-
* `php-mbstring`
56-
* `php-simplexml`
57-
* `php-curl`
56+
The build script additionally requires cURL.
5857

5958

6059

6160
## Installation
6261

63-
Composer is the easiest:
62+
Install via Composer:
6463
```bash
6564
composer require "blobfolio/blob-mimes:dev-master"
6665
```
6766

68-
Otherwise, download the `src` directory and include all the PHP scripts in your application. If your project has an autoloader, point the `blobmimes` namespace to `src/blobmimes`.
67+
68+
69+
## Reference
70+
71+
### check_ext_and_mime()
72+
73+
Verify that a file extension and MIME type belong together. Because technology is always evolving and the MIME standard is always changing, this will consider `some/thing` and `some/x-thing` equivalent.
74+
75+
#### Arguments
76+
77+
* (*string*) File extension
78+
* (*string*) MIME type
79+
* (*bool*) (*optional*) Soft pass. If `TRUE`, the check will return `TRUE` if it lacks information about either the extension or MIME type.
80+
81+
#### Returns
82+
83+
Returns `TRUE` or `FALSE`.
84+
85+
#### Example
86+
87+
```php
88+
$foo = blobfolio\mimes\mimes::check_ext_and_mime('jpeg', 'image/jpeg'); //TRUE
89+
$foo = blobfolio\mimes\mimes::check_ext_and_mime('jpeg', 'image/gif'); //FALSE
90+
```
91+
92+
93+
94+
### finfo()
95+
96+
Pull path and type information for a file, using its name and/or content. If it is determined that the file is incorrectly named, alternative names with the correct file extension(s) are suggested.
97+
98+
#### Arguments
99+
100+
* (*string*) Path
101+
* (*string*) (*optional*) Nice name. If provided, the nice name will be treated as the filename. This can be useful if passing a temporary upload, for example. Default: `NULL`
102+
103+
#### Returns
104+
105+
Returns all file information that can be derived according to the format below.
106+
107+
#### Example
108+
109+
```php
110+
print_r(blobfolio\mimes\mimes::finfo('../wp/img/blobfolio.svg'));
111+
/*
112+
array(
113+
[dirname] => /var/www/blob-common/wp/img
114+
[basename] => blobfolio.svg
115+
[extension] => svg
116+
[filename] => blobfolio
117+
[path] => /var/www/blob-common/wp/img/blobfolio.svg
118+
[mime] => image/svg+xml
119+
[suggested_filename] => array()
120+
)
121+
*/
122+
```
123+
124+
125+
126+
### get_extension()
127+
128+
Retrieve information about a file extension.
129+
130+
#### Arguments
131+
132+
* (*string*) File extension
133+
134+
#### Returns
135+
136+
Returns the information or `FALSE`.
137+
138+
```php
139+
print_r(blobfolio\mimes\mimes::get_extension('jpeg'));
140+
/*
141+
array(
142+
[ext] => jpeg
143+
[mime] => array(
144+
0 => image/jpeg
145+
1 => image/pjpeg
146+
)
147+
[source] => array(
148+
0 => Apache
149+
1 => Nginx
150+
2 => freedesktop.org
151+
)
152+
[alias] => array(
153+
] => image/pjpeg
154+
)
155+
[primary] => image/jpeg
156+
)
157+
*/
158+
```
159+
160+
161+
162+
### get_extensions()
163+
164+
Retrieve information about all known file extensions.
165+
166+
#### Arguments
167+
168+
N/A
169+
170+
#### Returns
171+
172+
Returns a MIME database oganized by extension.
173+
174+
175+
176+
### get_mime()
177+
178+
Retrieve information about a MIME type.
179+
180+
#### Arguments
181+
182+
* (*string*) MIME type
183+
184+
#### Returns
185+
186+
Returns the information or `FALSE`.
187+
188+
#### Example
189+
190+
```php
191+
print_r(blobfolio\mimes\mimes::get_mime('image/jpeg'));
192+
/*
193+
array(
194+
[mime] => image/jpeg
195+
[ext] => array(
196+
0 => jpeg
197+
1 => jpg
198+
2 => jpe
199+
)
200+
[source] => array(
201+
0 => Apache
202+
1 => Nginx
203+
2 => freedesktop.org
204+
)
205+
)
206+
*/
207+
```
208+
209+
210+
211+
### get_mimes()
212+
213+
Retrieve information about all known MIME types.
214+
215+
#### Arguments
216+
217+
N/A
218+
219+
#### Returns
220+
221+
Returns a MIME database oganized by type.
69222

70223

71224

docs/BUILD.md renamed to build/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ The combined data will be output to two different JSON files:
2020
* `build/extensions_by_mime.json`
2121
* `build/mimes_by_extension.json`
2222

23-
After a build has completed, copy these two files to the main `src` directory.
23+
After a build has completed, copy these two files to the main `lib/blobfolio/mimes` directory.

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"extensions",
88
"suffix"
99
],
10+
"version": "1.0.0",
1011
"type": "library",
1112
"homepage": "https://github.com/Blobfolio/blob-mimes",
1213
"license": "GPLv2",
@@ -18,11 +19,16 @@
1819
}
1920
],
2021
"require": {
21-
"neitanod/forceutf8": "dev-master"
22+
"neitanod/forceutf8": "dev-master",
23+
"blobfolio/blob-common": "dev-master"
24+
},
25+
"config": {
26+
"vendor-dir": "lib/vendor",
27+
"preferred-install": "dist"
2228
},
2329
"autoload": {
2430
"psr-4": {
25-
"blobmimes\\": "src/blobmimes"
31+
"blobfolio\\mimes\\": "lib/blobfolio/mimes"
2632
}
2733
}
2834
}

0 commit comments

Comments
 (0)