Skip to content

szepeviktor/php-chmod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP chmod

Packagist Version Packagist Downloads CI status Contributors Forks Stargazers Issues MIT License

php-chmod is a PHP library for easily changing the permissions recursively.

Versions & Dependencies

Version PHP Documentation
^1.0 ^7.4 current

Requirements

  • PHP >= 7.4
  • php-extension ext-mbstring

Installation

Run composer require MathiasReker/php-chmod

Examples

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

Documentation

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 files/folders permission to the default mode:

$result->fix();

exclude excludes a list of files/folder names (not paths):

$result->exclude(['.docker']);

Roadmap

See the open issues for a complete list of proposed features (and known issues).

Contributing

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!

License

It is distributed under the MIT License. See LICENSE for more information.

About

php-chmod is a PHP library for easily changing permissions recursively.

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%