Exemplo n.º 1
0
 /**
  * Get/create current object instance
  */
 public static function getCurrent()
 {
     if (is_null(self::$current)) {
         // Make a new uuid from the server's secret
         $config = JFactory::getConfig();
         $id = self::hash($config->get('secret'));
         self::$current = self::newFromId($id);
         // If the object was newly created, populate with default initial data and save
         if (!self::$current->tag) {
             lgDebug('Server object created', self::$current);
             // Make it easy to find this server by domain
             self::$current->tag = $_SERVER['HTTP_HOST'];
             // Server information
             self::$current->data = self::serverData();
             // Save our new instance to the DB (if we have a master yet)
             if (self::$master) {
                 self::$current->update();
                 lgDebug('Server object updated', self::$master);
             } else {
                 self::$deferred = true;
                 lgDebug('Server object update deferred, master unknown');
             }
         } else {
             lgDebug('Server object retrieved from database', self::$current);
         }
     }
     // If we have a master and we're not in standalone, ensure the server data is up to date
     if (self::$master && !LG_STANDALONE) {
         static $checked = false;
         if (!$checked) {
             $checked = true;
             if (json_encode(self::$current->data) !== json_encode(self::serverData(self::$current->data))) {
                 self::$current->data = self::serverData(self::$current->data);
                 self::$current->update();
             }
         }
     }
     return self::$current;
 }