It is a simple library to create a report of the existing files in an established directory. It has some filters to identify for example: duplicate files or files with the same name.
Install vía Composer
composer require oscarweb/file-reporter
<?php
/* enter correct path */
require __DIR__.'/../vendor/autoload.php';
use FileReporter\FileReporter;
/**
* Set Directory
* @param string
*/
$app = new FileReporter(__DIR__.DIRECTORY_SEPARATOR.'docs');
/**
* Return data
* @return object - default
*/
$response = $app->getReport();
var_dump($response);
Output example here
Report JSON Structure: report.md
To enable cache, with the previous example you must add the directory path where json files will be saved
/**
* Set Cache Directory
* @param string
*/
$app->setCacheDir(__DIR__.DIRECTORY_SEPARATOR.'cache');
/**
* Return data
* @return object - default
*/
$response = $app->getReport();
See example here
Every time you make a new report and have cache enabled, part of the information will be saved in a control file. You can read the information with the following method.
$app = new FileReporter();
/**
* @return object - default
*/
$control = $app->getControl();
Output example here
Control JSON Structure: control.md
You can create a custom recursive function.
/**
* Set Directory
* @param string
*/
$app = new FileReporter(__DIR__.DIRECTORY_SEPARATOR.'docs');
/**
* Set Cache Directory
* @param string
*/
$app->setCacheDir(__DIR__.DIRECTORY_SEPARATOR.'cache');
/**
* Adjust the output of the json file: JSON_PRETTY_PRINT
*/
$app->setJsonPrettyPrint();
/**
* Your custom function
*/
function recursive($route, $app){
$app->setDir($route);
$result = $app->getReport();
foreach($result->content as $item){
if($item->is->dir){
recursive($item->data->route, $app);
}
}
}
recursive($app->getDir(), $app);
See example here
You can filter and create file searches based on cached data.
It can retrieve repeated files based on the hash
value.
$app = new FileReporter(__DIR__.DIRECTORY_SEPARATOR.'docs');
/**
* If you set cache, it will filter on all reports.
*/
$app->setCacheDir(__DIR__.DIRECTORY_SEPARATOR.'cache');
/**
* HASH Files - sha1
* @return object - default
*/
$duplicate_files = $app->filterCache()->repeatsByHash();
See example here
You can see more examples here.