for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of project-quality-inspector.
*
* (c) Alexandre GESLIN <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ProjectQualityInspector\Application;
class ProcessHelper
{
/**
* @param string $command
* @param string $baseDir
* @param boolean $allowErrorExitCode
* @return array
* @throws \RuntimeException
public static function execute($command, $baseDir, $allowErrorExitCode = false)
$command = 'cd ' . escapeshellarg($baseDir) . '; ' . $command . ' 2>&1';
if (DIRECTORY_SEPARATOR == '/') {
$command = 'LC_ALL=en_US.UTF-8 ' . $command;
}
exec($command, $output, $returnValue);
if ($returnValue !== 0 && !$allowErrorExitCode) {
throw new \RuntimeException(sprintf('ProcessHelper command : %s. Output: %s', $command, implode("\r\n", $output)));
return $output;