Example #1
0
 function __construct($config_file, $path)
 {
     $this->path = $path;
     $this->config_file = $config_file;
     $full_path = $path . "/" . $this->config_file;
     if (file_exists($full_path)) {
         try {
             $this->config = json_decode(file_get_contents($full_path));
         } catch (Exception $e) {
             $this->config = new stdClass();
         }
         // it had no write permission when first created while testing
         if (!is_writable($full_path)) {
             chmod($full_path, 0664);
         }
     } else {
         $this->config = new stdClass();
     }
     if (!isset($this->config->sessions) || !is_array($this->config->sessions)) {
         $this->config->sessions = array();
     } else {
         $this->config->sessions = array_map(function ($session) {
             return Session::cast($session);
         }, array_filter($this->config->sessions, function ($session) {
             return isset($session->token) && isset($session->username);
         }));
     }
     if (!isset($this->config->users) || !is_array($this->config->sessions)) {
         $this->config->users = array();
     }
 }