mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
Merge pull request #14 from halkyon/json-output
Output check result and details as JSON if requested
This commit is contained in:
commit
20f0a2bf88
@ -192,6 +192,22 @@ class EnvironmentCheckSuiteResult extends ViewableData {
|
||||
return $this->details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the final result status and details to JSON.
|
||||
* @return string
|
||||
*/
|
||||
function toJSON() {
|
||||
$result = array(
|
||||
'Status' => $this->Status(),
|
||||
'ShouldPass' => $this->ShouldPass(),
|
||||
'Checks' => array()
|
||||
);
|
||||
foreach($this->details as $detail) {
|
||||
$result['Checks'][] = $detail->toMap();
|
||||
}
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a text version of a status code
|
||||
*/
|
||||
|
@ -105,6 +105,16 @@ class EnvironmentChecker extends RequestHandler {
|
||||
$email->send();
|
||||
}
|
||||
|
||||
// output the result as JSON if requested
|
||||
if(
|
||||
$this->getRequest()->getExtension() == 'json'
|
||||
|| strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false
|
||||
) {
|
||||
$response->setBody($result->toJSON());
|
||||
$response->addHeader('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response->setBody($resultText);
|
||||
|
||||
return $response;
|
||||
|
Loading…
Reference in New Issue
Block a user