2018-07-17 20:08:34 +02:00
|
|
|
<?php
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
namespace Psalm\Internal\Fork;
|
2018-07-17 20:08:34 +02:00
|
|
|
|
|
|
|
class PsalmRestarter extends \Composer\XdebugHandler\XdebugHandler
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $required = false;
|
|
|
|
|
|
|
|
/**
|
2018-07-17 22:40:03 +02:00
|
|
|
* @var string[]
|
2018-07-17 20:08:34 +02:00
|
|
|
*/
|
2018-07-17 22:40:03 +02:00
|
|
|
private $disabledExtensions = [];
|
2018-07-17 20:08:34 +02:00
|
|
|
|
|
|
|
/**
|
2018-07-17 22:40:03 +02:00
|
|
|
* @param string $disabledExtension
|
|
|
|
*
|
2018-07-17 20:08:34 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2018-07-17 22:40:03 +02:00
|
|
|
public function disableExtension($disabledExtension)
|
2018-07-17 20:08:34 +02:00
|
|
|
{
|
2018-07-17 22:40:03 +02:00
|
|
|
$this->disabledExtensions[] = $disabledExtension;
|
2018-07-17 20:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-suppress UnusedMethod
|
|
|
|
*/
|
|
|
|
protected function requiresRestart($loaded)
|
|
|
|
{
|
2018-07-17 22:40:03 +02:00
|
|
|
$this->required = (bool) array_filter(
|
|
|
|
$this->disabledExtensions,
|
|
|
|
/**
|
|
|
|
* @param string $extension
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function ($extension) {
|
|
|
|
return extension_loaded($extension);
|
|
|
|
}
|
|
|
|
);
|
2018-07-17 20:08:34 +02:00
|
|
|
|
|
|
|
return $loaded || $this->required;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-suppress UnusedMethod
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function restart($command)
|
|
|
|
{
|
|
|
|
if ($this->required && $this->tmpIni) {
|
2018-07-17 22:40:03 +02:00
|
|
|
$regex = '/^\s*(extension\s*=.*(' . implode('|', $this->disabledExtensions) . ').*)$/mi';
|
2018-07-17 20:08:34 +02:00
|
|
|
$content = file_get_contents($this->tmpIni);
|
|
|
|
|
|
|
|
$content = preg_replace($regex, ';$1', $content);
|
2018-07-17 22:40:03 +02:00
|
|
|
|
2018-07-17 20:08:34 +02:00
|
|
|
file_put_contents($this->tmpIni, $content);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @psalm-suppress MixedArgument */
|
|
|
|
parent::restart($command);
|
|
|
|
}
|
|
|
|
}
|