Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php declare(strict_types=1); /* * This file is part of Composer. * * (c) Nils Aderma..
Decoded Output download
<?php declare(strict_types=1);
/*
* This file is part of Composer.
*
* (c) Nils Adermann <[email protected]>
* Jordi Boggiano <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Util\Http;
use Composer\Downloader\TransportException;
use Composer\Util\NoProxyPattern;
/**
* @internal
* @author John Stevenson <[email protected]>
*/
class ProxyManager
{
/** @var ?string */
private $error = null;
/** @var ?ProxyItem */
private $httpProxy = null;
/** @var ?ProxyItem */
private $httpsProxy = null;
/** @var ?NoProxyPattern */
private $noProxyHandler = null;
/** @var ?self */
private static $instance = null;
/** The following 3 properties can be removed after the transition period */
/** @var bool */
private $ignoreHttpsProxy = false;
/** @var bool */
private $isTransitional = false;
/** @var bool */
private $needsTransitionWarning = false;
private function __construct()
{
// this can be removed after the transition period
$this->isTransitional = true;
try {
$this->getProxyData();
} catch (\RuntimeException $e) {
$this->error = $e->getMessage();
}
}
public static function getInstance(): ProxyManager
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Clears the persistent instance
*/
public static function reset(): void
{
self::$instance = null;
}
/**
* Returns a RequestProxy instance for the request url
*
* @param non-empty-string $requestUrl
*/
public function getProxyForRequest(string $requestUrl): RequestProxy
{
if ($this->error !== null) {
throw new TransportException('Unable to use a proxy: '.$this->error);
}
$scheme = (string) parse_url($requestUrl, PHP_URL_SCHEME);
$proxy = $this->getProxyForScheme($scheme);
if ($proxy === null) {
return RequestProxy::none();
}
if ($this->noProxy($requestUrl)) {
return RequestProxy::noProxy();
}
return $proxy->toRequestProxy($scheme);
}
/**
* Returns true if the user needs to set an https_proxy environment variable
*
* This method can be removed after the transition period
*/
public function needsTransitionWarning(): bool
{
return $this->needsTransitionWarning;
}
/**
* Returns a ProxyItem if one is set for the scheme, otherwise null
*/
private function getProxyForScheme(string $scheme): ?ProxyItem
{
if ($scheme === 'http') {
return $this->httpProxy;
}
if ($scheme === 'https') {
// this can be removed after the transition period
if ($this->isTransitional && $this->httpsProxy === null) {
if ($this->httpProxy !== null && !$this->ignoreHttpsProxy) {
$this->needsTransitionWarning = true;
return $this->httpProxy;
}
}
return $this->httpsProxy;
}
return null;
}
/**
* Finds proxy values from the environment and sets class properties
*/
private function getProxyData(): void
{
// Handle http_proxy/HTTP_PROXY on CLI only for security reasons
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
[$env, $name] = $this->getProxyEnv('http_proxy');
if ($env !== null) {
$this->httpProxy = new ProxyItem($env, $name);
}
}
// Handle cgi_http_proxy/CGI_HTTP_PROXY if needed
if ($this->httpProxy === null) {
[$env, $name] = $this->getProxyEnv('cgi_http_proxy');
if ($env !== null) {
$this->httpProxy = new ProxyItem($env, $name);
}
}
// Handle https_proxy/HTTPS_PROXY
[$env, $name] = $this->getProxyEnv('https_proxy');
if ($env !== null) {
$this->httpsProxy = new ProxyItem($env, $name);
}
// Handle no_proxy/NO_PROXY
[$env, $name] = $this->getProxyEnv('no_proxy');
if ($env !== null) {
$this->noProxyHandler = new NoProxyPattern($env);
}
}
/**
* Searches $_SERVER for case-sensitive values
*
* @return array{0: string|null, 1: string} value, name
*/
private function getProxyEnv(string $envName): array
{
$names = [strtolower($envName), strtoupper($envName)];
foreach ($names as $name) {
if (is_string($_SERVER[$name] ?? null)) {
if ($_SERVER[$name] !== '') {
return [$_SERVER[$name], $name];
}
// this can be removed after the transition period
if ($this->isTransitional && strtolower($name) === 'https_proxy') {
$this->ignoreHttpsProxy = true;
break;
}
}
}
return [null, ''];
}
/**
* Returns true if a url matches no_proxy value
*/
private function noProxy(string $requestUrl): bool
{
if ($this->noProxyHandler === null) {
return false;
}
return $this->noProxyHandler->test($requestUrl);
}
}
?>
Did this file decode correctly?
Original Code
<?php declare(strict_types=1);
/*
* This file is part of Composer.
*
* (c) Nils Adermann <[email protected]>
* Jordi Boggiano <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Util\Http;
use Composer\Downloader\TransportException;
use Composer\Util\NoProxyPattern;
/**
* @internal
* @author John Stevenson <[email protected]>
*/
class ProxyManager
{
/** @var ?string */
private $error = null;
/** @var ?ProxyItem */
private $httpProxy = null;
/** @var ?ProxyItem */
private $httpsProxy = null;
/** @var ?NoProxyPattern */
private $noProxyHandler = null;
/** @var ?self */
private static $instance = null;
/** The following 3 properties can be removed after the transition period */
/** @var bool */
private $ignoreHttpsProxy = false;
/** @var bool */
private $isTransitional = false;
/** @var bool */
private $needsTransitionWarning = false;
private function __construct()
{
// this can be removed after the transition period
$this->isTransitional = true;
try {
$this->getProxyData();
} catch (\RuntimeException $e) {
$this->error = $e->getMessage();
}
}
public static function getInstance(): ProxyManager
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Clears the persistent instance
*/
public static function reset(): void
{
self::$instance = null;
}
/**
* Returns a RequestProxy instance for the request url
*
* @param non-empty-string $requestUrl
*/
public function getProxyForRequest(string $requestUrl): RequestProxy
{
if ($this->error !== null) {
throw new TransportException('Unable to use a proxy: '.$this->error);
}
$scheme = (string) parse_url($requestUrl, PHP_URL_SCHEME);
$proxy = $this->getProxyForScheme($scheme);
if ($proxy === null) {
return RequestProxy::none();
}
if ($this->noProxy($requestUrl)) {
return RequestProxy::noProxy();
}
return $proxy->toRequestProxy($scheme);
}
/**
* Returns true if the user needs to set an https_proxy environment variable
*
* This method can be removed after the transition period
*/
public function needsTransitionWarning(): bool
{
return $this->needsTransitionWarning;
}
/**
* Returns a ProxyItem if one is set for the scheme, otherwise null
*/
private function getProxyForScheme(string $scheme): ?ProxyItem
{
if ($scheme === 'http') {
return $this->httpProxy;
}
if ($scheme === 'https') {
// this can be removed after the transition period
if ($this->isTransitional && $this->httpsProxy === null) {
if ($this->httpProxy !== null && !$this->ignoreHttpsProxy) {
$this->needsTransitionWarning = true;
return $this->httpProxy;
}
}
return $this->httpsProxy;
}
return null;
}
/**
* Finds proxy values from the environment and sets class properties
*/
private function getProxyData(): void
{
// Handle http_proxy/HTTP_PROXY on CLI only for security reasons
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
[$env, $name] = $this->getProxyEnv('http_proxy');
if ($env !== null) {
$this->httpProxy = new ProxyItem($env, $name);
}
}
// Handle cgi_http_proxy/CGI_HTTP_PROXY if needed
if ($this->httpProxy === null) {
[$env, $name] = $this->getProxyEnv('cgi_http_proxy');
if ($env !== null) {
$this->httpProxy = new ProxyItem($env, $name);
}
}
// Handle https_proxy/HTTPS_PROXY
[$env, $name] = $this->getProxyEnv('https_proxy');
if ($env !== null) {
$this->httpsProxy = new ProxyItem($env, $name);
}
// Handle no_proxy/NO_PROXY
[$env, $name] = $this->getProxyEnv('no_proxy');
if ($env !== null) {
$this->noProxyHandler = new NoProxyPattern($env);
}
}
/**
* Searches $_SERVER for case-sensitive values
*
* @return array{0: string|null, 1: string} value, name
*/
private function getProxyEnv(string $envName): array
{
$names = [strtolower($envName), strtoupper($envName)];
foreach ($names as $name) {
if (is_string($_SERVER[$name] ?? null)) {
if ($_SERVER[$name] !== '') {
return [$_SERVER[$name], $name];
}
// this can be removed after the transition period
if ($this->isTransitional && strtolower($name) === 'https_proxy') {
$this->ignoreHttpsProxy = true;
break;
}
}
}
return [null, ''];
}
/**
* Returns true if a url matches no_proxy value
*/
private function noProxy(string $requestUrl): bool
{
if ($this->noProxyHandler === null) {
return false;
}
return $this->noProxyHandler->test($requestUrl);
}
}
Function Calls
None |
Stats
MD5 | c345645bdd4cb0a480115d94851e6b16 |
Eval Count | 0 |
Decode Time | 89 ms |