Select Git revision
ConfigurationComponent.php
Forked from
FS Info TU Dortmund / Infoscreen / Infoscreen
534 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ConfigurationComponent.php 1.61 KiB
<?php
namespace App\Controller\Component;
use Cake\Controller\Component;
use Cake\Filesystem\File;
class ConfigurationComponent extends Component {
private $session = NULL;
private $folder = null;
public function initialize(array $config) {
$this->session = $this->request->session();
}
public function getConfiguration($session_key, $config_name = '', $config_type = 'panel') {
if (!is_string($session_key)
|| !is_string($config_name)
|| !is_string($config_type)
|| empty($session_key)) {
return FALSE;
}
// load data from session or reload data to session?
// if ($this->session->check($session_key)) {
// return configuration
// return $this->session->read($session_key);
// } else {
// reload configuration
return $this->getReloadedConfiguration($session_key, $config_name, $config_type);
// }
}
public function getReloadedConfiguration($session_key, $config_name = '', $config_type = 'panel') {
if (!is_string($session_key)
|| !is_string($config_name)
|| !is_string($config_type)
|| (strpos($config_type, ".."))
|| empty($config_name)
|| empty($session_key)) {
return FALSE;
}
// get filename for configuration
$file = new File(ROOT.'/config/'.$config_type.'/'.$config_name.'.json');
// can we get our configuration?
if ($file->exists() && $file->readable()
&& !(($file_content = $file->read()) === false)) {
// decode, save and return configuration
$result = json_decode($file_content,true);
$this->session->write($session_key, $result);
return $result;
} else {
// ERROR!
return FALSE;
}
}
}