1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-15 10:57:08 +01:00
psalm/src/Psalm/Internal/Fork/PsalmRestarter.php
orklah ead107fa9e
More return types (#4173)
* add native return types

* redundant phpdoc
2020-09-12 11:24:05 -04:00

66 lines
1.5 KiB
PHP

<?php
namespace Psalm\Internal\Fork;
use function array_filter;
use function extension_loaded;
use function file_get_contents;
use function file_put_contents;
use function implode;
use function preg_replace;
/**
* @internal
*/
class PsalmRestarter extends \Composer\XdebugHandler\XdebugHandler
{
/**
* @var bool
*/
private $required = false;
/**
* @var string[]
*/
private $disabledExtensions = [];
public function disableExtension(string $disabledExtension): void
{
$this->disabledExtensions[] = $disabledExtension;
}
/**
* @param mixed $isLoaded
*/
protected function requiresRestart($isLoaded): bool
{
$this->required = (bool) array_filter(
$this->disabledExtensions,
function (string $extension): bool {
return extension_loaded($extension);
}
);
return $isLoaded || $this->required;
}
/**
* @param mixed $command
*
* @return void
*/
protected function restart($command)
{
if ($this->required && $this->tmpIni) {
$regex = '/^\s*(extension\s*=.*(' . implode('|', $this->disabledExtensions) . ').*)$/mi';
$content = file_get_contents($this->tmpIni);
$content = preg_replace($regex, ';$1', $content);
file_put_contents($this->tmpIni, $content);
}
/** @psalm-suppress MixedArgument */
parent::restart($command);
}
}