Wrapper for retrieving information about file types with native PHP functions

v1.0.0 2018-12-14 23:16 UTC

README

Wrapper for retrieving information about file types with native PHP functions

Installation

composer require operating-system/file-type

Usage

Instantiate permission:

use OperatingSystem\FileType\FileType;

$fileType = new FileType(stat(__FILE__)['mode']);

Get file type information:

switch ($fileType->getType()) {
    case FileType::SOCKET:
        // is socket
        break;
    case FileType::SYMBOLIC_LINK:
        // is symbolic link
        break;
    case FileType::REGULAR_FILE:
        // is file
        break;
    case FileType::BLOCK_DEVICE:
        // is block device
        break;
    case FileType::DIRECTORY:
        // is directory
        break;
    case FileType::CHARACTER_DEVICE:
        // is character device
        break;
    case FileType::FIFO:
        // is FIFO
        break;
}
$fileType->getMode();               // 33188 
$fileType->isSocket();              // FALSE
$fileType->isSymbolicLink();        // FALSE
$fileType->isFile();                // TRUE
$fileType->isBlockDevice();         // FALSE
$fileType->isDirectory();           // FALSE
$fileType->isCharacterDevice();     // FALSE
$fileType->isFifo();                // FALSE

Testing

$ ./vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.