alex-kalanis / kw_mime
Determine file mime type in KWCMS
v3.1.0
2025-05-08 20:56 UTC
Requires
- php: >=7.4.0
- alex-kalanis/kw_paths: >=4.0 <5
Requires (Dev)
- ext-fileinfo: *
- alex-kalanis/kw_files: >=5.0 <6
- alex-kalanis/kw_storage: >=6.0 <7
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: >=9.0 <10
- shipmonk/composer-dependency-analyser: ^1.4
Suggests
- ext-fileinfo: *
- alex-kalanis/kw_files: Accessing stored entries as files on some volume
- alex-kalanis/kw_storage: Universal storage library for store data as key-value pairs
README
Simple library to access mime type of sent file. Just makes nice facade to mime libraries.
PHP Installation
composer.phar require alex-kalanis/kw_mime
(Refer to Composer Documentation if you are not familiar with composer)
PHP Usage
1.) Use your autoloader (if not already done via Composer autoloader)
2.) Connect the "\kalanis\kw_mime\MimeType" into your app. Extends it for setting your case.
3.) Just call setting and render
// Somewhere in DI return function ($params): \kalanis\kw_mime\Interfaces\IMime { return (new \kalanis\kw_mime\Check\Factory())->getLibrary($params); }
// In code class MimeExample { public function __construct( // ... protected readonly \kalanis\kw_mime\Interfaces\IMime $mime, // ... ) { } public function which(string $file): string { $path = (new \kalanis\kw_paths\ArrayPath())->setString($file); return $this->mime->getMime($path->getArray()); } }
Caveats
If not specified by time of construction it uses external libraries in extension ext-fileinfo. Be aware of that.