[ 'src' => '2.8.1', ], '7.1' => [ 'src' => '2.9.8', 'win' => '2.9.8' ], '7.2' => [ 'src' => '3.1.6', 'win' => '3.1.6' ], '7.3' => [ 'src' => '3.1.6', 'win' => '3.1.6' ], '7.4' => [ 'src' => '3.1.6', 'win' => '3.1.6' ], '8.0' => [ 'src' => '3.5.3', 'win' => '3.5.3' ], '8.1' => [ 'src' => '3.5.3', 'win' => '3.5.3' ], '8.2' => [ 'src' => '3.5.3', 'win' => '3.5.3' ], '8.3' => [ 'src' => '3.5.3', 'win' => '3.5.3' ], '8.4' => [ 'src' => '3.5.3', 'win' => '3.5.3' ], '8.5' => [ 'src' => '3.5.3', 'win' => '3.5.3' ], ]; /* Start one is inclusive, end is exclusive */ private const UNSUPPORTED_WIN_VERSIONS = [ [ '7.4.0', '7.4.20', 'due to missing exported symbols in zlib' ], [ '8.0.0', '8.0.7', 'due to missing exported symbols in zlib' ], ]; /** @var string|null */ public $version; /** @var bool */ public $ts = false; /** @var bool */ public $debug = false; /** @var bool */ public $windows = false; /** @var string|false */ public $phpApi = false; /** @var string|false */ public $zendApi = false; /** @var string|false */ public $configFile = false; /** @var bool */ public $configFilePerSapi = false; /** @var string|false */ public $configPath = false; /** @var string|false */ public $configExtraPath = false; /** @var array|false */ public $configExtraFiles = false; /** @var string */ public $extensionDir = ''; /** @var string|false */ public $sapi = false; /** @var string|false */ public $tarDir = false; /** @var string|false */ public $xdebugVersion = false; /** @var bool */ public $zendServer = false; /** @var bool */ public $opcacheLoaded = false; /** @var bool */ public $xdebugAsZendExt = false; /** @var bool */ public $xdebugAsPhpExt = false; /** @var string|false */ public $distribution = false; /** @var int */ public $winCompiler = 9; /** @var string */ public $architecture = 'x86'; /** @var string|false */ public $opcacheVersion = false; /** @var string|null */ public $zendServerInstallPath; /** @var string|null */ public $xdebugVersionToInstall; /** @var string */ public $dirSep; public function __construct( string $data ) { $html = false; $htmlData = null; if ( str_contains( $data, 'extension_dir' ) ) { $html = true; $htmlData = $data; } $data = strip_tags( $data ); $data = str_replace( ' ', ' ', $data ); ini_set('xdebug.var_display_max_data', '633333' ); if ( preg_match( '/Zend Extension Manager/', $data ) ) { $this->zendServer = true; } if ( preg_match( '/Server API([ =>\t]*)(.*)/', $data, $m ) ) { $this->sapi = trim( $m[2] ); } if ( preg_match( '/PHP Version([^45678]+)([45678][0-9.dev-]+)/', $data, $m ) ) { $this->version = $m[2]; } // Zend Extension check if ( preg_match( '/with\sXdebug\sv([0-9.RCrcdevalphabeta-]+),/', $data, $m ) ) { $this->xdebugVersion = $m[1]; $this->xdebugAsZendExt = true; } // OPcache Extension check if ( preg_match( '/with\sZend\sOPcache\sv([0-9.RCrcdevalphabeta-]+),/', $data, $m ) ) { $this->opcacheVersion = $m[1]; $this->opcacheLoaded = true; } // Xdebug as normal php ext if ( preg_match( '/xdebug support/', $data, $m ) ) { $this->xdebugAsPhpExt = true; } if ( preg_match( '/Thread Safety([ =>\t]+)(disabled|enabled)/', $data, $m ) ) { $this->ts = $m[2] == 'enabled'; } if ( preg_match( '/Debug Build([ =>\t]+)(yes|no)/', $data, $m ) ) { $this->debug = $m[2] == 'yes'; } if ( preg_match( '/System([ =>\t]+)Windows/', $data, $m ) ) { $this->windows = true; } if ( preg_match( '/System(.+)Debian/', $data, $m ) ) { $this->distribution = "Debian"; } if ( preg_match( '/System(.+)Ubuntu/', $data, $m ) ) { $this->distribution = "Ubuntu"; } if ( preg_match( '/System(.+)el[5678]/', $data, $m ) ) { $this->distribution = "RedHat"; } if ( preg_match( '/System(.+)\.fc\d+\./', $data, $m ) ) { $this->distribution = "Fedora"; } if ( preg_match( '/System(.+)Darwin/', $data, $m ) ) { $this->distribution = "Darwin"; } // windows 32/64 bit if ( preg_match( '/Architecture([ =>\t]*)(x[0-9]*)/', $data, $m ) ) { $this->architecture = $m[2]; } // for 4.4 and 5.1 if ( preg_match( '/PHP Extension([ =>\t]*)([0-9]*)/', $data, $m ) ) { $this->phpApi = $m[2]; } if ( preg_match( '/Zend Extension([ =>\t]*)([0-9]*)/', $data, $m ) ) { $this->zendApi = $m[2]; } // extra path if ( preg_match( '/Scan this dir for additional .ini files([ =>\t]*)(.*)/', $data, $m ) ) { $directory = trim( $m[2] ); if ( $directory == '(none)' ) { $directory = false; } $this->configExtraPath = $directory; } // extra files if ( preg_match( '/Additional .ini files parsed([ =>\t]*)(.*)PHP API/s', $data, $m ) ) { $extraFiles = false; $fileString = strtr( trim( $m[2] ), "\r\n", ' ' ); if ( $fileString !== '(none)' && $fileString != '' ) { $extraFiles = explode( ', ', $fileString ); $extraFiles = array_map( 'trim', $extraFiles ); } $this->configExtraFiles = $extraFiles; } // paths if ( preg_match( '/Loaded Configuration File([ =>\t]*)(.*)/', $data, $m ) ) { $file = trim( $m[2] ); if ( $file == '(none)' ) { $file = false; } $this->configFile = $file; if ( $file && preg_match( '/(php-fpm)|(fpm)|(apache2)|(cli).*php\.ini/', $file, $m ) ) { $this->configFilePerSapi = true; } } if ( preg_match( '/Configuration File \(php.ini\) Path([ =>\t]*)(.*)/', $data, $m ) ) { $file = trim( $m[2] ); if ( $file == '(none)' ) { $file = false; } $this->configPath = $file; } if ( $htmlData !== null ) { if ( preg_match( '@extension_dir
{$extraFile} to have";
}
}
}
if ( $this->configExtraPath && !$this->xdebugVersion )
{
$iniFileName = "{$this->configExtraPath}{$this->dirSep}{$defaultFileName}";
return "Create {$iniFileName} and add";
}
if ( $this->configFile )
{
$iniFileName = $this->configFile;
if ( $this->xdebugVersion )
{
return "Update {$iniFileName} to have";
}
return "Update {$iniFileName} and add";
}
if ( $this->configPath )
{
if ( $this->windows )
{
$iniFileName = false;
return "Create php.ini in the same folder as where php.exe is, and add";
}
$iniFileName = "{$this->configExtraPath}{$this->dirSep}php.ini";
return "Create {$iniFileName}, and add";
}
$iniFileName = false;
return "Find your php.ini file, and add";
}
public function determineIniLine() : string
{
if ( version_compare( $this->version, '7.2', '>=' ) )
{
return 'zend_extension = xdebug';
}
$line = 'zend_extension';
if (!$this->version) {
return '';
}
if ( version_compare( $this->version, '5.3.0', '<' ) )
{
if ( $this->debug )
{
$line .= '_debug';
}
if ( $this->ts )
{
$line .= '_ts';
}
}
$line .= ' = ';
if ( $this->extensionDir !== '' )
{
$line .= !str_contains( $this->extensionDir, ' ') ? '' : '"';
$line .= $this->extensionDir . $this->dirSep;
}
if ( $this->windows )
{
$line .= $this->determineFile();
}
else
{
$line .= 'xdebug.so';
}
if ( $this->extensionDir !== '' )
{
$line .= !str_contains( $this->extensionDir, ' ') ? '' : '"';
}
return $line;
}
}
?>