Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5955327
ShellSyntaxError.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ShellSyntaxError.php
View Options
<?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
Details
Attached
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)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment