Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F119864795
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, Jun 29, 23:55
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Jul 1, 23:55 (2 d)
Engine
blob
Format
Raw Data
Handle
27078929
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
(
$ref
,
$content
),
);
}
}
Event Timeline
Log In to Comment