Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97989770
PhabricatorJSONDocumentEngine.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jan 8, 08:29
Size
1 KB
Mime Type
text/x-php
Expires
Fri, Jan 10, 08:29 (2 d)
Engine
blob
Format
Raw Data
Handle
23448329
Attached To
rPH Phabricator
PhabricatorJSONDocumentEngine.php
View Options
<?php
final
class
PhabricatorJSONDocumentEngine
extends
PhabricatorTextDocumentEngine
{
const
ENGINEKEY
=
'json'
;
public
function
getViewAsLabel
(
PhabricatorDocumentRef
$ref
)
{
return
pht
(
'View as JSON'
);
}
protected
function
getDocumentIconIcon
(
PhabricatorDocumentRef
$ref
)
{
return
'fa-database'
;
}
protected
function
getContentScore
(
PhabricatorDocumentRef
$ref
)
{
if
(
preg_match
(
'/
\.
json
\z
/'
,
$ref
->
getName
()))
{
return
2000
;
}
if
(
$ref
->
isProbablyJSON
())
{
return
1750
;
}
return
500
;
}
protected
function
newDocumentContent
(
PhabricatorDocumentRef
$ref
)
{
$raw_data
=
$this
->
loadTextData
(
$ref
);
try
{
$data
=
phutil_json_decode
(
$raw_data
);
if
(
preg_match
(
'/^
\s
*
\[
/'
,
$raw_data
))
{
$content
=
id
(
new
PhutilJSON
())->
encodeAsList
(
$data
);
}
else
{
$content
=
id
(
new
PhutilJSON
())->
encodeFormatted
(
$data
);
}
$message
=
null
;
$content
=
PhabricatorSyntaxHighlighter
::
highlightWithLanguage
(
'json'
,
$content
);
}
catch
(
PhutilJSONParserException
$ex
)
{
$message
=
$this
->
newMessage
(
pht
(
'This document is not valid JSON: %s'
,
$ex
->
getMessage
()));
$content
=
$raw_data
;
}
return
array
(
$message
,
$this
->
newTextDocumentContent
(
$content
),
);
}
}
Event Timeline
Log In to Comment