Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79243024
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
Sun, Aug 25, 11:10
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Aug 27, 11:10 (2 d)
Engine
blob
Format
Raw Data
Handle
20166702
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