public function __construct($functionName, $callback, $source, array $error = null, $cause = null)
{
$this->functionName = $functionName;
$this->callback = $callback;
$this->source = $source;
$this->error = $error;
$lines = explode(PHP_EOL, $source);
if (null === $error) {
$message = sprintf('Function hook %s generation failed.%sRelevant lines:%%s', $functionName, PHP_EOL);
$errorLineNumber = null;
} else {
$errorLineNumber = $error['line'];
$startLine = $errorLineNumber - 4;
$contextLineCount = 7;
if ($startLine < 0) {
$contextLineCount += $startLine;
$startLine = 0;
}
$lines = array_slice($lines, $startLine, $contextLineCount, true);
$message = sprintf('Function hook %s generation failed: ' . '%s in generated code on line %d.%s' . 'Relevant lines:%%s', $functionName, $error['message'], $errorLineNumber, PHP_EOL);
}
end($lines);
$lineNumber = key($lines);
$padSize = strlen($lineNumber + 1) + 4;
$renderedLines = '';
foreach ($lines as $lineNumber => $line) {
if (null !== $errorLineNumber) {
$highlight = $lineNumber + 1 === $errorLineNumber;
} else {
$highlight = false;
}
$renderedLines .= sprintf('%s%s%s %s', PHP_EOL, str_pad($lineNumber + 1, $padSize, ' ', STR_PAD_LEFT), $highlight ? ':' : ' ', $line);
}
parent::__construct(sprintf($message, $renderedLines), 0, $cause);
}