AppserverIo\Appserver\Core\Utilities\FileSystem::initUmask PHP Method

initUmask() public static method

Init the umask to use creating files/directories, either with the passed value or the one found in the configuration.
public static initUmask ( integer $umask ) : void
$umask integer The new umask to set
return void
    public static function initUmask($umask)
    {
        // don't do anything under Windows
        if (FileSystem::getOsIdentifier() === self::OS_IDENTIFIER_WIN) {
            return;
        }
        // set new umask to use
        umask($umask);
        // query whether the new umask has been set or not
        if (umask() != $umask) {
            throw new \Exception(sprintf('Can\'t set umask \'%s\' found \'%\' instead', $umask, umask()));
        }
    }

Usage Example

 /**
  * Init the umask to use creating files/directories, either with
  * the passed value or the one found in the configuration.
  *
  * @param integer $umask The new umask to set
  *
  * @return void
  * @throws \Exception Is thrown if the umask can not be set
  */
 public function initUmask($umask = null)
 {
     // check if a umask has been passed
     if ($umask == null) {
         $umask = $this->getInitialContext()->getSystemConfiguration()->getParam('umask');
     }
     // initialize the umask
     FileSystem::initUmask($umask);
 }