Skip to content

Library to validate symbolic and octal modes used by unix chmod program

License

Notifications You must be signed in to change notification settings

oliwierptak/phuxtil-chmod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phuxtil-chmod

Easy way to validate symbolic and octal modes used by unix chmod program.

In Unix and Unix-like operating systems, chmod is the command and system call which is used to change the access permissions of file system objects. It is also used to change special mode flags.

Installation

composer require phuxtil/chmod

Note: Use v1.x for compatibility with PHP v7.0+ Note: Use v2.x for compatibility with PHP v7.2+

Usage

Facade

Create new instance:

$facade = new ChmodFacade();
isReadable(...)
$facade->isReadable('0755');     # true
$facade->isReadable('0334');     # true
$facade->isReadable('0333');     # false
isWritable(...)
$facade->isWritable('0644');     # true
$facade->isWritable('0222');     # true
$facade->isWritable('0111');     # false
isExecutable(...)
$facade->isExecutable('0755');     # true
$facade->isExecutable('0644');     # false
$facade->isExecutable('0222');     # false
validateByOctal(...)
$facade->validateByOctal('0755', 'u', 'r');     # true
$facade->validateByOctal('0755', 'u', 'x');     # true
$facade->validateByOctal('0755', 'o', 'w');     # false
validateBySymbol(...)
$facade->validateBySymbol('-rw-r--r--', 'u', 'r');     # true
$facade->validateBySymbol('-rw-r--r--', 'u', 'x');     # false
$facade->validateBySymbol('-rw-r--r--', 'o', 'r');     # true
applyUid(...)
$facade->applyUid('0644');          # 4644
applyGid(...)
$facade->applyGid('0644');          # 2644
applyUidAndGid(...)
$facade->applyUidAndGid('0644');    # 6644
toArray()
print_r($facade->toArray('0775'));
[
    'u' => [
        'r' => 'r',
        'w' => 'w',
        'x' => 'x',
    ],
    'g' => [
        'r' => 'r',
        'w' => 'w',
        'x' => 'x',
    ],
    'o' => [
        'r' => 'r',
        'w' => '-',
        'x' => 'x',
    ]
]

See tests for details.

About

Library to validate symbolic and octal modes used by unix chmod program

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages