The package provides useful methods to manage files and directories.
- PHP 7.4 or higher.
The package could be installed with composer:
composer require yiisoft/files --prefer-dist
Create a new directory:
use \Yiisoft\Files\FileHelper;
$directory = '/path/to/dir';
FileHelper::createDirectory($directory);
Create a new directory with the permission to be set:
use \Yiisoft\Files\FileHelper;
$directory = '/path/to/dir';
FileHelper::createDirectory($directory, 0775);
Remove a directory:
use \Yiisoft\Files\FileHelper;
$directory = '/path/to/dir';
FileHelper::removeDirectory($directory);
Remove a file or symlink:
use \Yiisoft\Files\FileHelper;
$file = '/path/to/file.txt';
FileHelper::unlink($file);
Normalize path:
use \Yiisoft\Files\FileHelper;
$path = '/home/samdark/./test/..///dev\yii/';
echo FileHelper::normalizePath($path);
// outputs:
// /home/samdark/dev/yii
File helper methods are static so usage is like the following:
\Yiisoft\Files\FileHelper::copyDirectory('/home/master/inbox', '/backup/inbox') ?>
Overall the helper has the following method groups.
- createDirectory
- copyDirectory
- clearDirectory
- removeDirectory
- isEmptyDirectory
- findDirectories
- findFiles
- openFile
- normalizePath
- unlink
- lastModifiedTime
The package is tested with PHPUnit. To run tests:
./vendor/bin/phpunit
The package tests are checked with Infection mutation framework with Infection Static Analysis Plugin. To run it:
./vendor/bin/roave-infection-static-analysis-plugin
The code is statically analyzed with Psalm. To run static analysis:
./vendor/bin/psalm
The Yii Files is free software. It is released under the terms of the BSD License.
Please see LICENSE
for more information.
Maintained by Yii Software.