JBZoo\Utils\FS::_setPerms PHP Method

_setPerms() protected static method

protected static _setPerms ( string $filename, boolean $isFlag, integer $perm ) : boolean
$filename string
$isFlag boolean
$perm integer
return boolean
    protected static function _setPerms($filename, $isFlag, $perm)
    {
        $stat = @stat($filename);
        if ($stat === false) {
            return false;
        }
        // We're on Windows
        if (Sys::isWin()) {
            //@codeCoverageIgnoreStart
            return true;
            //@codeCoverageIgnoreEnd
        }
        list($myuid, $mygid) = array(posix_geteuid(), posix_getgid());
        $isMyUid = $stat['uid'] == $myuid;
        $isMyGid = $stat['gid'] == $mygid;
        //@codeCoverageIgnoreStart
        if ($isFlag) {
            // Set only the user writable bit (file is owned by us)
            if ($isMyUid) {
                return chmod($filename, fileperms($filename) | intval('0' . $perm . '00', 8));
            }
            // Set only the group writable bit (file group is the same as us)
            if ($isMyGid) {
                return chmod($filename, fileperms($filename) | intval('0' . $perm . $perm . '0', 8));
            }
            // Set the world writable bit (file isn't owned or grouped by us)
            return chmod($filename, fileperms($filename) | intval('0' . $perm . $perm . $perm, 8));
        } else {
            // Set only the user writable bit (file is owned by us)
            if ($isMyUid) {
                $add = intval('0' . $perm . $perm . $perm, 8);
                return self::_chmod($filename, $perm, $add);
            }
            // Set only the group writable bit (file group is the same as us)
            if ($isMyGid) {
                $add = intval('00' . $perm . $perm, 8);
                return self::_chmod($filename, $perm, $add);
            }
            // Set the world writable bit (file isn't owned or grouped by us)
            $add = intval('000' . $perm, 8);
            return self::_chmod($filename, $perm, $add);
        }
        //@codeCoverageIgnoreEnd
    }