AcquiaLiftReportDataFromFileBase.inc in Acquia Lift Connector 7.2
File
includes/AcquiaLiftReportDataFromFileBase.inc
View source
<?php
class AcquiaLiftReportDataFromFileBase {
protected $fileLocation;
protected $reports;
public function __construct($file_location, AcquiaLiftReportCacheInterface $cache = NULL) {
$this->fileLocation = $file_location;
$this->cache = $cache;
}
public function getReport($agent_name, $report_name = NULL) {
if ($this->reports) {
if (!empty($report_name)) {
return isset($this->reports[$report_name]) ? $this->reports[$report_name] : array();
}
return $this->reports;
}
if ($this->cache && ($reports = $this->cache
->getCachedReports($agent_name))) {
$this->reports = $reports;
if (!empty($report_name)) {
return isset($this->reports[$report_name]) ? $this->reports[$report_name] : array();
}
return $this->reports;
}
else {
$file_name = $this->fileLocation;
if (strpos($file_name, '://') === FALSE) {
if (strpos($file_name, '/') !== 0) {
$file_name = '/' . $file_name;
}
global $base_url;
$file_name = $base_url . $file_name;
}
if ($str = file_get_contents($file_name)) {
$parsed = json_decode($str, TRUE);
$this->reports = isset($parsed['reports']) ? $parsed['reports'] : $parsed;
if ($this->cache) {
$this->cache
->cacheReports($agent_name, $this->reports);
}
if (!empty($report_name)) {
return isset($this->reports[$report_name]) ? $this->reports[$report_name] : array();
}
return $this->reports;
}
}
return array();
}
}