AppserverIo\Appserver\Core\Utilities\FileSystem::recursiveChown PHP Метод

recursiveChown() публичный статический Метод

Will set the owner and group on the passed directory.
public static recursiveChown ( string $path, string $user, string $group = null ) : void
$path string The directory to set the rights for
$user string The user to set
$group string The group to set
Результат void
    public static function recursiveChown($path, $user, $group = null)
    {
        // we don't do anything under Windows
        if (FileSystem::getOsIdentifier() === self::OS_IDENTIFIER_WIN) {
            return;
        }
        // we don't have a directory to change the user/group permissions for
        if (is_dir($path) === false) {
            return;
        }
        // get all the files recursively
        $files = FileSystem::globDir($path . '/*');
        // query whether we've a user passed
        if (empty($user) === false) {
            // Change the rights of everything within the defined dirs
            foreach ($files as $file) {
                FileSystem::chown($file, $user, $group);
            }
            FileSystem::chown($path, $user, $group);
        }
    }

Usage Example

 /**
  * Will set the owner and group on the passed directory recursively.
  *
  * @param \SplFileInfo $targetDir The directory to set the rights for
  * @param string       $user      The user that has to own the passed directory
  * @param string       $group     The group that has to own the passed directory
  *
  * @return void
  */
 public function setUserRights(\SplFileInfo $targetDir, $user = null, $group = null)
 {
     // Get our system configuration as it contains the user and group to set
     $systemConfiguration = $this->getInitialContext()->getSystemConfiguration();
     // check for the existence of a user
     if ($user == null) {
         $user = $systemConfiguration->getParam('user');
     }
     // check for the existence of a group
     if ($group == null) {
         $group = $systemConfiguration->getParam('group');
     }
     // change the owner for the passed directory
     FileSystem::recursiveChown($targetDir, $user, $group);
 }
All Usage Examples Of AppserverIo\Appserver\Core\Utilities\FileSystem::recursiveChown