Wrapper for retrieving information about an operating system group with native PHP functions

v1.0.0 2018-12-13 19:18 UTC

README

Wrapper for retrieving information about an operating system group with native PHP functions

Installation

composer require operating-system/group

Usage

Instantiate group with gid 0:

use OperatingSystem\Group\Group;
use OperatingSystem\Group\Exception\PosixNotAvailableException;

try {
    $group = new Group(0);
} catch (PosixNotAvailableException $e) {
    $e->getMessage;         // 'Could not retrieve information about the operating system group because POSIX functions are not available to your PHP executable.'
}

Get group information for group:

$group->getName();           // 'root'
$group->getPassword();       // 'x'
$group->getMembers();        // ['root']
$group->getGid();            // 0

Factory methods:

use OperatingSystem\Group\Factory\GroupFactory;
use OperatingSystem\Group\Exception\PosixNotAvailableException;

try {
    $group = GroupFactory::createFromExecutedFileGroup();
} catch (PosixNotAvailableException $e) {
    $e->getMessage;         // 'Could not retrieve information about the operating system group because POSIX functions are not available to your PHP executable.'
} catch (\Exception $e) {
    $e->getMessage;         // 'Could not get the group of the current script.'
}

try {
    $group = GroupFactory::createFromEffectiveProcessGroup();
} catch (PosixNotAvailableException $e) {
    $e->getMessage;         // 'Could not retrieve information about the operating system group because POSIX functions are not available to your PHP executable.'
} catch (\Exception $e) {
    $e->getMessage;         // 'Could not get the effective group of the current process.'
}

try {
    $group = GroupFactory::createFromRealProcessGroup();
} catch (PosixNotAvailableException $e) {
    $e->getMessage;         // 'Could not retrieve information about the operating system group because POSIX functions are not available to your PHP executable.'
} catch (\Exception $e) {
    $e->getMessage;         // 'Could not get the real group of the current process.'
}

try {
    $group = GroupFactory::createFromFileGroup(__FILE__);
} catch (\InvalidArgumentException $e) {
    $e->getMessage;         // 'Invalid file name provided.'
} catch (PosixNotAvailableException $e) {
    $e->getMessage;         // 'Could not retrieve information about the operating system group because POSIX functions are not available to your PHP executable.'
} catch (\Exception $e) {
    $e->getMessage;         // 'Could not get the real group of the current process.'
}

Testing

$ ./vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.