PHP code example of wexample / php-file

1. Go to this page and download the library: Download wexample/php-file library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wexample / php-file example snippets


use Wexample\PhpFile\Class\FileSystemItemScanner;

$scanner = new FileSystemItemScanner('/srv/project');

foreach ($scanner->scanLevel('src') as $item) {
    echo $item[FileSystemItemScanner::KEY_NAME], ' ',
        $item[FileSystemItemScanner::KEY_TYPE]->value, PHP_EOL;
}

$one = $scanner->scanOne('src/Kernel.php'); // null outside the root

use Wexample\PhpFile\Class\PathMatcher;

$matcher = new PathMatcher(['src/**', '!src/vendor/', '*.md']);

$matcher->matches('src/Kernel.php');   // true
$matcher->matches('other/thing.php');  // false
$matcher->couldMatchUnder('src');      // true

use Wexample\PhpFile\Helper\FileSizeHelper;

FileSizeHelper::format(1536);    // '1.5 KB'
FileSizeHelper::parse('10MB');   // 10485760
FileSizeHelper::parse('10 Mo');  // 10485760
FileSizeHelper::parse('nonsense'); // null
bash
composer