Gives a string representation of the permissions.

See "Example #2 Display full permissions" on http://php.net/manual/en/function.fileperms.php

@param int $mode

@return FilePermissionCalculator
767058
public static function getStringRepresentation($mode)
    {
        $permissions = '';

        if (($mode & 0xC000) == 0xC000) {
            $permissions = 's'; // socket
        } elseif (($mode & 0xA000) == 0xA000) {
            $permissions = 'l'; // symbolic link
        } elseif (($mode & 0x8000) == 0x8000) {
            $permissions = '-'; // regular
        } elseif (($mode & 0x6000) == 0x6000) {
            $permissions = 'b'; // block special
        } elseif (($mode & 0x4000) == 0x4000) {
            $permissions = 'd'; // directory
        } elseif (($mode & 0x2000) == 0x2000) {
            $permissions = 'c'; // character special
        } elseif (($mode & 0x1000) == 0x1000) {
            $permissions = 'p'; // FIFO pipe
        } else {
            $permissions = 'u'; // unknown
        }

        // owner
        $permissions .= (($mode & 0x0100) ? 'r' : '-');
        $permissions .= (($mode & 0x0080) ? 'w' : '-');
        $permissions .= (($mode & 0x0040) ?
                    (($mode & 0x0800) ? 's' : 'x') :
                    (($mode & 0x0800) ? 'S' : '-'));

        // group
        $permissions .= (($mode & 0x0020) ? 'r' : '-');
        $permissions .= (($mode & 0x0010) ? 'w' : '-');
        $permissions .= (($mode & 0x0008) ?
                    (($mode & 0x0400) ? 's' : 'x') :
                    (($mode & 0x0400) ? 'S' : '-'));

        // world
        $permissions .= (($mode & 0x0004) ? 'r' : '-');
        $permissions .= (($mode & 0x0002) ? 'w' : '-');
        $permissions .= (($mode & 0x0001) ?
                    (($mode & 0x0200) ? 't' : 'x') :
                    (($mode & 0x0200) ? 'T' : '-'));

        return $permissions;
    }
213976
public function getPermission($action)
    {
        $action = strtoupper($action);
        if ($action == 'LIST') {
            return 'VIEW';
        } elseif ($action == 'SHOW') {
            return 'VIEW';
        } elseif ($action == 'NEW') {
            return 'CREATE';
        } elseif ($action == 'EDIT') {
            return 'EDIT';
        } elseif ($action == 'REMOVE') {
            return 'DELETE';
        }
        return $action;
    }
457339
public static function changeFilePermissions($filename, $mode = 0644)
    {

        // make the passed filename OS compliant
        $toBeChanged = Setup::prepareOsSpecificPath($filename);

        // change the mode, if we're not on Windows
        if (SetupKeys::OS_FAMILY_WINDOWS !== strtolower(php_uname('s'))) {
            chmod($toBeChanged, $mode);
        }
    }
20872
public static function permission($path, $full = false)
    {
        if (self::exists($path) === false) {
            return false;
        }

        $perms = fileperms($path);

        if ($full !== true) {
            return substr(sprintf('%o', $perms), -4);
        }

        if (($perms & 0xC000) === 0xC000) {
            $info = 's';
        } elseif (($perms & 0xA000) === 0xA000) {
            $info = 'l';
        } elseif (($perms & 0x8000) === 0x8000) {
            $info = '-';
        } elseif (($perms & 0x6000) === 0x6000) {
            $info = 'b';
        } elseif (($perms & 0x4000) === 0x4000) {
            $info = 'd';
        } elseif (($perms & 0x2000) === 0x2000) {
            $info = 'c';
        } elseif (($perms & 0x1000) === 0x1000) {
            $info = 'p';
        } else {
            $info = 'u';
        }

        $info .= $perms & 0x0100 ? 'r' : '-';
        $info .= $perms & 0x0080 ? 'w' : '-';
        $info .= $perms & 0x0040 ?
                    ($perms & 0x0800 ? 's' : 'x') :
                        ($perms & 0x0800 ? 'S' : '-');

        $info .= $perms & 0x0020 ? 'r' : '-';
        $info .= $perms & 0x0010 ? 'w' : '-';
        $info .= $perms & 0x0008 ?
                    ($perms & 0x0400 ? 's' : 'x') :
                        ($perms & 0x0400 ? 'S' : '-');

        $info .= $perms & 0x0004 ? 'r' : '-';
        $info .= $perms & 0x0002 ? 'w' : '-';
        $info .= $perms & 0x0001 ?
                    ($perms & 0x0200 ? 't' : 'x') :
                        ($perms & 0x0200 ? 'T' : '-');

        return $info;

    }
223192
public function chmod($fileMode)
    {
        if ($this->exists()) {
            // file mode must be from type octal. through converting octal to decimal and the other way around
            // we going sure that the given value is a octal. Any non octal number will be detected.
            if (decoct(octdec($fileMode)) != $fileMode) {
                throw new FileException('Chmod failed, because given permission is not from type octal.');
            }

            // convert a given octal string to a octal integer
            if (is_string($fileMode)) {
                $fileMode = intval($fileMode, 8);
            }

            switch ($fileMode) {
                case 0600: // file owner read and write;
                case 0640: // file owner read and write; owner group read
                case 0660: // file owner read and write; owner group read and write
                case 0604: // file owner read and write; everbody read
                case 0606: // file owner read and write; everbody read and write
                case 0664: // file owner read and write; owner group read and write; everbody read
                case 0666: // file owner read and write; owner group read and write; everbody read and write
                case 0700: // file owner read, execute and write;
                case 0740: // file owner read, execute and write; owner group read
                case 0760: // file owner read, execute and write; owner group read and write
                case 0770: // file owner read, execute and write; owner group read, execute and write
                case 0704: // file owner read, execute and write; everbody read
                case 0706: // file owner read, execute and write; everbody read and write
                case 0707: // file owner read, execute and write; everbody read, execute and write
                case 0744: // file owner read, execute and write; owner group read; everbody read
                case 0746: // file owner read, execute and write; owner group read; everbody read and write
                case 0747: // file owner read, execute and write; owner group read; everbody read, execute and write
                case 0754: // file owner read, execute and write; owner group read and execute; everbody read
                case 0755: // file owner read, execute and write; owner group read and execute; everbody read and execute
                case 0756: // file owner read, execute and write; owner group read and execute; everbody read and write
                case 0757: // file owner read, execute and write; owner group read and execute; everbody read, execute and write
                case 0764: // file owner read, execute and write; owner group read and write; everbody read
                case 0766: // file owner read, execute and write; owner group read and write; everbody read and write
                case 0767: // file owner read, execute and write; owner group read and write; everbody read, execute and write
                case 0774: // file owner read, execute and write; owner group read, execute and write; everbody read
                case 0775: // file owner read, execute and write; owner group read, execute and write; everbody read, execute and write
                case 0776: // file owner read, execute and write; owner group read, execute and write; everbody read and write
                case 0777: // file owner read, execute and write; owner group read, execute and write; everbody read, execute and write
                    break;
                default:
                    $fileMode = 0777;
            }

            return chmod($this->getPathname(), $fileMode);
        }
        return false;
    }
203951
public static function getModeFromStringRepresentation($permissions)
    {
        if (strlen($permissions) !== 10) {
            throw new InvalidArgumentException('Please provide a 10 character long string');
        }
        $mode = 0;

        if ($permissions[0] == 's') {
            $mode = 0140000;
        } elseif ($permissions[0] == 'l') {
            $mode = 0120000;
        } elseif ($permissions[0] == '-') {
            $mode = 0100000;
        } elseif ($permissions[0] == 'b') {
            $mode = 060000;
        } elseif ($permissions[0] == 'd') {
            $mode = 040000;
        } elseif ($permissions[0] == 'c') {
            $mode = 020000;
        } elseif ($permissions[0] == 'p') {
            $mode = 010000;
        } elseif ($permissions[0] == 'u') {
            $mode = 0;
        }

        if ($permissions[1] == 'r') {
            $mode += 0400;
        }
        if ($permissions[2] == 'w') {
            $mode += 0200;
        }
        if ($permissions[3] == 'x') {
            $mode += 0100;
        } elseif ($permissions[3] == 's') {
            $mode += 04100;
        } elseif ($permissions[3] == 'S') {
            $mode += 04000;
        }

        if ($permissions[4] == 'r') {
            $mode += 040;
        }
        if ($permissions[5] == 'w') {
            $mode += 020;
        }
        if ($permissions[6] == 'x') {
            $mode += 010;
        } elseif ($permissions[6] == 's') {
            $mode += 02010;
        } elseif ($permissions[6] == 'S') {
            $mode += 02000;
        }

        if ($permissions[7] == 'r') {
            $mode += 04;
        }
        if ($permissions[8] == 'w') {
            $mode += 02;
        }
        if ($permissions[9] == 'x') {
            $mode += 01;
        } elseif ($permissions[9] == 't') {
            $mode += 01001;
        } elseif ($permissions[9] == 'T') {
            $mode += 01000;
        }

        return $mode;
    }
744449
public function createDir($mode = 0777)
    {
        return is_dir($this->absoluteFileName) || mkdir($this->absoluteFileName, $mode, true);
    }
439961
static ZTFilePermissions fromPosixFileMode(int mode) {
    ZTFilePermissions permissions = new ZTFilePermissions();
    
    permissions.setOwnerCanExecute( (mode &  OWNER_EXECUTE_FLAG)  > 0 );
    permissions.setGroupCanExecute( (mode &  GROUP_EXECUTE_FLAG)  > 0 );
    permissions.setOthersCanExecute((mode &  OTHERS_EXECUTE_FLAG) > 0 );
    
    permissions.setOwnerCanWrite( (mode &  OWNER_WRITE_FLAG)  > 0 );
    permissions.setGroupCanWrite( (mode &  GROUP_WRITE_FLAG)  > 0 );
    permissions.setOthersCanWrite((mode &  OTHERS_WRITE_FLAG) > 0 );
    
    permissions.setOwnerCanRead( (mode &  OWNER_READ_FLAG)  > 0 );
    permissions.setGroupCanRead( (mode &  GROUP_READ_FLAG)  > 0 );
    permissions.setOthersCanRead((mode &  OTHERS_READ_FLAG) > 0 );
    
    return permissions;
  }
519496
public static function chmod($file, $mode)
    {
        if (!@chmod($file, $mode)) {
            throw new IOException(sprintf("Cannot chmod %s to %s", $file, $mode));
        }
    }
289860
function doOpen( $filename, $mode )
    {
        $this->FileHandler = @fopen( $filename, $mode );
        return $this->FileHandler;
    }
262733
public function setMode($mode) {

		if(false === is_string($mode)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($mode)), E_USER_ERROR);
		}

		$this -> mode = $mode;

		return $this;
	}
1241462
public static function getRsa($mode)
    {
        if (self::$rsa) {
            $rsa = self::$rsa;
        } else {
            $rsa = new RSA();
            $rsa->setMGFHash('sha256');
        }

        $rsa->setSignatureMode($mode);

        return $rsa;
    }
1368105
public static function setPermissions(string $path, int $mode = null)
    {
        $is_dir = is_dir($path);

        $current_uid = posix_getuid();
        $owner = @fileowner($path);
        if ($current_uid !== $owner)
            return;

        if (self::$file_group)
        {
            $current_gid = filegroup($path);
            $grpinfo = posix_getgrnam(self::$file_group);
            $wanted_gid = $grpinfo['gid'];
            if ($wanted_gid !== $current_gid)
            {
                try
                {
                    !@chgrp($path, self::$file_group);
                    clearstatcache(true, $path);
                }
                // @codeCoverageIgnoreStart
                // Impossible to test - this would require a RO file system
                catch (Throwable $e)
                {
                    throw new IOException(
                        "Could not set group on " . $path . " to " . self::$file_group
                    );
                }
                // @codeCoverageIgnoreEnd
            }
        }
        
        if ($mode === null)
            $mode = $is_dir ? self::$dir_mode : self::$file_mode;

        if (!empty($mode))
        {
            $perms = self::getPermissions($path);
            $current_mode = $perms['mode'];
            
            if ($mode !== $current_mode)
            {
                try
                {
                    @chmod($path, $mode);
                    clearstatcache(true, $path);
                }
                // @codeCoverageIgnoreStart
                // Impossible to test - this would require a RO file system
                catch (Throwable $e)
                {
                    throw new IOException(
                        "Could not set mode on " . $path . " to " . $mode
                    );
                }
                // @codeCoverageIgnoreEnd
            }
        }
    }
945086
public function getMode($mode = 'list')
    {
        if ($this->getOrder()) {
            $website = $this->_storeManager
                ->getStore($this->getOrder()->getStoreId())
                ->getWebsite();
            $mode = $this->helper->getReviewDisplayType($website);
        }

        return $mode;
    }
717479
public function chmod($filename = '', $mode = 0)
	{
		if (!$filename)
		{
			if (!isset($this->filename) || !$this->filename)
			{
				throw new FilesystemException('Filename not set');
			}

			$filename = $this->filename;
		}

		// If no mode is set use the default
		if (!$mode)
		{
			$mode = $this->filemode;
		}

		// Capture PHP errors
		$php_errormsg = '';
		$trackErrors  = ini_get('track_errors');
		ini_set('track_errors', true);
		$sch = parse_url($filename, PHP_URL_SCHEME);

		// Scheme specific options; ftp's chmod support is fun.
		switch ($sch)
		{
			case 'ftp':
			case 'ftps':
				$res = Helper::ftpChmod($filename, $mode);

				break;

			default:
				$res = chmod($filename, $mode);

				break;
		}

		// Restore error tracking to what it was before.
		ini_set('track_errors', $trackErrors);

		// Seek, interestingly, returns 0 on success or -1 on failure
		if ($res === false)
		{
			throw new FilesystemException($php_errormsg);
		}

		// Return the result
		return true;
	}
855251
public static function getPermissions($path)
    {
        try
        {
            $mode = @fileperms($path);
            if ($mode === false)
                throw new IOException();
        }
        catch (Throwable $e)
        {
            throw new IOException("Could not stat: " . $path);
        }

        $perms = array(
            'owner' => array(
                'read'    => (bool)($mode & 0x0100),
                'write'   => (bool)($mode & 0x0080),
                'execute' => (bool)($mode & 0x0040)
            ),
            'group' => array(
                'read'    => (bool)($mode & 0x0020),
                'write'   => (bool)($mode & 0x0010),
                'execute' => (bool)($mode & 0x0008)
            ),
            'world' => array(
                'read'    => (bool)($mode & 0x0004),
                'write'   => (bool)($mode & 0x0002),
                'execute' => (bool)($mode & 0x0001)
            )
        );

        $perms['mode'] = self::compileMode($perms);
        return $perms;
    }
729837
static Set<PosixFilePermission> getPosixFilePermissions(int mode) {
    Set<PosixFilePermission> result = EnumSet.noneOf(PosixFilePermission.class);

    if ((mode & 0400) != 0) {
      result.add(PosixFilePermission.OWNER_READ);
    }
    if ((mode & 0200) != 0) {
      result.add(PosixFilePermission.OWNER_WRITE);
    }
    if ((mode & 0100) != 0) {
      result.add(PosixFilePermission.OWNER_EXECUTE);
    }
    if ((mode & 040) != 0) {
      result.add(PosixFilePermission.GROUP_READ);
    }
    if ((mode & 020) != 0) {
      result.add(PosixFilePermission.GROUP_WRITE);
    }
    if ((mode & 010) != 0) {
      result.add(PosixFilePermission.GROUP_EXECUTE);
    }
    if ((mode & 04) != 0) {
      result.add(PosixFilePermission.OTHERS_READ);
    }
    if ((mode & 02) != 0) {
      result.add(PosixFilePermission.OTHERS_WRITE);
    }
    if ((mode & 01) != 0) {
      result.add(PosixFilePermission.OTHERS_EXECUTE);
    }
    return result;
  }