Skip to content

Commit

Permalink
Strip PHP error level issues from process output
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jan 7, 2021
1 parent 98bd498 commit 4e7e200
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
15 changes: 1 addition & 14 deletions api/Process/ContaoConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,7 @@ public function getVersion(): string
$process = $this->processFactory->createContaoConsoleProcess(['contao:version']);
$process->run();

$version = '';
$lines = preg_split('/\r\n|\r|\n/', $process->getOutput());

while ($line = array_shift($lines)) {
if (0 === strpos($line, 'PHP Warning:')
|| 0 === strpos($line, 'Warning:')
|| 0 === strpos($line, 'Failed loading ')
) {
continue;
}

$version = trim($line."\n".implode("\n", $lines));
break;
}
$version = trim($process->getOutput());

try {
// Run parser to check whether a valid version was returned
Expand Down
23 changes: 21 additions & 2 deletions api/Process/Utf8Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,31 @@ class Utf8Process extends Process
{
public function getOutput(): string
{
return $this->convertEncoding(parent::getOutput());
return $this->normalizeOutput(parent::getOutput());
}

public function getErrorOutput(): string
{
return $this->convertEncoding(parent::getErrorOutput());
return $this->normalizeOutput(parent::getErrorOutput());
}

/**
* Normalize encoding and try to fix PHP error level issues.
*/
private function normalizeOutput(string $output): string
{
$output = $this->convertEncoding($output);

return implode("\n", array_filter(
preg_split('/\r\n|\r|\n/', $output),
static function ($line) {
return 0 !== strpos($line, 'PHP Warning:')
&& 0 !== strpos($line, 'Warning:')
&& 0 !== strpos($line, 'Deprecated:')
&& 0 !== strpos($line, 'Runtime Notice:')
&& 0 !== strpos($line, 'Failed loading ');
}
));
}

private function convertEncoding(string $data): string
Expand Down

0 comments on commit 4e7e200

Please sign in to comment.