PHP code example of automattic / ignorefile

1. Go to this page and download the library: Download automattic/ignorefile 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/ */

    

automattic / ignorefile example snippets


// Read a .myignore file.
$ignore = new IgnoreFile();
$ignore->add( file_get_contents( '.myignore' ) );

// Test if a file is ignored.
if ( $ignore->ignores( $filename ) ) {
        echo "$filename is ignored\n";
} else {
        echo "$filename is not ignored\n";
}

// Filter ignored files from an array of files.
$filesToProcess = $ignore->filter( $allFiles );

// Load all .myignore files in a directory tree, then list all non-ignored files.
$ignore = new IgnoreFile();
$iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( '.' ) );
foreach ( $iter as $path ) {
        if ( basename( $path ) === '.myignore' ) {
                $ignore->add( file_get_contents( $path ), dirname( $path ) . '/' );
        }
}

$iter = new RecursiveIteratorIterator(
    $ignore->filterIterator( new RecursiveDirectoryIterator( '.' ) )
);
foreach ( $iter as $file ) {
        echo "$file\n";
}