/**
* Helper method which allows to execute a callable as the super user the server got started by.
*
* @param callable $callable The callable to run
* @param array $arguments Arguments to pass to the callable
*
* @return mixed The callables result
*/
public static function sudo(callable $callable, array $arguments = array())
{
// don't do anything under Windows
if (FileSystem::getOsIdentifier() === FileSystem::OS_IDENTIFIER_WIN) {
return call_user_func_array($callable, $arguments);
}
// get the current user user pair (super user and effective user)
$currentUserId = (int) posix_geteuid();
$superUserId = (int) posix_getuid();
// temporarily switch to the super user
posix_seteuid($superUserId);
// execute the callable
$result = call_user_func_array($callable, $arguments);
// switch back to the effective user
posix_seteuid($currentUserId);
return $result;
}