forked from php-school/php-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeExecutionException.php
More file actions
61 lines (53 loc) · 1.33 KB
/
Copy pathCodeExecutionException.php
File metadata and controls
61 lines (53 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace PhpSchool\PhpWorkshop\Exception;
use RuntimeException;
use Symfony\Component\Process\Process;
/**
* Class CodeExecutionException
* @package PhpSchool\PhpWorkshop\Exception
* @author Aydin Hassan <aydin@hotmail.co.uk>
*/
class CodeExecutionException extends RuntimeException
{
/**
* @var string
*/
private $actual;
/**
* @var string
*/
private $errors;
/**
* CodeExecutionException constructor.
* @param string $reason
* @param string $actual
* @param string $errors
*/
public function __construct($reason, $actual = null, $errors = null)
{
$this->message = $reason;
$this->actual = $actual;
$this->errors = $errors;
}
/**
* @param Process $process
* @return static
*/
public static function fromProcess(Process $process)
{
$message = "PHP Code failed to execute. Error: \n%s";
$processOutput = $process->getOutput();
$processErrorOutput = $process->getErrorOutput();
return new static(
sprintf($message, $processErrorOutput ?: $processOutput), $processOutput, $processErrorOutput
);
}
public function getActual()
{
return $this->actual;
}
public function getErrors()
{
return $this->errors;
}
}