Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F113095448
PhabricatorNotificationClient.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, May 14, 23:21
Size
1 KB
Mime Type
text/x-php
Expires
Fri, May 16, 23:21 (2 d)
Engine
blob
Format
Raw Data
Handle
26183902
Attached To
rPH Phabricator
PhabricatorNotificationClient.php
View Options
<?php
final
class
PhabricatorNotificationClient
{
const
EXPECT_VERSION
=
7
;
public
static
function
getServerStatus
()
{
$uri
=
PhabricatorEnv
::
getEnvConfig
(
'notification.server-uri'
);
$uri
=
id
(
new
PhutilURI
(
$uri
))
->
setPath
(
'/status/'
)
->
setQueryParam
(
'instance'
,
self
::
getInstance
());
list
(
$body
)
=
id
(
new
HTTPSFuture
(
$uri
))
->
setTimeout
(
3
)
->
resolvex
();
$status
=
phutil_json_decode
(
$body
);
if
(!
is_array
(
$status
))
{
throw
new
Exception
(
pht
(
'Expected JSON response from notification server, received: %s'
,
$body
));
}
return
$status
;
}
public
static
function
tryToPostMessage
(
array
$data
)
{
if
(!
PhabricatorEnv
::
getEnvConfig
(
'notification.enabled'
))
{
return
;
}
try
{
self
::
postMessage
(
$data
);
}
catch
(
Exception
$ex
)
{
// Just ignore any issues here.
phlog
(
$ex
);
}
}
private
static
function
postMessage
(
array
$data
)
{
$server_uri
=
PhabricatorEnv
::
getEnvConfig
(
'notification.server-uri'
);
$server_uri
=
id
(
new
PhutilURI
(
$server_uri
))
->
setPath
(
'/'
)
->
setQueryParam
(
'instance'
,
self
::
getInstance
());
id
(
new
HTTPSFuture
(
$server_uri
,
json_encode
(
$data
)))
->
setMethod
(
'POST'
)
->
setTimeout
(
1
)
->
resolvex
();
}
private
static
function
getInstance
()
{
$client_uri
=
PhabricatorEnv
::
getEnvConfig
(
'notification.client-uri'
);
return
id
(
new
PhutilURI
(
$client_uri
))->
getPath
();
}
}
Event Timeline
Log In to Comment