php-chmod
is a PHP library for easily changing the permissions recursively.
Version | PHP | Documentation |
---|---|---|
^1.0 | ^7.4 | current |
PHP
>= 7.4- php-extension
ext-mbstring
Run composer require MathiasReker/php-chmod
Dry run:
<?php
use MathiasReker\PhpChmod\FilePerm;
require __DIR__ . '/vendor/autoload.php';
$result = (new FilePerm([__DIR__]))
->setDefaultModeFile(0644)
->setDefaultModeFolder(0755)
->setAllowedModeFiles([0400, 0444, 0640])
->setAllowedModeFolders([0750])
->scan()
->dryRun();
var_dump($result); // string[]
Fix:
<?php
use MathiasReker\PhpChmod\FilePerm;
require __DIR__ . '/vendor/autoload.php';
$result = (new FilePerm([__DIR__]))
->setDefaultModeFile(0644)
->setDefaultModeFolder(0755)
->setAllowedModeFiles([0400, 0444, 0640])
->setAllowedModeFolders([0750])
->scan()
->fix();
var_dump($result); // bool
The constructor takes an array of directories to scan:
$result = new FilePerm([__DIR__]);
setDefaultModeFile
sets the default file permission:
$result->setDefaultModeFile(0644);
setDefaultModeFolder
sets the default folder permission:
$result->setDefaultModeFolder(0755);
setAllowedModeFiles
sets the allowed permissions for files. Files with these permissions will be skipped:
$result->setAllowedModeFiles([0400, 0444, 0640]);
setAllowedModeFolders
sets the allowed permissions for folders. Folders with these permissions will be skipped:
$result->setAllowedModeFolders([0750]);
scan
finds all the concerned files/folders:
$result->scan();
setConcernedPaths
sets concerned files manually. This is useful if you want to use a custom scanner:
$result->setConcernedPaths($paths);
dryRun
returns an array of concerned files/folders:
$result->dryRun();
fix
changes the concerned file/folder permissions to the default mode:
$result->fix();
exclude
excludes a list of files/folder names (not paths):
$result->exclude(['.docker']);
See the open issues for a complete list of proposed features (and known issues).
If you have a suggestion to improve this, please fork the repo and create a pull request. You can also open an issue with the tag "enhancement". Finally, don't forget to give the project a star! Thanks again!
It is distributed under the MIT License. See LICENSE
for more information.