Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1429274
DefaultTracer.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
DefaultTracer.php
View Options
<?php
namespace
Wikimedia\WikiPEG
;
use
InvalidArgumentException
;
class
DefaultTracer
implements
Tracer
{
private
$indentLevel
=
0
;
public
function
trace
(
$event
)
{
switch
(
$event
[
'type'
]
)
{
case
'rule.enter'
:
$this
->
log
(
$event
);
$this
->
indentLevel
++;
break
;
case
'rule.match'
:
$this
->
indentLevel
--;
$this
->
log
(
$event
);
break
;
case
'rule.fail'
:
$this
->
indentLevel
--;
$this
->
log
(
$event
);
break
;
default
:
throw
new
InvalidArgumentException
(
"Invalid event type {$event['type']}"
);
}
}
private
function
log
(
$event
)
{
print
str_pad
(
''
.
$event
[
'location'
],
20
)
.
str_pad
(
$event
[
'type'
],
10
)
.
' '
.
str_repeat
(
' '
,
$this
->
indentLevel
)
.
$event
[
'rule'
]
.
$this
->
formatArgs
(
$event
[
'args'
]
??
null
)
.
"
\n
"
;
}
private
function
formatArgs
(
$argMap
)
{
if
(
!
$argMap
)
{
return
''
;
}
$argParts
=
[];
foreach
(
$argMap
as
$argName
=>
$argValue
)
{
if
(
$argName
===
'$silence'
)
{
continue
;
}
if
(
$argName
===
'$boolParams'
)
{
$argParts
[]
=
'0x'
.
base_convert
(
$argValue
,
10
,
16
);
}
else
{
$displayName
=
str_replace
(
'$param_'
,
''
,
$argName
);
if
(
$displayName
[
0
]
===
'&'
)
{
$displayName
=
substr
(
$displayName
,
1
);
$ref
=
'&'
;
}
else
{
$ref
=
''
;
}
$argParts
[]
=
"$displayName=$ref"
.
json_encode
(
$argValue
,
JSON_UNESCAPED_SLASHES
|
JSON_UNESCAPED_UNICODE
);
}
}
if
(
$argParts
)
{
return
'<'
.
implode
(
', '
,
$argParts
)
.
'>'
;
}
else
{
return
''
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 17:21 (10 h, 24 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e5/f3/0c492506ebadb1b4b578ca9e54af
Default Alt Text
DefaultTracer.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment