Skip to content

Commit

Permalink
Support 'conf.d' directories in wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Aug 3, 2021
1 parent 95e3826 commit 787fa2a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 23 deletions.
81 changes: 80 additions & 1 deletion src/XdebugVersion.php
Expand Up @@ -43,6 +43,12 @@ class XdebugVersion
/** @var string|false */
public $configPath = false;

/** @var string|false */
public $configExtraPath = false;

/** @var array|false */
public $configExtraFiles = false;

/** @var string */
public $extensionDir = '';

Expand Down Expand Up @@ -184,6 +190,31 @@ public function __construct( string $data )
$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 ) )
{
Expand All @@ -194,7 +225,7 @@ public function __construct( string $data )
}
$this->configFile = $file;

if ( $file && preg_match( '/(apache2)|(cli).*php\.ini/', $file, $m ) )
if ( $file && preg_match( '/(php-fpm)|(fpm)|(apache2)|(cli).*php\.ini/', $file, $m ) )
{
$this->configFilePerSapi = true;
}
Expand Down Expand Up @@ -383,6 +414,54 @@ public function determineFile() : string
}
}

public function determineIniFileInstruction( &$iniFileName ) : string
{
$defaultFileName = '99-xdebug.ini';

if ( $this->configExtraFiles )
{
foreach ( $this->configExtraFiles as $extraFile )
{
if ( preg_match( '/xdebug/', $extraFile ) )
{
$iniFileName = $extraFile;
return "Update <code>{$extraFile}</code> to have";
}
}
}

if ( $this->configExtraPath && !$this->xdebugVersion )
{
$iniFileName = "{$this->configExtraPath}{$this->dirSep}{$defaultFileName}";
return "Create <code>{$iniFileName}</code> and add";
}

if ( $this->configFile )
{
$iniFileName = $this->configFile;

if ( $this->xdebugVersion )
{
return "Update <code>{$iniFileName}</code> to have";
}
return "Update <code>{$iniFileName}</code> and add";
}

if ( $this->configPath )
{
if ( $this->windows )
{
$iniFileName = false;
return "Create <code>php.ini</code> in the same folder as where <code>php.exe</code> is, and add";
}
$iniFileName = "{$this->configExtraPath}{$this->dirSep}php.ini";
return "Create <code>{$iniFileName}</code>, and add";
}

$iniFileName = false;
return "Find your <code>php.ini</code> file, and add";
}

public function determineIniLine() : string
{
$line = 'zend_extension';
Expand Down
40 changes: 18 additions & 22 deletions views/wizard/result.php
Expand Up @@ -48,11 +48,18 @@
<?php endif ?>
<?php endif ?>
<?php endif ?>
<?php if ( $this->x->configExtraPath ) : ?>
<li><b>Extra Configuration Files Path:</b> <?= $this->x->configExtraPath ?></li>
<?php endif ?>
<?php if ( $this->x->configExtraFiles ) : ?>
<li><b>Extra Configuration Files:</b><br/><?= join( "<br/>\n", $this->x->configExtraFiles ); ?></li>
<?php endif ?>
<li><b>Extensions directory:</b> <?= $this->x->extensionDir ?></li>
</ul>

<?php
$dlFile = $this->x->determineFile();
$iniFileInstruction = $this->x->determineIniFileInstruction( $iniFileName );
$iniLine = $this->x->determineIniLine();

// add quotes when necessary
Expand Down Expand Up @@ -128,37 +135,26 @@
</li>
<?php endif ?>

<?php if ( $this->x->configPath || $this->x->windows ) : ?>
<li>
<?php if ($this->x->configFile) : ?>
<?php if ($this->x->xdebugVersion) : ?>
Update <code><?= $this->x->configFile ?></code>
<?php else : ?>
Edit <code><?= $this->x->configFile ?></code>
<?php endif ?>
<?php else : ?>
<?php if ($this->x->windows) : ?>
Create <code>php.ini</code> in the same folder as where <code>php.exe</code> is
<?php else : ?>
Create <code><?= $this->x->configPath . $this->x->dirSep ?>php.ini</code>
<?php endif ?>
<?php endif ?>
and <?= $this->x->xdebugVersion ? "change " : ( $this->x->zendServer ? "add at the begining of the file " : "add " ) ?>
the line<br/><code><?= $iniLine ?></code>
<li><?= $iniFileInstruction ?> the line:<br/><code><?= $iniLine ?></code>

<?php if ($this->x->opcacheLoaded) : ?>
<br/>Make sure that <code><?= $iniLine ?></code> is <b>below</b> the line for OPcache.
<?php endif ?>
</li>
<?php if ($this->x->opcacheLoaded && $this->x->configExtraPath === false) : ?>
<br/>Make sure that <code><?= $iniLine ?></code> is <b>below</b> the line for OPcache.
<?php endif ?>
</li>

<?php if ($this->x->configFilePerSapi) : ?>
<li>Please also update <code>php.ini</code> files in adjacent
directories, as your system seems to be configured with a separate
<code>php.ini</code> file for the web server and command line.</li>
<?php endif ?>

<?php if ($this->x->sapi !== 'Command Line Interface') : ?>
<?php if ($this->x->sapi === 'Apache 2.0 Handler') : ?>
<li>Restart the Apache Webserver</li>
<?php elseif ($this->x->sapi === 'FPM/FastCGI') : ?>
<li>Restart PHP-FPM</li>
<?php elseif ($this->x->sapi === 'Built-in HTTP server') : ?>
<li>Restart PHP's built-in HTTP server (php -S)</li>
<?php elseif ($this->x->sapi !== 'Command Line Interface') : ?>
<li>Restart the webserver</li>
<?php endif ?>
</ol>

0 comments on commit 787fa2a

Please sign in to comment.