Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
URL-encode according to RFC 3986
<?php rawurlencode(string $string): string
<?php                 if ($this->io->hasAuthentication($match[1])) {

                    $auth = $this->io->getAuthentication($match[1]);

                    $authUrl = 'https://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[1] . '/' . $match[2] . '.git';

                    $command = call_user_func($commandCallable, $authUrl);

                    if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {

                        return;
<?php                         return;

                    }



                    $credentials = array(rawurlencode($auth['username']), rawurlencode($auth['password']));

                    $errorMsg = $this->process->getErrorOutput();

                }

            } elseif (Preg::isMatch('{^https://(bitbucket\.org)/(.*?)(?:\.git)?$}i', $url, $match)) { //bitbucket oauth
<?php                 if ($this->io->hasAuthentication($match[1])) {

                    $auth = $this->io->getAuthentication($match[1]);

                    $authUrl = 'https://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[1] . '/' . $match[2] . '.git';



                    $command = call_user_func($commandCallable, $authUrl);

                    if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {
<?php                         return;

                    }



                    $credentials = array(rawurlencode($auth['username']), rawurlencode($auth['password']));

                    $errorMsg = $this->process->getErrorOutput();

                } else { // Falling back to ssh

                    $sshUrl = 'git@bitbucket.org:' . $match[2] . '.git';
<?php                 if ($this->io->hasAuthentication($match[2])) {

                    $auth = $this->io->getAuthentication($match[2]);

                    if ($auth['password'] === 'private-token' || $auth['password'] === 'oauth2' || $auth['password'] === 'gitlab-ci-token') {

                        $authUrl = $match[1] . '://' . rawurlencode($auth['password']) . ':' . rawurlencode($auth['username']) . '@' . $match[2] . '/' . $match[3]; // swap username and password

                    } else {

                        $authUrl = $match[1] . '://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[2] . '/' . $match[3];

                    }
<?php                     if ($auth['password'] === 'private-token' || $auth['password'] === 'oauth2' || $auth['password'] === 'gitlab-ci-token') {

                        $authUrl = $match[1] . '://' . rawurlencode($auth['password']) . ':' . rawurlencode($auth['username']) . '@' . $match[2] . '/' . $match[3]; // swap username and password

                    } else {

                        $authUrl = $match[1] . '://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[2] . '/' . $match[3];

                    }



                    $command = call_user_func($commandCallable, $authUrl);
<?php                         return;

                    }



                    $credentials = array(rawurlencode($auth['username']), rawurlencode($auth['password']));

                    $errorMsg = $this->process->getErrorOutput();

                }

            } elseif ($this->isAuthenticationFailure($url, $match)) { // private non-github/gitlab/bitbucket repo that failed to authenticate
<?php                 }



                if ($auth) {

                    $authUrl = $match[1] . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[2] . $match[3];



                    $command = call_user_func($commandCallable, $authUrl);

                    if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {
<?php                         return;

                    }



                    $credentials = array(rawurlencode($auth['username']), rawurlencode($auth['password']));

                    $errorMsg = $this->process->getErrorOutput();

                }

            }
<?php         }

        $note .= ' ' . date('Y-m-d Hi');



        $url = 'https://'.$originUrl.'/settings/tokens/new?scopes=&description=' . str_replace('%20', '+', rawurlencode($note));

        $this->io->writeError(sprintf('When working with _public_ GitHub repositories only, head to %s to retrieve a token.', $url));

        $this->io->writeError('This token will have read-only permission for public information only.');
<?php         $this->io->writeError(sprintf('When working with _public_ GitHub repositories only, head to %s to retrieve a token.', $url));

        $this->io->writeError('This token will have read-only permission for public information only.');



        $url = 'https://'.$originUrl.'/settings/tokens/new?scopes=repo&description=' . str_replace('%20', '+', rawurlencode($note));

        $this->io->writeError(sprintf('When you need to access _private_ GitHub repositories as well, go to %s', $url));

        $this->io->writeError('Note that such tokens have broad read/write permissions on your behalf, even if not needed by Composer.');

        $this->io->writeError(sprintf('Tokens will be stored in plain text in "%s" for future use by Composer.', $this->config->getAuthConfigSource()->getName()));
<?php         if (Preg::isMatch('{^(https?)://((.+)(?:\:(.+))?@)?([^/]+)(/.*)?}mi', $url, $match) && $this->io->hasAuthentication($match[5])) {

            $auth = $this->io->getAuthentication($match[5]);

            $authenticatedUrl = $match[1] . '://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[5] . (!empty($match[6]) ? $match[6] : null);



            $command = call_user_func($commandCallable, $authenticatedUrl);