CFile::setGroup PHP Method

setGroup() public method

For POSIX systems. Asserts that group exists before process if posix_ functions are available.
public setGroup ( string | integer $group, boolean $recursive = False ) : CFile | boolean
$group string | integer New group name or ID
$recursive boolean Apply group to directory contents flag.
return CFile | boolean Current CFile object on success, 'False' on fail.
    public function setGroup($group, $recursive = False)
    {
        if (function_exists('posix_getgrnam') && function_exists('posix_getgrgid')) {
            if (posix_getgrnam($group) == False xor is_numeric($group) && posix_getgrgid($group) == False) {
                throw new CFileException('Unable to set group for filesystem object. Group "' . $group . '" is not found.');
            }
        }
        if ($this->getExists()) {
            $success = @chgrp($this->_realpath, $group);
            if ($success) {
                $this->_group = $group;
            }
            if ($success && $this->getIsDir() && $recursive) {
                $contents = $this->getContents(True);
                foreach ($contents as $filepath) {
                    if (!@chgrp($filepath, $group)) {
                        $this->addLog('Unable to set group for "' . $filepath . '" to "' . $group . '"');
                        $success = False;
                    }
                }
            }
            if ($success) {
                return $this;
            }
        }
        $this->addLog('Unable to set group for filesystem object to "' . $group . '"');
        return False;
    }