Page MenuHomeWickedGov Phorge

ShellSyntaxError.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

ShellSyntaxError.php

<?php
namespace Shellbox\ShellParser;
use Shellbox\ShellboxError;
use Wikimedia\WikiPEG\Location;
/**
* Exception class for shell command syntax errors. By default the message uses
* multiple lines to show the exact location of the syntax error.
*/
class ShellSyntaxError extends ShellboxError {
/** @var string */
private $originalMessage;
/** @var Location */
private $location;
/** @var string */
private $input;
/** @var bool */
private $contextEnabled;
/**
* @internal
* @param string $message The message from the PEG
* @param Location $location The error location
* @param string $input The complete input text
*/
public function __construct( $message, Location $location, $input ) {
parent::__construct( $message );
$this->originalMessage = $message;
$this->location = $location;
$this->input = $input;
$this->contextEnabled = true;
$this->updateMessage();
}
/**
* Enable multi-line context
*/
public function enableContext() {
$this->contextEnabled = true;
$this->updateMessage();
}
/**
* Disable multi-line context
*/
public function disableContext() {
$this->contextEnabled = false;
$this->updateMessage();
}
/**
* Update the message (stored in the parent) according to the contextEnabled
* setting.
*/
private function updateMessage() {
if ( !$this->contextEnabled ) {
$this->message = $this->originalMessage;
return;
}
$lines = explode( "\n", $this->input );
$line = $lines[$this->location->line - 1] ?? '';
$this->message = $this->originalMessage . "\n" .
$line . "\n" .
str_repeat( ' ', $this->location->column - 1 ) . '^';
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Oct 3, 03:37 (3 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0c/19/a4e5022bdb66ceae1a454b8338b5
Default Alt Text
ShellSyntaxError.php (1 KB)

Event Timeline